org.locationtech.geogig.model.Ref.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中org.locationtech.geogig.model.Ref.<init>方法的一些代码示例,展示了Ref.<init>的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ref.<init>方法的具体详情如下:
包路径:org.locationtech.geogig.model.Ref
类名称:Ref
方法名:<init>

Ref.<init>介绍

[英]Constructs a new Ref with the given parameters.
[中]用给定的参数构造一个新的Ref。

代码示例

代码示例来源:origin: locationtech/geogig

/**
 * @return the non-symbolic {@link Ref} this symbolic reference points to.
 */
public @Override Ref peel() {
  return new Ref(target, getObjectId());
}

代码示例来源:origin: org.locationtech.geogig/geogig-api

/**
 * @return the non-symbolic {@link Ref} this symbolic reference points to.
 */
public @Override Ref peel() {
  return new Ref(target, getObjectId());
}

代码示例来源:origin: locationtech/geogig

private Ref toLocal(Ref remoteRef) {
  Optional<String> localName = remote.mapToRemote(remoteRef.getName());
  Preconditions.checkArgument(localName.isPresent(), "Can't map %s to local ref using %s",
      remoteRef.getName(), remote.getFetchSpec());
  Ref localRef;
  if (remoteRef instanceof SymRef) {
    Ref target = toLocal(remoteRef.peel());
    localRef = new SymRef(localName.get(), target);
  } else {
    localRef = new Ref(localName.get(), remoteRef.getObjectId());
  }
  return localRef;
}

代码示例来源:origin: locationtech/geogig

private Ref toRemote(Ref localRef) {
  Optional<String> remoteName = remote.mapToLocal(localRef.getName());
  Preconditions.checkArgument(remoteName.isPresent(), "Can't map %s to remote ref using %s",
      localRef.getName(), remote.getFetchSpec());
  Ref remoteRef;
  if (localRef instanceof SymRef) {
    Ref target = toRemote(localRef.peel());
    remoteRef = new SymRef(remoteName.get(), target);
  } else {
    remoteRef = new Ref(remoteName.get(), localRef.getObjectId());
  }
  return remoteRef;
}

代码示例来源:origin: org.locationtech.geogig/geogig-remoting

private Ref toLocal(Ref localRemoteRef) {
  final Remote remote = this.remote;
  if (localRemoteRef.namespace().equals(Ref.TAGS_PREFIX)) {
    return localRemoteRef;
  }
  final String localName = localRemoteRef.localName();
  final String remoteNamespace = localRemoteRef.namespace();
  final String expectedRemotePrefix = Ref.REMOTES_PREFIX + remote.getName() + "/";
  Preconditions.checkArgument(remoteNamespace.equals(expectedRemotePrefix));
  final String localPrefix = Ref.HEAD.equals(localName) ? "" : Ref.HEADS_PREFIX;
  final String localRefName = localPrefix + localName;
  Ref ref = null;
  if (localRemoteRef instanceof SymRef) {
    SymRef sr = (SymRef) localRemoteRef;
    Ref localTarget = toLocal(new Ref(sr.getTarget(), sr.getObjectId()));
    ref = new SymRef(localRefName, localTarget);
  } else {
    ref = new Ref(localRefName, localRemoteRef.getObjectId());
  }
  return ref;
}

代码示例来源:origin: org.locationtech.geogig/geogig-remoting

private Ref toRemote(Ref localRef) {
  if (localRef.namespace().equals(Ref.TAGS_PREFIX)) {
    return localRef;
  }
  checkArgument(!localRef.getName().startsWith(Ref.REMOTES_PREFIX),
      "ref is already in a remotes namespace: %s", localRef);
  final String remoteNamespace = Ref.REMOTES_PREFIX + remote.getName() + "/";
  final String remoteRefName = remoteNamespace + localRef.localName();
  Ref remoteRef;
  if (localRef instanceof SymRef) {
    SymRef sr = (SymRef) localRef;
    String localtarget = sr.getTarget();
    Ref remoteTarget = toRemote(new Ref(localtarget, sr.getObjectId()));
    remoteRef = new SymRef(remoteRefName, remoteTarget);
  } else {
    remoteRef = new Ref(remoteRefName, localRef.getObjectId());
  }
  return remoteRef;
}

代码示例来源:origin: locationtech/geogig

private Optional<Ref> resolveRef(@Nullable String head, Context repo) {
  Ref ref = null;
  if (head != null) {
    ref = repo.command(RefParse.class).setName(head).call().orNull();
    if (null == ref) {
      RevObject root = repo.command(RevObjectParse.class).setRefSpec(head).call()
          .orNull();
      if (null != root) {
        ref = new Ref(root.getType().toString(), root.getId());
      }
    }
  }
  return Optional.ofNullable(ref);
}

代码示例来源:origin: locationtech/geogig

@Test
  public void testHashCode() {
    assertFalse(new Ref("refs/heads/master", oid)
        .hashCode() == new Ref("refs/heads/branch1", oid2).hashCode());
  }
}

代码示例来源:origin: locationtech/geogig

@Test
public void testEquals() throws Exception {
  Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid);
  Ref testRef2 = new Ref(Ref.REFS_PREFIX + "commit2", oid2);
  assertFalse(testRef.equals(testRef2));
  testRef2 = new Ref(Ref.REFS_PREFIX + "commit1", oid3);
  assertFalse(testRef.equals(testRef2));
  assertFalse(testRef.equals("not a ref"));
  assertTrue(testRef.equals(testRef));
}

代码示例来源:origin: locationtech/geogig

@Test
public void testCompare() throws Exception {
  Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid);
  Ref testRef2 = new Ref(Ref.REFS_PREFIX + "commit2", oid2);
  assertTrue(testRef.compareTo(testRef2) < 0);
  assertTrue(testRef2.compareTo(testRef) > 0);
  assertEquals(0, testRef.compareTo(testRef));
}

代码示例来源:origin: org.locationtech.geogig/geogig-core

@Test
public void testReinitializeExistingRepo() throws Exception {
  when(injector.repository()).thenReturn(mockRepo);
  Optional<Ref> absent = Optional.absent();
  when(mockRefParse.call()).thenReturn(absent);
  Repository created = init.call();
  assertSame(mockRepo, created);
  verify(mockUpdateRef, times(3)).call();
  verify(mockUpdateSymRef, times(1)).call();
  assertTrue(new File(workingDir, ".geogig").exists());
  assertTrue(new File(workingDir, ".geogig").isDirectory());
  Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me"));
  when(mockRefParse.call()).thenReturn(Optional.of(master));
  Context injector = mock(Context.class);
  when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse);
  when(injector.platform()).thenReturn(platform);
  when(injector.repository()).thenReturn(mockRepo);
  init.setContext(injector);
  assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent());
  assertNotNull(init.call());
  verify(platform, atLeastOnce()).pwd();
  assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent());
  verify(injector, never()).command(eq(UpdateRef.class));
  verify(injector, never()).command(eq(UpdateSymRef.class));
  assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID));
}

代码示例来源:origin: locationtech/geogig

@Test
public void testReinitializeExistingRepo() throws Exception {
  when(injector.repository()).thenReturn(mockRepo);
  Optional<Ref> absent = Optional.absent();
  when(mockRefParse.call()).thenReturn(absent);
  Repository created = init.call();
  assertSame(mockRepo, created);
  verify(mockUpdateRef, times(3)).call();
  verify(mockUpdateSymRef, times(1)).call();
  assertTrue(new File(workingDir, ".geogig").exists());
  assertTrue(new File(workingDir, ".geogig").isDirectory());
  Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me"));
  when(mockRefParse.call()).thenReturn(Optional.of(master));
  Context injector = mock(Context.class);
  when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse);
  when(injector.platform()).thenReturn(platform);
  when(injector.repository()).thenReturn(mockRepo);
  init.setContext(injector);
  assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent());
  assertNotNull(init.call());
  verify(platform, atLeastOnce()).pwd();
  assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent());
  verify(injector, never()).command(eq(UpdateRef.class));
  verify(injector, never()).command(eq(UpdateSymRef.class));
  assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID));
}

代码示例来源:origin: locationtech/geogig

private Iterable<RefDiff> updateLocalRemoteRefs(Remote remote, List<LocalRemoteRef> fetchSpecs,
    final boolean prune) {
  List<RefDiff> updatedLocalRemoteRefs = new ArrayList<>();
  for (LocalRemoteRef expected : fetchSpecs) {
    final boolean isNew = expected.isNew;
    final boolean remoteDeleted = expected.remoteDeleted;
    final String localName = expected.localRemoteRef.getName();
    if (remoteDeleted) {
      if (prune) {
        updatedLocalRemoteRefs.add(RefDiff.removed(expected.localRemoteRef));
        command(UpdateRef.class).setName(localName)
            .setOldValue(expected.localRemoteRef.getObjectId()).setDelete(true)
            .call();
      }
      continue;
    }
    RefDiff localRefDiff;
    Ref oldRef = isNew ? null : expected.localRemoteRef;
    Ref newRef = new Ref(localName, expected.remoteRef.getObjectId());
    command(UpdateRef.class).setName(localName).setNewValue(newRef.getObjectId()).call();
    localRefDiff = new RefDiff(oldRef, newRef);
    updatedLocalRemoteRefs.add(localRefDiff);
  }
  return updatedLocalRemoteRefs;
}

代码示例来源:origin: locationtech/geogig

@Test
public void testToString() throws Exception {
  Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid);
  assertEquals("[" + testRef.getName() + " -> " + testRef.getObjectId().toString() + "]",
      testRef.toString());
}

代码示例来源:origin: locationtech/geogig

@Test
public void testConstructor() throws Exception {
  Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid);
  assertEquals(Ref.REFS_PREFIX + "commit1", testRef.getName());
  assertEquals(Ref.REFS_PREFIX, testRef.namespace());
  assertEquals("commit1", testRef.localName());
  assertEquals(oid, testRef.getObjectId());
}

代码示例来源:origin: locationtech/geogig

@Test
public void testPushNewBranch() throws Exception {
  localRepo.command(BranchCreateOp.class).setName("newbranch").call();
  localRepo.command(CheckoutOp.class).setSource("newbranch").call();
  // Add a commit to the local repository
  insertAndAdd(localRepo, lines3);
  insertAndAdd(localRepo, points1_modified);
  localRepo.command(CommitOp.class).call();
  final Ref branch1 = getRef(localRepo, "newbranch").get();
  // Push the commit
  PushOp push = pushOp();
  push.addRefSpec("newbranch");
  TransferSummary summary = push.call();
  assertSummary(summary, remote.getPushURL(), absent(),
      Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId())));
  TestSupport.verifyRepositoryContents(remoteRepo);
}

代码示例来源:origin: org.locationtech.geogig/geogig-remoting

@Test
public void testPushNewBranch() throws Exception {
  localRepo.command(BranchCreateOp.class).setName("newbranch").call();
  localRepo.command(CheckoutOp.class).setSource("newbranch").call();
  // Add a commit to the local repository
  insertAndAdd(localRepo, lines3);
  insertAndAdd(localRepo, points1_modified);
  localRepo.command(CommitOp.class).call();
  final Ref branch1 = getRef(localRepo, "newbranch").get();
  // Push the commit
  PushOp push = pushOp();
  push.addRefSpec("newbranch");
  TransferSummary summary = push.call();
  assertSummary(summary, remote.getPushURL(), absent(),
      Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId())));
  TestSupport.verifyRepositoryContents(remoteRepo);
}

代码示例来源:origin: org.locationtech.geogig/geogig-remoting

@Test
public void testPushWithRefSpec() throws Exception {
  // Add a commit to the local repository
  insertAndAdd(localRepo, lines3);
  RevCommit commit = localRepo.command(CommitOp.class).call();
  expectedMaster.addFirst(commit);
  // Push the commit
  PushOp push = pushOp();
  push.addRefSpec("master:NewRemoteBranch");
  TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call();
  assertSummary(summary, remote.getPushURL(), null,
      new Ref("refs/heads/NewRemoteBranch", commit.getId()));
  assertTrue(getRef(remoteRepo, "NewRemoteBranch").isPresent());
  // verify that the remote got the commit
  remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call();
  List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call());
  assertEquals(expectedMaster, logged);
  // verify that the local reference of the remote master is updated
  Optional<Ref> ref = localRepo.command(RefParse.class)
      .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/NewRemoteBranch")).call();
  assertTrue(ref.isPresent());
  assertEquals(logged.get(0).getId(), ref.get().getObjectId());
  TestSupport.verifyRepositoryContents(remoteRepo);
}

代码示例来源:origin: locationtech/geogig

@Test
  public void testSymRef() {
    Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1",
        ObjectId.valueOf("abc123000000000000001234567890abcdef0000"));

    SymRef symRef = new SymRef("TestRef", testRef);

    assertEquals(testRef.getName(), symRef.getTarget());

    String symRefString = symRef.toString();

    assertEquals("TestRef -> " + "[" + testRef.getName() + " -> "
        + testRef.getObjectId().toString() + "]", symRefString);
  }
}

代码示例来源:origin: locationtech/geogig

@Test
public void testPushWithRefSpec() throws Exception {
  // Add a commit to the local repository
  insertAndAdd(localRepo, lines3);
  RevCommit commit = localRepo.command(CommitOp.class).call();
  expectedMaster.addFirst(commit);
  // Push the commit
  PushOp push = pushOp();
  push.addRefSpec("master:NewRemoteBranch");
  TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call();
  assertSummary(summary, remote.getPushURL(), null,
      new Ref("refs/heads/NewRemoteBranch", commit.getId()));
  assertTrue(getRef(remoteRepo, "NewRemoteBranch").isPresent());
  // verify that the remote got the commit
  remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call();
  List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call());
  assertEquals(expectedMaster, logged);
  // verify that the local reference of the remote master is updated
  Optional<Ref> ref = localRepo.command(RefParse.class)
      .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/NewRemoteBranch")).call();
  assertTrue(ref.isPresent());
  assertEquals(logged.get(0).getId(), ref.get().getObjectId());
  TestSupport.verifyRepositoryContents(remoteRepo);
}

相关文章