/** * Check if any refs exist in the ref database. * <p> * This uses the same definition of refs as {@link #getRefs()}. In * particular, returns {@code false} in a new repository with no refs * under {@code refs/} and {@code HEAD} pointing to a branch yet to be * born, and returns {@code true} in a repository with no refs under * {@code refs/} and a detached {@code HEAD} pointing to history. * * @return true if the database has refs. * @throws java.io.IOException * the reference space cannot be accessed. * @since 5.0 */ public boolean hasRefs() throws IOException { return !getRefs().isEmpty(); }
private Collection<Ref> getAllRefs() throws IOException { Collection<Ref> refs = refdb.getRefs(); List<Ref> addl = refdb.getAdditionalRefs(); if (!addl.isEmpty()) { List<Ref> all = new ArrayList<>(refs.size() + addl.size()); all.addAll(refs); // add additional refs which start with refs/ for (Ref r : addl) { if (r.getName().startsWith(Constants.R_REFS)) { all.add(r); } } return all; } return refs; }
/** * 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<>(); } }
@Override public void checkWants(UploadPack up, List<ObjectId> wants) throws PackProtocolException, IOException { checkNotAdvertisedWants(up, wants, refIdSet(up.getRepository().getRefDatabase().getRefs())); } }
public Collection<String> getConflictingNames(String name) throws IOException { Map<String, Ref> allRefs = getRefs(ALL);
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; }
/** {@inheritDoc} */ @Override public void scanForRepoChanges() throws IOException { getRefDatabase().getRefs(); // This will look for changes to refs detectIndexChanges(); }
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; }
/** * Returns a collection of all refs and additional refs. * * Additional refs which don't start with "refs/" are not returned because * they should not save objects from being garbage collected. Examples for * such references are ORIG_HEAD, MERGE_HEAD, FETCH_HEAD and * CHERRY_PICK_HEAD. * * @return a collection of refs pointing to live objects. * @throws IOException */ private Collection<Ref> getAllRefs() throws IOException { RefDatabase refdb = repo.getRefDatabase(); Collection<Ref> refs = refdb.getRefs(); List<Ref> addl = refdb.getAdditionalRefs(); if (!addl.isEmpty()) { List<Ref> all = new ArrayList<>(refs.size() + addl.size()); all.addAll(refs); // add additional refs which start with refs/ for (Ref r : addl) { checkCancelled(); if (r.getName().startsWith(Constants.R_REFS)) { all.add(r); } } return all; } return refs; }
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; }
@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); } } } }
for (Ref r : refDb.getRefs()) { Storage storage = r.getStorage(); if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED)
localRefs = transport.local.getRefDatabase().getRefs(); } catch (IOException e) { throw new TransportException(transport.uri, e.getMessage(), e);
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); } } }
pm.beginTask(JGitText.get().countingObjects, ProgressMonitor.UNKNOWN); try (ObjectWalk ow = new ObjectWalk(repo)) { for (Ref r : repo.getRefDatabase().getRefs()) { ObjectId objectId = r.getObjectId(); if (objectId == null) {
for (Ref ref : getRepository().getRefDatabase().getRefs()) { if(!ref.isPeeled()) ref = getRepository().getRefDatabase().peel(ref);
Map<String, Ref> refs = refdb.getRefs(ALL); batch.addCommand(prepareCommit(git, refs, committed.getNewId()));
private void markReachable(Set<ObjectId> have, int maxTime) throws IOException { for (Ref r : local.getRefDatabase().getRefs()) { ObjectId id = r.getPeeledObjectId(); if (id == null)