/** * Add a reference to push. * * @param ref * the source reference. The remote name will match. * @return {@code this}. */ public PushCommand add(Ref ref) { refSpecs.add(new RefSpec(ref.getLeaf().getName())); return this; }
private static void findSymrefs( final RefAdvertiser adv, final Map<String, Ref> refs) { Ref head = refs.get(Constants.HEAD); if (head != null && head.isSymbolic()) { adv.addSymref(Constants.HEAD, head.getLeaf().getName()); } }
/** * Get ref that HEAD points to in the current submodule's repository * * @return ref name, null on failures * @throws java.io.IOException */ public String getHeadRef() throws IOException { try (Repository subRepo = getRepository()) { if (subRepo == null) { return null; } Ref head = subRepo.exactRef(Constants.HEAD); return head != null ? head.getLeaf().getName() : null; } }
/** {@inheritDoc} */ @Override public Ref peel(Ref ref) throws IOException { Ref oldLeaf = ref.getLeaf(); if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null) { return ref; } return recreate(ref, doPeel(oldLeaf)); }
if (ref != null) { if (ref.isSymbolic()) ref = ref.getLeaf(); remoteName = parent.getConfig().getString( ConfigConstants.CONFIG_BRANCH_SECTION,
/** * Get branch that HEAD currently points to * * @param subRepo * a {@link org.eclipse.jgit.lib.Repository} object. * @return shortened branch name, null on failures * @throws java.io.IOException */ protected String getHeadBranch(Repository subRepo) throws IOException { Ref head = subRepo.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) return Repository.shortenRefName(head.getLeaf().getName()); else return null; }
String targetName = target.getLeaf().getName(); if (!targetName.equals(Constants.R_HEADS + Constants.MASTER)) { String targetShortName = Repository.shortenRefName(targetName);
if (head != null && head.getLeaf().getName().equals(HEAD)) { refs.add(head);
/** {@inheritDoc} */ @Override protected boolean tryLock(boolean deref) throws IOException { dstRef = getRef(); if (deref) dstRef = dstRef.getLeaf(); if (dstRef.isSymbolic()) setOldObjectId(null); else setOldObjectId(dstRef.getObjectId()); return true; }
void stored(RefDirectoryUpdate update, FileSnapshot snapshot) { final ObjectId target = update.getNewObjectId().copy(); final Ref leaf = update.getRef().getLeaf(); putLooseRef(new LooseUnpeeled(snapshot, leaf.getName(), target)); }
/** {@inheritDoc} */ @Override public Ref peel(Ref ref) throws IOException { final Ref leaf = ref.getLeaf(); if (leaf.isPeeled() || leaf.getObjectId() == null) return ref; ObjectIdRef newLeaf = doPeel(leaf); // Try to remember this peeling in the cache, so we don't have to do // it again in the future, but only if the reference is unchanged. if (leaf.getStorage().isLoose()) { RefList<LooseRef> curList = looseRefs.get(); int idx = curList.find(leaf.getName()); if (0 <= idx && curList.get(idx) == leaf) { LooseRef asPeeled = ((LooseRef) leaf).peel(newLeaf); RefList<LooseRef> newList = curList.set(idx, asPeeled); looseRefs.compareAndSet(curList, newList); } } return recreate(ref, newLeaf); }
/** {@inheritDoc} */ @Override public Ref peel(Ref ref) throws IOException { final Ref oldLeaf = ref.getLeaf(); if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null) return ref; Ref newLeaf = doPeel(oldLeaf); RefCache cur = read(); int idx = cur.ids.find(oldLeaf.getName()); if (0 <= idx && cur.ids.get(idx) == oldLeaf) { RefList<Ref> newList = cur.ids.set(idx, newLeaf); cache.compareAndSet(cur, new RefCache(newList, cur)); cachePeeledState(oldLeaf, newLeaf); } return recreate(ref, newLeaf); }
/** {@inheritDoc} */ @Override protected boolean tryLock(boolean deref) throws IOException { shouldDeref = deref; Ref dst = getRef(); if (deref) dst = dst.getLeaf(); String name = dst.getName(); lock = new LockFile(database.fileFor(name)); if (lock.lock()) { dst = database.getRef(name); setOldObjectId(dst != null ? dst.getObjectId() : null); return true; } else { return false; } }
if (resolved instanceof String) { final Ref ref = findRef((String) resolved); return ref != null ? ref.getLeaf().getObjectId() : null; } else { return (ObjectId) resolved;
final String myName = detachingSymbolicRef ? getRef().getName() : getRef().getLeaf().getName(); if (myName.startsWith(Constants.R_HEADS) && !getRepository().isBare()) {
void delete(RefDirectoryUpdate update) throws IOException { Ref dst = update.getRef(); if (!update.isDetachingSymbolicRef()) { dst = dst.getLeaf();
Ref head = repo.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) refSpecs.add(new RefSpec(head.getLeaf().getName()));
/** {@inheritDoc} */ @Override public Ref peel(Ref ref) throws IOException { Ref i = ref.getLeaf(); ObjectId id = i.getObjectId(); if (i.isPeeled() || id == null) { return ref; } try (RevWalk rw = new RevWalk(repo)) { RevObject obj = rw.parseAny(id); if (obj instanceof RevTag) { ObjectId p = rw.peel(obj).copy(); i = new ObjectIdRef.PeeledTag(PACKED, i.getName(), id, p); } else { i = new ObjectIdRef.PeeledNonTag(PACKED, i.getName(), id); } } return recreate(ref, i); }
/** * Write the given ref update to the ref's log. * * @param update * a {@link org.eclipse.jgit.lib.RefUpdate} * @param msg * reflog message * @param deref * whether to dereference symbolic refs * @return this writer * @throws java.io.IOException */ public ReflogWriter log(RefUpdate update, String msg, boolean deref) throws IOException { ObjectId oldId = update.getOldObjectId(); ObjectId newId = update.getNewObjectId(); Ref ref = update.getRef(); PersonIdent ident = update.getRefLogIdent(); if (ident == null) ident = new PersonIdent(refdb.getRepository()); else ident = new PersonIdent(ident); byte[] rec = encode(oldId, newId, ident, msg); if (deref && ref.isSymbolic()) { log(ref.getName(), rec); log(ref.getLeaf().getName(), rec); } else log(ref.getName(), rec); return this; }