org.eclipse.jgit.lib.Ref.getLeaf()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(182)

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

Ref.getLeaf介绍

[英]Traverse target references until #isSymbolic() is false.

If #isSymbolic() is false, returns this.

If #isSymbolic() is true, this method recursively traverses #getTarget() until #isSymbolic() returns false.

This method is effectively

  1. return isSymbolic() ? getTarget().getLeaf() : this;

[中]遍历目标引用,直到#isSymbolic()为false。
如果#isSymbolic()为false,则返回该值。
如果#isSymbolic()为true,则此方法递归遍历#getTarget(),直到#isSymbolic()返回false。
这种方法是有效的

  1. return isSymbolic() ? getTarget().getLeaf() : this;

代码示例

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /**
  2. * Add a reference to push.
  3. *
  4. * @param ref
  5. * the source reference. The remote name will match.
  6. * @return {@code this}.
  7. */
  8. public PushCommand add(Ref ref) {
  9. refSpecs.add(new RefSpec(ref.getLeaf().getName()));
  10. return this;
  11. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. private static void findSymrefs(
  2. final RefAdvertiser adv, final Map<String, Ref> refs) {
  3. Ref head = refs.get(Constants.HEAD);
  4. if (head != null && head.isSymbolic()) {
  5. adv.addSymref(Constants.HEAD, head.getLeaf().getName());
  6. }
  7. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /**
  2. * Get ref that HEAD points to in the current submodule's repository
  3. *
  4. * @return ref name, null on failures
  5. * @throws java.io.IOException
  6. */
  7. public String getHeadRef() throws IOException {
  8. try (Repository subRepo = getRepository()) {
  9. if (subRepo == null) {
  10. return null;
  11. }
  12. Ref head = subRepo.exactRef(Constants.HEAD);
  13. return head != null ? head.getLeaf().getName() : null;
  14. }
  15. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /** {@inheritDoc} */
  2. @Override
  3. public Ref peel(Ref ref) throws IOException {
  4. Ref oldLeaf = ref.getLeaf();
  5. if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null) {
  6. return ref;
  7. }
  8. return recreate(ref, doPeel(oldLeaf));
  9. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. if (ref != null) {
  2. if (ref.isSymbolic())
  3. ref = ref.getLeaf();
  4. remoteName = parent.getConfig().getString(
  5. ConfigConstants.CONFIG_BRANCH_SECTION,

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /**
  2. * Get branch that HEAD currently points to
  3. *
  4. * @param subRepo
  5. * a {@link org.eclipse.jgit.lib.Repository} object.
  6. * @return shortened branch name, null on failures
  7. * @throws java.io.IOException
  8. */
  9. protected String getHeadBranch(Repository subRepo) throws IOException {
  10. Ref head = subRepo.exactRef(Constants.HEAD);
  11. if (head != null && head.isSymbolic())
  12. return Repository.shortenRefName(head.getLeaf().getName());
  13. else
  14. return null;
  15. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. String targetName = target.getLeaf().getName();
  2. if (!targetName.equals(Constants.R_HEADS + Constants.MASTER)) {
  3. String targetShortName = Repository.shortenRefName(targetName);

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. if (head != null && head.getLeaf().getName().equals(HEAD)) {
  2. refs.add(head);

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /** {@inheritDoc} */
  2. @Override
  3. protected boolean tryLock(boolean deref) throws IOException {
  4. dstRef = getRef();
  5. if (deref)
  6. dstRef = dstRef.getLeaf();
  7. if (dstRef.isSymbolic())
  8. setOldObjectId(null);
  9. else
  10. setOldObjectId(dstRef.getObjectId());
  11. return true;
  12. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. void stored(RefDirectoryUpdate update, FileSnapshot snapshot) {
  2. final ObjectId target = update.getNewObjectId().copy();
  3. final Ref leaf = update.getRef().getLeaf();
  4. putLooseRef(new LooseUnpeeled(snapshot, leaf.getName(), target));
  5. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /** {@inheritDoc} */
  2. @Override
  3. public Ref peel(Ref ref) throws IOException {
  4. final Ref leaf = ref.getLeaf();
  5. if (leaf.isPeeled() || leaf.getObjectId() == null)
  6. return ref;
  7. ObjectIdRef newLeaf = doPeel(leaf);
  8. // Try to remember this peeling in the cache, so we don't have to do
  9. // it again in the future, but only if the reference is unchanged.
  10. if (leaf.getStorage().isLoose()) {
  11. RefList<LooseRef> curList = looseRefs.get();
  12. int idx = curList.find(leaf.getName());
  13. if (0 <= idx && curList.get(idx) == leaf) {
  14. LooseRef asPeeled = ((LooseRef) leaf).peel(newLeaf);
  15. RefList<LooseRef> newList = curList.set(idx, asPeeled);
  16. looseRefs.compareAndSet(curList, newList);
  17. }
  18. }
  19. return recreate(ref, newLeaf);
  20. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. try {
  2. tip = ow.parseAny(objectId);
  3. if (r.getLeaf().getName().startsWith(Constants.R_HEADS)
  4. && tip.getType() != Constants.OBJ_COMMIT) {
  5. errors.getNonCommitHeads().add(r.getLeaf().getName());

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /** {@inheritDoc} */
  2. @Override
  3. public Ref peel(Ref ref) throws IOException {
  4. final Ref oldLeaf = ref.getLeaf();
  5. if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null)
  6. return ref;
  7. Ref newLeaf = doPeel(oldLeaf);
  8. RefCache cur = read();
  9. int idx = cur.ids.find(oldLeaf.getName());
  10. if (0 <= idx && cur.ids.get(idx) == oldLeaf) {
  11. RefList<Ref> newList = cur.ids.set(idx, newLeaf);
  12. cache.compareAndSet(cur, new RefCache(newList, cur));
  13. cachePeeledState(oldLeaf, newLeaf);
  14. }
  15. return recreate(ref, newLeaf);
  16. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /** {@inheritDoc} */
  2. @Override
  3. protected boolean tryLock(boolean deref) throws IOException {
  4. shouldDeref = deref;
  5. Ref dst = getRef();
  6. if (deref)
  7. dst = dst.getLeaf();
  8. String name = dst.getName();
  9. lock = new LockFile(database.fileFor(name));
  10. if (lock.lock()) {
  11. dst = database.getRef(name);
  12. setOldObjectId(dst != null ? dst.getObjectId() : null);
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. if (resolved instanceof String) {
  2. final Ref ref = findRef((String) resolved);
  3. return ref != null ? ref.getLeaf().getObjectId() : null;
  4. } else {
  5. return (ObjectId) resolved;

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. final String myName = detachingSymbolicRef
  2. ? getRef().getName()
  3. : getRef().getLeaf().getName();
  4. if (myName.startsWith(Constants.R_HEADS) && !getRepository().isBare()) {

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. void delete(RefDirectoryUpdate update) throws IOException {
  2. Ref dst = update.getRef();
  3. if (!update.isDetachingSymbolicRef()) {
  4. dst = dst.getLeaf();

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. Ref head = repo.exactRef(Constants.HEAD);
  2. if (head != null && head.isSymbolic())
  3. refSpecs.add(new RefSpec(head.getLeaf().getName()));

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /** {@inheritDoc} */
  2. @Override
  3. public Ref peel(Ref ref) throws IOException {
  4. Ref i = ref.getLeaf();
  5. ObjectId id = i.getObjectId();
  6. if (i.isPeeled() || id == null) {
  7. return ref;
  8. }
  9. try (RevWalk rw = new RevWalk(repo)) {
  10. RevObject obj = rw.parseAny(id);
  11. if (obj instanceof RevTag) {
  12. ObjectId p = rw.peel(obj).copy();
  13. i = new ObjectIdRef.PeeledTag(PACKED, i.getName(), id, p);
  14. } else {
  15. i = new ObjectIdRef.PeeledNonTag(PACKED, i.getName(), id);
  16. }
  17. }
  18. return recreate(ref, i);
  19. }

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

  1. /**
  2. * Write the given ref update to the ref's log.
  3. *
  4. * @param update
  5. * a {@link org.eclipse.jgit.lib.RefUpdate}
  6. * @param msg
  7. * reflog message
  8. * @param deref
  9. * whether to dereference symbolic refs
  10. * @return this writer
  11. * @throws java.io.IOException
  12. */
  13. public ReflogWriter log(RefUpdate update, String msg,
  14. boolean deref) throws IOException {
  15. ObjectId oldId = update.getOldObjectId();
  16. ObjectId newId = update.getNewObjectId();
  17. Ref ref = update.getRef();
  18. PersonIdent ident = update.getRefLogIdent();
  19. if (ident == null)
  20. ident = new PersonIdent(refdb.getRepository());
  21. else
  22. ident = new PersonIdent(ident);
  23. byte[] rec = encode(oldId, newId, ident, msg);
  24. if (deref && ref.isSymbolic()) {
  25. log(ref.getName(), rec);
  26. log(ref.getLeaf().getName(), rec);
  27. } else
  28. log(ref.getName(), rec);
  29. return this;
  30. }

相关文章