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

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

本文整理了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

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

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

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

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

  1. private Ref toLocal(Ref remoteRef) {
  2. Optional<String> localName = remote.mapToRemote(remoteRef.getName());
  3. Preconditions.checkArgument(localName.isPresent(), "Can't map %s to local ref using %s",
  4. remoteRef.getName(), remote.getFetchSpec());
  5. Ref localRef;
  6. if (remoteRef instanceof SymRef) {
  7. Ref target = toLocal(remoteRef.peel());
  8. localRef = new SymRef(localName.get(), target);
  9. } else {
  10. localRef = new Ref(localName.get(), remoteRef.getObjectId());
  11. }
  12. return localRef;
  13. }

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

  1. private Ref toRemote(Ref localRef) {
  2. Optional<String> remoteName = remote.mapToLocal(localRef.getName());
  3. Preconditions.checkArgument(remoteName.isPresent(), "Can't map %s to remote ref using %s",
  4. localRef.getName(), remote.getFetchSpec());
  5. Ref remoteRef;
  6. if (localRef instanceof SymRef) {
  7. Ref target = toRemote(localRef.peel());
  8. remoteRef = new SymRef(remoteName.get(), target);
  9. } else {
  10. remoteRef = new Ref(remoteName.get(), localRef.getObjectId());
  11. }
  12. return remoteRef;
  13. }

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

  1. private Ref toLocal(Ref localRemoteRef) {
  2. final Remote remote = this.remote;
  3. if (localRemoteRef.namespace().equals(Ref.TAGS_PREFIX)) {
  4. return localRemoteRef;
  5. }
  6. final String localName = localRemoteRef.localName();
  7. final String remoteNamespace = localRemoteRef.namespace();
  8. final String expectedRemotePrefix = Ref.REMOTES_PREFIX + remote.getName() + "/";
  9. Preconditions.checkArgument(remoteNamespace.equals(expectedRemotePrefix));
  10. final String localPrefix = Ref.HEAD.equals(localName) ? "" : Ref.HEADS_PREFIX;
  11. final String localRefName = localPrefix + localName;
  12. Ref ref = null;
  13. if (localRemoteRef instanceof SymRef) {
  14. SymRef sr = (SymRef) localRemoteRef;
  15. Ref localTarget = toLocal(new Ref(sr.getTarget(), sr.getObjectId()));
  16. ref = new SymRef(localRefName, localTarget);
  17. } else {
  18. ref = new Ref(localRefName, localRemoteRef.getObjectId());
  19. }
  20. return ref;
  21. }

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

  1. private Ref toRemote(Ref localRef) {
  2. if (localRef.namespace().equals(Ref.TAGS_PREFIX)) {
  3. return localRef;
  4. }
  5. checkArgument(!localRef.getName().startsWith(Ref.REMOTES_PREFIX),
  6. "ref is already in a remotes namespace: %s", localRef);
  7. final String remoteNamespace = Ref.REMOTES_PREFIX + remote.getName() + "/";
  8. final String remoteRefName = remoteNamespace + localRef.localName();
  9. Ref remoteRef;
  10. if (localRef instanceof SymRef) {
  11. SymRef sr = (SymRef) localRef;
  12. String localtarget = sr.getTarget();
  13. Ref remoteTarget = toRemote(new Ref(localtarget, sr.getObjectId()));
  14. remoteRef = new SymRef(remoteRefName, remoteTarget);
  15. } else {
  16. remoteRef = new Ref(remoteRefName, localRef.getObjectId());
  17. }
  18. return remoteRef;
  19. }

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

  1. private Optional<Ref> resolveRef(@Nullable String head, Context repo) {
  2. Ref ref = null;
  3. if (head != null) {
  4. ref = repo.command(RefParse.class).setName(head).call().orNull();
  5. if (null == ref) {
  6. RevObject root = repo.command(RevObjectParse.class).setRefSpec(head).call()
  7. .orNull();
  8. if (null != root) {
  9. ref = new Ref(root.getType().toString(), root.getId());
  10. }
  11. }
  12. }
  13. return Optional.ofNullable(ref);
  14. }

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

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

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

  1. @Test
  2. public void testEquals() throws Exception {
  3. Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid);
  4. Ref testRef2 = new Ref(Ref.REFS_PREFIX + "commit2", oid2);
  5. assertFalse(testRef.equals(testRef2));
  6. testRef2 = new Ref(Ref.REFS_PREFIX + "commit1", oid3);
  7. assertFalse(testRef.equals(testRef2));
  8. assertFalse(testRef.equals("not a ref"));
  9. assertTrue(testRef.equals(testRef));
  10. }

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

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

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

  1. @Test
  2. public void testReinitializeExistingRepo() throws Exception {
  3. when(injector.repository()).thenReturn(mockRepo);
  4. Optional<Ref> absent = Optional.absent();
  5. when(mockRefParse.call()).thenReturn(absent);
  6. Repository created = init.call();
  7. assertSame(mockRepo, created);
  8. verify(mockUpdateRef, times(3)).call();
  9. verify(mockUpdateSymRef, times(1)).call();
  10. assertTrue(new File(workingDir, ".geogig").exists());
  11. assertTrue(new File(workingDir, ".geogig").isDirectory());
  12. Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me"));
  13. when(mockRefParse.call()).thenReturn(Optional.of(master));
  14. Context injector = mock(Context.class);
  15. when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse);
  16. when(injector.platform()).thenReturn(platform);
  17. when(injector.repository()).thenReturn(mockRepo);
  18. init.setContext(injector);
  19. assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent());
  20. assertNotNull(init.call());
  21. verify(platform, atLeastOnce()).pwd();
  22. assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent());
  23. verify(injector, never()).command(eq(UpdateRef.class));
  24. verify(injector, never()).command(eq(UpdateSymRef.class));
  25. assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID));
  26. }

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

  1. @Test
  2. public void testReinitializeExistingRepo() throws Exception {
  3. when(injector.repository()).thenReturn(mockRepo);
  4. Optional<Ref> absent = Optional.absent();
  5. when(mockRefParse.call()).thenReturn(absent);
  6. Repository created = init.call();
  7. assertSame(mockRepo, created);
  8. verify(mockUpdateRef, times(3)).call();
  9. verify(mockUpdateSymRef, times(1)).call();
  10. assertTrue(new File(workingDir, ".geogig").exists());
  11. assertTrue(new File(workingDir, ".geogig").isDirectory());
  12. Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me"));
  13. when(mockRefParse.call()).thenReturn(Optional.of(master));
  14. Context injector = mock(Context.class);
  15. when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse);
  16. when(injector.platform()).thenReturn(platform);
  17. when(injector.repository()).thenReturn(mockRepo);
  18. init.setContext(injector);
  19. assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent());
  20. assertNotNull(init.call());
  21. verify(platform, atLeastOnce()).pwd();
  22. assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent());
  23. verify(injector, never()).command(eq(UpdateRef.class));
  24. verify(injector, never()).command(eq(UpdateSymRef.class));
  25. assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID));
  26. }

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

  1. private Iterable<RefDiff> updateLocalRemoteRefs(Remote remote, List<LocalRemoteRef> fetchSpecs,
  2. final boolean prune) {
  3. List<RefDiff> updatedLocalRemoteRefs = new ArrayList<>();
  4. for (LocalRemoteRef expected : fetchSpecs) {
  5. final boolean isNew = expected.isNew;
  6. final boolean remoteDeleted = expected.remoteDeleted;
  7. final String localName = expected.localRemoteRef.getName();
  8. if (remoteDeleted) {
  9. if (prune) {
  10. updatedLocalRemoteRefs.add(RefDiff.removed(expected.localRemoteRef));
  11. command(UpdateRef.class).setName(localName)
  12. .setOldValue(expected.localRemoteRef.getObjectId()).setDelete(true)
  13. .call();
  14. }
  15. continue;
  16. }
  17. RefDiff localRefDiff;
  18. Ref oldRef = isNew ? null : expected.localRemoteRef;
  19. Ref newRef = new Ref(localName, expected.remoteRef.getObjectId());
  20. command(UpdateRef.class).setName(localName).setNewValue(newRef.getObjectId()).call();
  21. localRefDiff = new RefDiff(oldRef, newRef);
  22. updatedLocalRemoteRefs.add(localRefDiff);
  23. }
  24. return updatedLocalRemoteRefs;
  25. }

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

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

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

  1. @Test
  2. public void testConstructor() throws Exception {
  3. Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid);
  4. assertEquals(Ref.REFS_PREFIX + "commit1", testRef.getName());
  5. assertEquals(Ref.REFS_PREFIX, testRef.namespace());
  6. assertEquals("commit1", testRef.localName());
  7. assertEquals(oid, testRef.getObjectId());
  8. }

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

  1. @Test
  2. public void testPushNewBranch() throws Exception {
  3. localRepo.command(BranchCreateOp.class).setName("newbranch").call();
  4. localRepo.command(CheckoutOp.class).setSource("newbranch").call();
  5. // Add a commit to the local repository
  6. insertAndAdd(localRepo, lines3);
  7. insertAndAdd(localRepo, points1_modified);
  8. localRepo.command(CommitOp.class).call();
  9. final Ref branch1 = getRef(localRepo, "newbranch").get();
  10. // Push the commit
  11. PushOp push = pushOp();
  12. push.addRefSpec("newbranch");
  13. TransferSummary summary = push.call();
  14. assertSummary(summary, remote.getPushURL(), absent(),
  15. Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId())));
  16. TestSupport.verifyRepositoryContents(remoteRepo);
  17. }

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

  1. @Test
  2. public void testPushNewBranch() throws Exception {
  3. localRepo.command(BranchCreateOp.class).setName("newbranch").call();
  4. localRepo.command(CheckoutOp.class).setSource("newbranch").call();
  5. // Add a commit to the local repository
  6. insertAndAdd(localRepo, lines3);
  7. insertAndAdd(localRepo, points1_modified);
  8. localRepo.command(CommitOp.class).call();
  9. final Ref branch1 = getRef(localRepo, "newbranch").get();
  10. // Push the commit
  11. PushOp push = pushOp();
  12. push.addRefSpec("newbranch");
  13. TransferSummary summary = push.call();
  14. assertSummary(summary, remote.getPushURL(), absent(),
  15. Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId())));
  16. TestSupport.verifyRepositoryContents(remoteRepo);
  17. }

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

  1. @Test
  2. public void testPushWithRefSpec() throws Exception {
  3. // Add a commit to the local repository
  4. insertAndAdd(localRepo, lines3);
  5. RevCommit commit = localRepo.command(CommitOp.class).call();
  6. expectedMaster.addFirst(commit);
  7. // Push the commit
  8. PushOp push = pushOp();
  9. push.addRefSpec("master:NewRemoteBranch");
  10. TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call();
  11. assertSummary(summary, remote.getPushURL(), null,
  12. new Ref("refs/heads/NewRemoteBranch", commit.getId()));
  13. assertTrue(getRef(remoteRepo, "NewRemoteBranch").isPresent());
  14. // verify that the remote got the commit
  15. remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call();
  16. List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call());
  17. assertEquals(expectedMaster, logged);
  18. // verify that the local reference of the remote master is updated
  19. Optional<Ref> ref = localRepo.command(RefParse.class)
  20. .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/NewRemoteBranch")).call();
  21. assertTrue(ref.isPresent());
  22. assertEquals(logged.get(0).getId(), ref.get().getObjectId());
  23. TestSupport.verifyRepositoryContents(remoteRepo);
  24. }

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

  1. @Test
  2. public void testSymRef() {
  3. Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1",
  4. ObjectId.valueOf("abc123000000000000001234567890abcdef0000"));
  5. SymRef symRef = new SymRef("TestRef", testRef);
  6. assertEquals(testRef.getName(), symRef.getTarget());
  7. String symRefString = symRef.toString();
  8. assertEquals("TestRef -> " + "[" + testRef.getName() + " -> "
  9. + testRef.getObjectId().toString() + "]", symRefString);
  10. }
  11. }

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

  1. @Test
  2. public void testPushWithRefSpec() throws Exception {
  3. // Add a commit to the local repository
  4. insertAndAdd(localRepo, lines3);
  5. RevCommit commit = localRepo.command(CommitOp.class).call();
  6. expectedMaster.addFirst(commit);
  7. // Push the commit
  8. PushOp push = pushOp();
  9. push.addRefSpec("master:NewRemoteBranch");
  10. TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call();
  11. assertSummary(summary, remote.getPushURL(), null,
  12. new Ref("refs/heads/NewRemoteBranch", commit.getId()));
  13. assertTrue(getRef(remoteRepo, "NewRemoteBranch").isPresent());
  14. // verify that the remote got the commit
  15. remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call();
  16. List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call());
  17. assertEquals(expectedMaster, logged);
  18. // verify that the local reference of the remote master is updated
  19. Optional<Ref> ref = localRepo.command(RefParse.class)
  20. .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/NewRemoteBranch")).call();
  21. assertTrue(ref.isPresent());
  22. assertEquals(logged.get(0).getId(), ref.get().getObjectId());
  23. TestSupport.verifyRepositoryContents(remoteRepo);
  24. }

相关文章