/** * Constructor for StashDropCommand. * * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. */ public StashDropCommand(Repository repo) { super(repo); if (!(repo.getRefDatabase() instanceof RefDirectory)) { throw new UnsupportedOperationException( JGitText.get().stashDropNotSupported); } }
/** * Get mutable map of all known refs, including symrefs like HEAD that may * not point to any object yet. * * @return mutable map of all known refs (heads, tags, remotes). * @deprecated use {@code getRefDatabase().getRefs()} instead. */ @Deprecated @NonNull public Map<String, Ref> getAllRefs() { try { return getRefDatabase().getRefs(RefDatabase.ALL); } catch (IOException e) { return new HashMap<>(); } }
/** * Get mutable map of all tags * * @return mutable map of all tags; key is short tag name ("v1.0") and value * of the entry contains the ref with the full tag name * ("refs/tags/v1.0"). * @deprecated use {@code getRefDatabase().getRefsByPrefix(R_TAGS)} instead */ @Deprecated @NonNull public Map<String, Ref> getTags() { try { return getRefDatabase().getRefs(Constants.R_TAGS); } catch (IOException e) { return new HashMap<>(); } }
private void addPrefix(String prefix, Map<ObjectId, String> nonCommits, FIFORevQueue pending) throws IOException { for (Ref ref : repo.getRefDatabase().getRefsByPrefix(prefix)) addRef(ref, nonCommits, pending); }
@Override public void checkWants(UploadPack up, List<ObjectId> wants) throws PackProtocolException, IOException { checkNotAdvertisedWants(up, wants, refIdSet(up.getRepository().getRefDatabase().getRefs())); } }
private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException { if (refs != null) { return refs; } if (!advertiseRefsHookCalled) { advertiseRefsHook.advertiseRefs(this); advertiseRefsHookCalled = true; } if (refs == null) { // Fall back to all refs. setAdvertisedRefs( db.getRefDatabase().getRefs().stream() .collect(toMap(Ref::getName, identity()))); } return refs; }
/** * Create a command to rename a ref in this repository * * @param fromRef * name of ref to rename from * @param toRef * name of ref to rename to * @return an update command that knows how to rename a branch to another. * @throws java.io.IOException * the rename could not be performed. */ @NonNull public RefRename renameRef(String fromRef, String toRef) throws IOException { return getRefDatabase().newRename(fromRef, toRef); }
/** * Get a ref by name. * * @param name * the name of the ref to lookup. Must not be a short-hand * form; e.g., "master" is not automatically expanded to * "refs/heads/master". * @return the Ref with the given name, or {@code null} if it does not exist * @throws java.io.IOException * @since 4.2 */ @Nullable public final Ref exactRef(String name) throws IOException { return getRefDatabase().exactRef(name); }
/** * Search for a ref by (possibly abbreviated) name. * * @param name * the name of the ref to lookup. May be a short-hand form, e.g. * "master" which is is automatically expanded to * "refs/heads/master" if "refs/heads/master" already exists. * @return the Ref with the given name, or {@code null} if it does not exist * @throws java.io.IOException * @since 4.2 */ @Nullable public final Ref findRef(String name) throws IOException { return getRefDatabase().getRef(name); }
/** * Create a command to update, create or delete a ref in this repository. * * @param ref * name of the ref the caller wants to modify. * @param detach * true to create a detached head * @return an update command. The caller must finish populating this command * and then invoke one of the update methods to actually make a * change. * @throws java.io.IOException * a symbolic ref was passed in and could not be resolved back * to the base ref, as the symbolic ref could not be read. */ @NonNull public RefUpdate updateRef(String ref, boolean detach) throws IOException { return getRefDatabase().newUpdate(ref, detach); }
private static Collection<RefSpec> expandPushWildcardsFor( final Repository db, final Collection<RefSpec> specs) throws IOException { final List<Ref> localRefs = db.getRefDatabase().getRefs(); final Collection<RefSpec> procRefs = new LinkedHashSet<>(); for (RefSpec spec : specs) { if (spec.isWildcard()) { for (Ref localRef : localRefs) { if (spec.matchSource(localRef)) procRefs.add(spec.expandFromSource(localRef)); } } else { procRefs.add(spec); } } return procRefs; }
private Map<String, Ref> localRefs() throws TransportException { if (localRefs == null) { try { localRefs = transport.local.getRefDatabase() .getRefs(RefDatabase.ALL); } catch (IOException err) { throw new TransportException(JGitText.get().cannotListRefs, err); } } return localRefs; }
private ObjectId getObjectIdFromRef(Ref r) throws JGitInternalException { try { ObjectId key = repo.getRefDatabase().peel(r).getPeeledObjectId(); if (key == null) { key = r.getObjectId(); } return key; } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } }
/** * Invoked when the use count drops to zero during {@link #close()}. * <p> * The default implementation closes the object and ref databases. */ protected void doClose() { getObjectDatabase().close(); getRefDatabase().close(); }
@Override public void checkWants(UploadPack up, List<ObjectId> wants) throws PackProtocolException, IOException { if (!up.isBiDirectionalPipe()) new ReachableCommitTipRequestValidator().checkWants(up, wants); else if (!wants.isEmpty()) { Set<ObjectId> refIds = refIdSet(up.getRepository().getRefDatabase().getRefs()); for (ObjectId obj : wants) { if (!refIds.contains(obj)) throw new WantNotValidException(obj); } } } }
void load() throws IOException { close(); reader = db.newObjectReader(); Ref ref = db.getRefDatabase().exactRef(REF_NAME); if (ref == null) { // No ref, same as empty. return; } try (RevWalk rw = new RevWalk(reader)) { commit = rw.parseCommit(ref.getObjectId()); } }
@Nullable private ObjectId resolveSimple(String revstr) throws IOException { if (ObjectId.isId(revstr)) return ObjectId.fromString(revstr); if (Repository.isValidRefName("x/" + revstr)) { //$NON-NLS-1$ Ref r = getRefDatabase().getRef(revstr); if (r != null) return r.getObjectId(); } if (AbbreviatedObjectId.isId(revstr)) return resolveAbbreviation(revstr); int dashg = revstr.indexOf("-g"); //$NON-NLS-1$ if ((dashg + 5) < revstr.length() && 0 <= dashg && isHex(revstr.charAt(dashg + 2)) && isHex(revstr.charAt(dashg + 3)) && isAllHex(revstr, dashg + 4)) { // Possibly output from git describe? String s = revstr.substring(dashg + 2); if (AbbreviatedObjectId.isId(s)) return resolveAbbreviation(s); } return null; }
private void markLocalRefsComplete(Set<ObjectId> have) throws TransportException { List<Ref> refs; try { refs = local.getRefDatabase().getRefs(); } catch (IOException e) { throw new TransportException(e.getMessage(), e); } for (Ref r : refs) { try { markLocalObjComplete(revWalk.parseAny(r.getObjectId())); } catch (IOException readError) { throw new TransportException(MessageFormat.format(JGitText.get().localRefIsMissingObjects, r.getName()), readError); } } for (ObjectId id : have) { try { markLocalObjComplete(revWalk.parseAny(id)); } catch (IOException readError) { throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionMissingAssumed, id.name()), readError); } } }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Ref> call = git.tagList().call(); for (Ref ref : call) { System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); // fetch all commits for this tag LogCommand log = git.log(); Ref peeledRef = repository.getRefDatabase().peel(ref); if(peeledRef.getPeeledObjectId() != null) { log.add(peeledRef.getPeeledObjectId()); } else { log.add(ref.getObjectId()); } Iterable<RevCommit> logs = log.call(); for (RevCommit rev : logs) { System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); } } } } } }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Ref> call = git.tagList().call(); for (Ref ref : call) { System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); // fetch all commits for this tag LogCommand log = git.log(); Ref peeledRef = repository.getRefDatabase().peel(ref); if(peeledRef.getPeeledObjectId() != null) { log.add(peeledRef.getPeeledObjectId()); } else { log.add(ref.getObjectId()); } Iterable<RevCommit> logs = log.call(); for (RevCommit rev : logs) { System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); } } } } } }