org.locationtech.geogig.model.Ref类的使用及代码示例

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

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

Ref介绍

[英]A named pointer to a RevObject that represents an entry point in a repository's revision graph.

The commit history consists of a DAG of commits, each one pointing to it's parent(s) commit(s). Refs are essentially named pointers to commits, where the ref name is usually the name of a branch (when the ref is in the refs/heads/ namespace), or the name of a branch in a remote repository (when the ref is in the refs/remotes//namespace).

Types of Refs

  • Branches: Refs under the refs/heads namespace, point to RevCommit
  • Remote Branches: Refs under the refs/remotes/ namespace, point to RevCommit
  • Tags: Refs under the refs/tags namespace, point to RevTag
  • Transaction refs: refs under the transactions/ namespace form a whole lot of refs like the ones in the root repository (e.g. transactions//HEAD, transactions//refs/heads/master, etc. They are created when the transaction namespace is created as a copy of the current state of all the refs in the repository, and when the transaction is committed, the refs that have changed in the transaction namespace override the ones in the main repository ref set.
  • #WORK_HEAD is a ref that points to the root RevTree that represents the current working tree
  • #STAGE_HEAD is a ref that points to the root RevTree that represents the current staging area
    [中]指向表示存储库修订图中入口点的RevObject的命名指针。
    提交历史由一个DAG的提交组成,每个提交都指向它的父提交。ref本质上是指向提交的命名指针,其中ref名称通常是分支的名称(当ref位于Refs/heads/名称空间中时),或远程存储库中分支的名称(当ref位于Refs/remotes/名称空间中时)。
    参考文献的类型
    *分支:Refs/heads名称空间下的Refs,指向RevCommit
    *远程分支:Refs/remotes/namespace下的Refs,指向RevCommit
    *标记:参考/标记命名空间下的参考,指向RevTag
    *事务引用:事务/名称空间下的引用与根存储库中的引用类似,形成了大量的引用(例如,事务//头、事务//引用/头/主等。它们是在事务命名空间作为存储库中所有引用的当前状态的副本创建时创建的,并且在提交事务时,事务命名空间中更改的引用会覆盖主存储库引用集中的引用。)。
    *#WORK_HEAD是指向表示当前工作树的根树的ref
    *#STAGE_HEAD是一个ref,指向表示当前staging区域的根RevTree

代码示例

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

/**
 * Constructs a new {@code SymRef} with the given name and target reference.
 * 
 * @param name the name of the symbolic reference
 * @param target the reference that this symbolic ref points to
 */
public SymRef(String name, Ref target) {
  super(name, target.getObjectId());
  this.target = target.getName();
}

代码示例来源: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 String toOrigInternal(String name) {
  String origName = append(txOrigNamespace, name);
  return origName;
}

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

private String refDisplayString(Ref ref) {

    String branchName = ref.getName();
    if (branchName.startsWith(Ref.HEADS_PREFIX)) {
      branchName = ref.localName();
    } else if (branchName.startsWith(Ref.REMOTES_PREFIX)) {
      branchName = branchName.substring(Ref.REMOTES_PREFIX.length());
    }
    if (ref instanceof SymRef) {
      branchName += " -> " + Ref.localName(((SymRef) ref).getTarget());
    }
    return branchName;
  }
}

代码示例来源: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 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: org.locationtech.geogig/geogig-core

@Override
protected ImmutableList<RevTag> _call() {
  List<Ref> refs = newArrayList(
      command(ForEachRef.class).setPrefixFilter(Ref.TAGS_PREFIX).call());
  List<ObjectId> tagIds = transform(refs, (r) -> r.getObjectId());
  Iterator<RevTag> alltags;
  alltags = objectDatabase().getAll(tagIds, BulkOpListener.NOOP_LISTENER, RevTag.class);
  ImmutableList<RevTag> res = ImmutableList.copyOf(alltags);
  return res;
}

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

private static Set<ObjectId> veifyRepositoryContents(Repository repo,
    Map<String, Ref> allRefs) {
  Set<ObjectId> allIds = Sets.newConcurrentHashSet();
  for (Ref ref : allRefs.values()) {
    if (ref instanceof SymRef) {
      Ref target = ref.peel();
      assertTrue(format("symref points to a non existent ref: %s", ref),
          allRefs.containsKey(target.getName()));
    } else {
      Stack<String> pathToObject = new Stack<>();
      pathToObject.push(ref.getName());
      verifyAllReachableContents(repo, ref.getObjectId(), pathToObject, allIds);
      pathToObject.pop();
    }
  }
  return allIds;
}

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

@Override
  public String apply(Ref ref) {
    return ref.getName();
  }
};

代码示例来源: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

/**
 * @return the name for this ref with the prefix removed
 */
public String localName() {
  return localName(name);
}

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

public void writeBranchCreateResponse(Ref createdBranch) throws StreamWriterException {
  out.writeStartElement("BranchCreated");
  writeElement("name", createdBranch.localName());
  writeElement("source", createdBranch.getObjectId().toString());
  out.writeEndElement(); // End BranchCreated
}

代码示例来源: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: locationtech/geogig

public @Test void prepareAndManuallyResolveAllConflicts() {
  createConflicts(TestData.point1, TestData.line1, TestData.poly1);
  PRStatus result = prepare();
  assertEquals(3, result.getNumConflicts());
  final UUID transactionId = request.getTransactionId();
  origin.resumeTransaction(transactionId);
  assertEquals(request.getTargetBranch(), origin.getRef("HEAD").peel().localName());
  //@formatter:off
  SimpleFeature c1 = TestData.clone(TestData.point1); c1.setAttribute("sp", "manually set");
  SimpleFeature c2 = TestData.clone(TestData.line1);  c2.setAttribute("sp", "manually set");
  SimpleFeature c3 = TestData.clone(TestData.poly1);  c3.setAttribute("sp", "manually set");
  //@formatter:on
  Context context = clone.checkout("issuerBranch").getContext();
  try {
    PullResult pres = context.command(PullOp.class).addRefSpec("master").call();
    fail("Expected MergeConflictsException , got " + pres);
  } catch (MergeConflictsException e) {
    assertEquals(3, e.getReport().getConflicts());
    clone.insert(c1, c2, c3).add().commit("manual conflict fix");
  }
  result = prepare();
  assertTrue(result.getMergeCommit().isPresent());
  assertTrue(result.getReport().isPresent());
  GeogigTransaction prtx = getTransaction();
  Optional<Ref> mergeRef = request.resolveMergeRef(prtx);
  assertTrue(mergeRef.isPresent());
  assertEquals(result.getMergeCommit().get(), mergeRef.get().getObjectId());
}

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

@Test
public void testLocalNameAndNamespace() {
  String ref = Ref.localName(Ref.HEADS_PREFIX + "branch1");
  assertEquals("branch1", ref);
  ref = Ref.localName(Ref.REFS_PREFIX + "commit1");
  assertEquals("commit1", ref);
  ref = Ref.localName(Ref.REMOTES_PREFIX + "origin/branch1");
  assertEquals("branch1", ref);
  ref = Ref.localName(Ref.TAGS_PREFIX + "tag1");
  assertEquals("tag1", ref);
  ref = Ref.localName("ref1");
  assertEquals("ref1", ref);
  ref = Ref.namespace(Ref.HEADS_PREFIX + "branch1");
  assertEquals(Ref.HEADS_PREFIX, ref);
  ref = Ref.namespace(Ref.REFS_PREFIX + "commit1");
  assertEquals(Ref.REFS_PREFIX, ref);
  ref = Ref.namespace(Ref.REMOTES_PREFIX + "origin/branch1");
  assertEquals(Ref.REMOTES_PREFIX + "origin/", ref);
  ref = Ref.namespace(Ref.TAGS_PREFIX + "tag1");
  assertEquals(Ref.TAGS_PREFIX, ref);
  ref = Ref.namespace("ref1");
  assertEquals("ref1", 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: 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

public Optional<String> mapToLocal(final String remoteRef) {
  Preconditions.checkNotNull(remoteRef);
  String localRef = null;
  if (isAllChildren()) {
    if (Ref.isChild(this.remoteRef, remoteRef)) {
      final String remoteRefName = remoteRef.substring(this.remoteRef.length());
      localRef = Ref.append(this.localRef, remoteRefName);
    }
  } else {
    if (remoteRef.equals(this.remoteRef)) {
      localRef = this.localRef;
    }
  }
  return Optional.ofNullable(localRef);
}

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

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

相关文章