List of usage examples for org.eclipse.jgit.lib RefDatabase getRefs
@NonNull @Deprecated public abstract Map<String, Ref> getRefs(String prefix) throws IOException;
From source file:com.google.gerrit.pgm.RebuildNotedb.java
License:Apache License
private void deleteDraftRefs(Repository allUsersRepo) throws IOException { RefDatabase refDb = allUsersRepo.getRefDatabase(); Map<String, Ref> allRefs = refDb.getRefs(RefNames.REFS_DRAFT_COMMENTS); BatchRefUpdate bru = refDb.newBatchUpdate(); for (Map.Entry<String, Ref> ref : allRefs.entrySet()) { bru.addCommand(new ReceiveCommand(ref.getValue().getObjectId(), ObjectId.zeroId(), RefNames.REFS_DRAFT_COMMENTS + ref.getKey())); }//from w w w .j a v a 2 s . c o m execute(bru, allUsersRepo); }
From source file:com.google.gerrit.server.change.IncludedInResolver.java
License:Apache License
private IncludedInDetail resolve() throws IOException { RefDatabase refDb = repo.getRefDatabase(); Collection<Ref> tags = refDb.getRefs(Constants.R_TAGS).values(); Collection<Ref> branches = refDb.getRefs(Constants.R_HEADS).values(); List<Ref> allTagsAndBranches = Lists.newArrayListWithCapacity(tags.size() + branches.size()); allTagsAndBranches.addAll(tags);//from w w w . j a va2 s. c o m allTagsAndBranches.addAll(branches); parseCommits(allTagsAndBranches); Set<String> allMatchingTagsAndBranches = includedIn(tipsByCommitTime, 0); IncludedInDetail detail = new IncludedInDetail(); detail.setBranches(getMatchingRefNames(allMatchingTagsAndBranches, branches)); detail.setTags(getMatchingRefNames(allMatchingTagsAndBranches, tags)); return detail; }
From source file:com.google.gerrit.server.git.ReplaceOp.java
License:Apache License
private Ref findMergedInto(ChangeContext ctx, String first, RevCommit commit) { try {/*from ww w.j a v a2s .c o m*/ RefDatabase refDatabase = ctx.getRepository().getRefDatabase(); Ref firstRef = refDatabase.exactRef(first); if (firstRef != null && isMergedInto(ctx.getRevWalk(), commit, firstRef)) { return firstRef; } for (Ref ref : refDatabase.getRefs(Constants.R_HEADS).values()) { if (isMergedInto(ctx.getRevWalk(), commit, ref)) { return ref; } } return null; } catch (IOException e) { log.warn("Can't check for already submitted change", e); return null; } }
From source file:com.google.gerrit.server.PatchLineCommentsUtil.java
License:Apache License
private Set<String> getRefNamesAllUsers(String prefix) throws OrmException { try (Repository repo = repoManager.openRepository(allUsers)) { RefDatabase refDb = repo.getRefDatabase(); return refDb.getRefs(prefix).keySet(); } catch (IOException e) { throw new OrmException(e); }//from w w w . ja v a 2 s . com }
From source file:com.google.gerrit.server.project.CreateBranch.java
License:Apache License
private RevWalk verifyConnected(final Repository repo, final ObjectId revid) throws InvalidRevisionException { try {//from www . j a v a 2 s . c o m final ObjectWalk rw = new ObjectWalk(repo); try { rw.markStart(rw.parseCommit(revid)); } catch (IncorrectObjectTypeException err) { throw new InvalidRevisionException(); } RefDatabase refDb = repo.getRefDatabase(); Iterable<Ref> refs = Iterables.concat(refDb.getRefs(Constants.R_HEADS).values(), refDb.getRefs(Constants.R_TAGS).values()); Ref rc = refDb.exactRef(RefNames.REFS_CONFIG); if (rc != null) { refs = Iterables.concat(refs, Collections.singleton(rc)); } for (Ref r : refs) { try { rw.markUninteresting(rw.parseAny(r.getObjectId())); } catch (MissingObjectException err) { continue; } } rw.checkConnectivity(); return rw; } catch (IncorrectObjectTypeException | MissingObjectException err) { throw new InvalidRevisionException(); } catch (IOException err) { log.error("Repository \"" + repo.getDirectory() + "\" may be corrupt; suggest running git fsck", err); throw new InvalidRevisionException(); } }
From source file:com.google.gerrit.server.project.RefUtil.java
License:Apache License
public static RevWalk verifyConnected(Repository repo, ObjectId revid) throws InvalidRevisionException { try {/*from w w w.ja v a 2s.c o m*/ ObjectWalk rw = new ObjectWalk(repo); try { rw.markStart(rw.parseCommit(revid)); } catch (IncorrectObjectTypeException err) { throw new InvalidRevisionException(); } RefDatabase refDb = repo.getRefDatabase(); Iterable<Ref> refs = Iterables.concat(refDb.getRefs(Constants.R_HEADS).values(), refDb.getRefs(Constants.R_TAGS).values()); Ref rc = refDb.exactRef(RefNames.REFS_CONFIG); if (rc != null) { refs = Iterables.concat(refs, Collections.singleton(rc)); } for (Ref r : refs) { try { rw.markUninteresting(rw.parseAny(r.getObjectId())); } catch (MissingObjectException err) { continue; } } rw.checkConnectivity(); return rw; } catch (IncorrectObjectTypeException | MissingObjectException err) { throw new InvalidRevisionException(); } catch (IOException err) { log.error("Repository \"" + repo.getDirectory() + "\" may be corrupt; suggest running git fsck", err); throw new InvalidRevisionException(); } }
From source file:com.google.gerrit.server.schema.Schema_108.java
License:Apache License
private static void updateProjectGroups(ReviewDb db, Repository repo, RevWalk rw, Set<Change.Id> changes) throws OrmException, IOException { // Match sorting in ReceiveCommits. rw.reset();//w w w .j a v a 2 s . c o m rw.sort(RevSort.TOPO); rw.sort(RevSort.REVERSE, true); RefDatabase refdb = repo.getRefDatabase(); for (Ref ref : refdb.getRefs(Constants.R_HEADS).values()) { RevCommit c = maybeParseCommit(rw, ref.getObjectId()); if (c != null) { rw.markUninteresting(c); } } Multimap<ObjectId, Ref> changeRefsBySha = ArrayListMultimap.create(); Multimap<ObjectId, PatchSet.Id> patchSetsBySha = ArrayListMultimap.create(); for (Ref ref : refdb.getRefs(RefNames.REFS_CHANGES).values()) { ObjectId id = ref.getObjectId(); if (ref.getObjectId() == null) { continue; } id = id.copy(); changeRefsBySha.put(id, ref); PatchSet.Id psId = PatchSet.Id.fromRef(ref.getName()); if (psId != null && changes.contains(psId.getParentKey())) { patchSetsBySha.put(id, psId); RevCommit c = maybeParseCommit(rw, id); if (c != null) { rw.markStart(c); } } } GroupCollector collector = new GroupCollector(changeRefsBySha, db); RevCommit c; while ((c = rw.next()) != null) { collector.visit(c); } updateGroups(db, collector, patchSetsBySha); }
From source file:com.google.gerrit.server.StarredChangesUtil.java
License:Apache License
private Set<String> getRefNames(String prefix) throws OrmException { try (Repository repo = repoManager.openRepository(allUsers)) { RefDatabase refDb = repo.getRefDatabase(); return refDb.getRefs(prefix).keySet(); } catch (IOException e) { throw new OrmException(e); }//w w w . j av a2 s.c o m }
From source file:com.google.gitiles.RefServlet.java
License:Open Source License
private static List<Map<String, Object>> getRefsSoyData(RefDatabase refdb, GitilesView view, String prefix, Ordering<Ref> ordering, @Nullable Ref headLeaf, int limit) throws IOException { Collection<Ref> refs = refdb.getRefs(prefix).values(); refs = ordering.leastOf(refs, limit > 0 ? Ints.saturatedCast(limit + 1L) : refs.size()); List<Map<String, Object>> result = Lists.newArrayListWithCapacity(refs.size()); for (Ref ref : refs) { String name = ref.getName().substring(prefix.length()); boolean needPrefix = !ref.getName().equals(refdb.getRef(name).getName()); Map<String, Object> value = Maps.newHashMapWithExpectedSize(3); value.put("url", GitilesView.revision().copyFrom(view) .setRevision(Revision.unpeeled(needPrefix ? ref.getName() : name, ref.getObjectId())).toUrl()); value.put("name", name); if (headLeaf != null) { value.put("isHead", headLeaf.equals(ref)); }//from ww w . jav a 2 s . c om result.add(value); } return result; }
From source file:com.google.gitiles.RefServlet.java
License:Open Source License
private static Map<String, Ref> getRefs(RefDatabase refdb, String path) throws IOException { path = GitilesView.maybeTrimLeadingAndTrailingSlash(path); if (path.isEmpty()) { return refdb.getRefs(RefDatabase.ALL); }/*from w w w .ja v a 2s. c om*/ path = Constants.R_REFS + path; Ref singleRef = refdb.getRef(path); if (singleRef != null) { return ImmutableMap.of(singleRef.getName(), singleRef); } return refdb.getRefs(path + '/'); }