/** * Returns all refs. * <p> * This includes {@code HEAD}, branches under {@code ref/heads/}, tags * under {@code refs/tags/}, etc. It does not include pseudo-refs like * {@code FETCH_HEAD}; for those, see {@link #getAdditionalRefs}. * <p> * Symbolic references to a non-existent ref (for example, * {@code HEAD} pointing to a branch yet to be born) are not included. * <p> * Callers interested in only a portion of the ref hierarchy can call * {@link #getRefsByPrefix} instead. * * @return immutable list of all refs. * @throws java.io.IOException * the reference space cannot be accessed. * @since 5.0 */ @NonNull public List<Ref> getRefs() throws IOException { return getRefsByPrefix(ALL); }
/** * Returns refs whose names start with one of the given prefixes. * <p> * The default implementation uses {@link #getRefsByPrefix(String)}. * Implementors of {@link RefDatabase} should override this method directly * if a better implementation is possible. * * @param prefixes * strings that names of refs should start with. * @return immutable list of refs whose names start with one of * {@code prefixes}. Refs can be unsorted and may contain duplicates * if the prefixes overlap. * @throws java.io.IOException * the reference space cannot be accessed. * @since 5.2 */ @NonNull public List<Ref> getRefsByPrefix(String... prefixes) throws IOException { List<Ref> result = new ArrayList<>(); for (String prefix : prefixes) { result.addAll(getRefsByPrefix(prefix)); } return Collections.unmodifiableList(result); }
private void addPrefix(String prefix, Map<ObjectId, String> nonCommits, FIFORevQueue pending) throws IOException { for (Ref ref : repo.getRefDatabase().getRefsByPrefix(prefix)) addRef(ref, nonCommits, pending); }
/** {@inheritDoc} */ @Override public List<Ref> getAdditionalRefs() throws IOException { Collection<Ref> txnRefs; if (txnNamespace != null) { txnRefs = bootstrap.getRefsByPrefix(txnNamespace); } else { Ref r = bootstrap.exactRef(txnCommitted); if (r != null && r.getObjectId() != null) { txnRefs = Collections.singleton(r); } else { txnRefs = Collections.emptyList(); } } List<Ref> otherRefs = bootstrap.getAdditionalRefs(); List<Ref> all = new ArrayList<>(txnRefs.size() + otherRefs.size()); all.addAll(txnRefs); all.addAll(otherRefs); return all; }
private Map<String, Ref> getFilteredRefs(Collection<String> refPrefixes) throws IOException { if (refPrefixes.isEmpty()) { return getAdvertisedOrDefaultRefs(); } if (refs == null && !advertiseRefsHookCalled) { advertiseRefsHook.advertiseRefs(this); advertiseRefsHookCalled = true; } if (refs == null) { // Fast path: the advertised refs hook did not set advertised refs. String[] prefixes = refPrefixes.toArray(new String[0]); Map<String, Ref> rs = db.getRefDatabase().getRefsByPrefix(prefixes).stream() .collect(toMap(Ref::getName, identity(), (a, b) -> b)); if (refFilter != RefFilter.DEFAULT) { return refFilter.filter(rs); } return transferConfig.getRefFilter().filter(rs); } // Slow path: filter the refs provided by the advertised refs hook. // refFilter has already been applied to refs. return refs.values().stream() .filter(ref -> refPrefixes.stream() .anyMatch(ref.getName()::startsWith)) .collect(toMap(Ref::getName, identity())); }
refs.addAll(repo.getRefDatabase().getRefsByPrefix(R_HEADS)); } else if (listMode == ListMode.REMOTE) { refs.addAll(repo.getRefDatabase().getRefsByPrefix(R_REMOTES)); } else { refs.addAll(repo.getRefDatabase().getRefsByPrefix(R_HEADS, R_REMOTES));
/** {@inheritDoc} */ @Override public List<Ref> call() throws GitAPIException { checkCallable(); List<Ref> tags = new ArrayList<>(); try (RevWalk revWalk = new RevWalk(repo)) { List<Ref> refList = repo.getRefDatabase() .getRefsByPrefix(Constants.R_TAGS); for (Ref ref : refList) { tags.add(ref); } } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } Collections.sort(tags, new Comparator<Ref>() { @Override public int compare(Ref o1, Ref o2) { return o1.getName().compareTo(o2.getName()); } }); setCallable(false); return tags; }
/** * Add all annotated tags under {@code refs/tags/} to the set that all * results must match. * <p> * Calls {@link #addRef(Ref)}; see that method for a note on matching * priority. * * @return {@code this} * @throws JGitInternalException * a low-level exception of JGit has occurred. The original * exception can be retrieved by calling * {@link java.lang.Exception#getCause()}. */ public NameRevCommand addAnnotatedTags() { checkCallable(); if (refs == null) refs = new ArrayList<>(); try { for (Ref ref : repo.getRefDatabase() .getRefsByPrefix(Constants.R_TAGS)) { ObjectId id = ref.getObjectId(); if (id != null && (walk.parseAny(id) instanceof RevTag)) addRef(ref); } } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } return this; }
/** * Packs all non-symbolic, loose refs into packed-refs. * * @throws java.io.IOException */ public void packRefs() throws IOException { Collection<Ref> refs = repo.getRefDatabase() .getRefsByPrefix(Constants.R_REFS); List<String> refsToBePacked = new ArrayList<>(refs.size()); pm.beginTask(JGitText.get().packRefs, refs.size()); try { for (Ref ref : refs) { checkCancelled(); if (!ref.isSymbolic() && ref.getStorage().isLoose()) refsToBePacked.add(ref.getName()); pm.update(1); } ((RefDirectory) repo.getRefDatabase()).pack(refsToBePacked); } finally { pm.endTask(); } }
.getRefsByPrefix(R_TAGS); Map<ObjectId, List<Ref>> tags = tagList.stream() .filter(this::filterLightweightTags)
req, req.getClientCapabilities().contains(OPTION_INCLUDE_TAG) ? db.getRefDatabase().getRefsByPrefix(R_TAGS) : null, unshallowCommits, deepenNots);
public List<Ref> getRefs(String prefix) { try { return getRepository().getRefDatabase().getRefsByPrefix(prefix); } catch (IOException e) { throw new RuntimeException(e); } }
private void addPrefix(String prefix, Map<ObjectId, String> nonCommits, FIFORevQueue pending) throws IOException { for (Ref ref : repo.getRefDatabase().getRefsByPrefix(prefix)) addRef(ref, nonCommits, pending); }
public List<RefInfo> getRefInfos(String prefix) { try (RevWalk revWalk = new RevWalk(getRepository())) { List<Ref> refs = new ArrayList<Ref>(getRepository().getRefDatabase().getRefsByPrefix(prefix)); List<RefInfo> refInfos = refs.stream() .map(ref->new RefInfo(revWalk, ref)) .filter(refInfo->refInfo.getPeeledObj() instanceof RevCommit) .collect(Collectors.toList()); Collections.sort(refInfos); Collections.reverse(refInfos); return refInfos; } catch (IOException e) { throw new RuntimeException(e); } }
Ref findMostRecentTag() throws IOException { return getLast( getDb().getRefsByPrefix( TAG_PREFIX + VERSION_PREFIX ) ); }
Ref findMostRecentTag() throws IOException { return getLast( getDb().getRefsByPrefix( TAG_PREFIX + VERSION_PREFIX ) ); }
Ref findMostRecentTag() throws IOException { return getLast( getDb().getRefsByPrefix( TAG_PREFIX + VERSION_PREFIX ) ); }
private void collect(Project project) { List<CollectingWork> works = new ArrayList<>(); try (RevWalk revWalk = new RevWalk(project.getRepository())) { Collection<Ref> refs = new ArrayList<>(); refs.addAll(project.getRepository().getRefDatabase().getRefsByPrefix(Constants.R_HEADS)); refs.addAll(project.getRepository().getRefDatabase().getRefsByPrefix(Constants.R_TAGS)); for (Ref ref: refs) { RevObject revObj = revWalk.peel(revWalk.parseAny(ref.getObjectId())); if (revObj instanceof RevCommit) works.add(new CollectingWork(PRIORITY, (RevCommit) revObj, ref.getName())); } } catch (IOException e) { throw new RuntimeException(e); } Collections.sort(works, new CommitTimeComparator()); for (CollectingWork work: works) batchWorkManager.submit(getBatchWorker(project.getId()), work); }
@Override public Map<String, GitTag> getTags() throws GitRepositoryException { Map<String, GitTag> tags = new HashMap<>(); try (RevWalk revWalk = getRevWalk()){ for (Ref tag : repository.getRefDatabase().getRefsByPrefix(R_TAGS)) { try { RevTag revTag = revWalk.lookupTag(tag.getObjectId()); RevObject object = revWalk.peel(revTag); if (object instanceof RevCommit) { tags.put(object.getName(), new JGitTag(revTag)); } } catch (MissingObjectException ignored) {} } } catch (IOException e) { throw new GitRepositoryException("The tags could not be resolved.", e); } return tags; }
private void excludeRemoteRefs(ObjectWalk walk) throws IOException { RefDatabase refDatabase = getRepository().getRefDatabase(); List<Ref> remoteRefs = refDatabase.getRefsByPrefix(remote()); for (Ref r : remoteRefs) { ObjectId oid = r.getPeeledObjectId(); if (oid == null) { oid = r.getObjectId(); } if (oid == null) { // ignore (e.g. symbolic, ...) continue; } RevObject o = walk.parseAny(oid); if (o.getType() == Constants.OBJ_COMMIT || o.getType() == Constants.OBJ_TAG) { walk.markUninteresting(o); } } }