List of usage examples for org.eclipse.jgit.lib Repository getRefDatabase
@NonNull public abstract RefDatabase getRefDatabase();
From source file:com.google.gerrit.server.ChangeUtil.java
License:Apache License
public static PatchSet.Id nextPatchSetId(Repository git, PatchSet.Id id) throws IOException { return nextPatchSetId(git.getRefDatabase().getRefs(RefDatabase.ALL), id); }
From source file:com.google.gerrit.server.CommentsUtil.java
License:Apache License
private Collection<Ref> getDraftRefs(Repository repo, Change.Id changeId) throws IOException { return repo.getRefDatabase().getRefs(RefNames.refsDraftCommentsPrefix(changeId)).values(); }
From source file:com.google.gerrit.server.git.BanCommit.java
License:Apache License
/** * Loads a list of commits to reject from {@code refs/meta/reject-commits}. * * @param repo repository from which the rejected commits should be loaded * @param walk open revwalk on repo.//w w w . j a v a 2s. co m * @return NoteMap of commits to be rejected, null if there are none. * @throws IOException the map cannot be loaded. */ public static NoteMap loadRejectCommitsMap(Repository repo, RevWalk walk) throws IOException { try { Ref ref = repo.getRefDatabase().exactRef(RefNames.REFS_REJECT_COMMITS); if (ref == null) { return NoteMap.newEmptyMap(); } RevCommit map = walk.parseCommit(ref.getObjectId()); return NoteMap.read(walk.getObjectReader(), map); } catch (IOException badMap) { throw new IOException("Cannot load " + RefNames.REFS_REJECT_COMMITS, badMap); } }
From source file:com.google.gerrit.server.git.ReadOnlyRepository.java
License:Apache License
ReadOnlyRepository(Repository delegate) { super(builder(delegate)); this.delegate = delegate; this.refdb = new RefDb(delegate.getRefDatabase()); this.objdb = new ObjDb(delegate.getObjectDatabase()); }
From source file:com.google.gerrit.server.git.RepoRefCache.java
License:Apache License
public RepoRefCache(Repository repo) { this.refdb = repo.getRefDatabase(); this.ids = new HashMap<>(); }
From source file:com.google.gerrit.server.git.strategy.SubmitDryRun.java
License:Apache License
public static Iterable<ObjectId> getAlreadyAccepted(Repository repo) throws IOException { return FluentIterable.from(repo.getRefDatabase().getRefs(Constants.R_HEADS).values()) .append(repo.getRefDatabase().getRefs(Constants.R_TAGS).values()) .transform(new Function<Ref, ObjectId>() { @Override/*w ww.j a v a2s . com*/ public ObjectId apply(Ref r) { return r.getObjectId(); } }); }
From source file:com.google.gerrit.server.git.TagSet.java
License:Apache License
void build(Repository git, TagSet old, TagMatcher m) { if (old != null && m != null && refresh(old, m)) { return;/*from w w w . j a v a2s .co m*/ } try (TagWalk rw = new TagWalk(git)) { rw.setRetainBody(false); for (Ref ref : git.getRefDatabase().getRefs(RefDatabase.ALL).values()) { if (skip(ref)) { continue; } else if (isTag(ref)) { // For a tag, remember where it points to. addTag(rw, git.peel(ref)); } else { // New reference to include in the set. addRef(rw, ref); } } // Traverse the complete history. Copy any flags from a commit to // all of its ancestors. This automatically updates any Tag object // as the TagCommit and the stored Tag object share the same // underlying bit set. TagCommit c; while ((c = (TagCommit) rw.next()) != null) { BitSet mine = c.refFlags; int pCnt = c.getParentCount(); for (int pIdx = 0; pIdx < pCnt; pIdx++) { ((TagCommit) c.getParent(pIdx)).refFlags.or(mine); } } } catch (IOException e) { log.warn("Error building tags for repository " + projectName, e); } }
From source file:com.google.gerrit.server.git.VersionedMetaData.java
License:Apache License
/** * Load the current version from the branch. * <p>//from ww w. ja v a2 s . c o m * The repository is not held after the call completes, allowing the * application to retain this object for long periods of time. * * @param db repository to access. * @throws IOException * @throws ConfigInvalidException */ public void load(Repository db) throws IOException, ConfigInvalidException { Ref ref = db.getRefDatabase().exactRef(getRefName()); load(db, ref != null ? ref.getObjectId() : null); }
From source file:com.google.gerrit.server.git.VisibleRefFilter.java
License:Apache License
@Override protected Map<String, Ref> getAdvertisedRefs(Repository repository, RevWalk revWalk) throws ServiceMayNotContinueException { try {//from w ww . ja v a2 s. c o m return filter(repository.getRefDatabase().getRefs(RefDatabase.ALL)); } catch (ServiceMayNotContinueException e) { throw e; } catch (IOException e) { ServiceMayNotContinueException ex = new ServiceMayNotContinueException(); ex.initCause(e); throw ex; } }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
public static NoteMap parseCommentsFromNotes(Repository repo, String refName, RevWalk walk, Change.Id changeId, Multimap<RevId, PatchLineComment> comments, Status status) throws IOException, ConfigInvalidException { Ref ref = repo.getRefDatabase().exactRef(refName); if (ref == null) { return null; }/* w w w .jav a 2s .co m*/ ObjectReader reader = walk.getObjectReader(); RevCommit commit = walk.parseCommit(ref.getObjectId()); NoteMap noteMap = NoteMap.read(reader, commit); for (Note note : noteMap) { byte[] bytes = reader.open(note.getData(), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ); List<PatchLineComment> result = parseNote(bytes, changeId, status); if (result == null || result.isEmpty()) { continue; } comments.putAll(new RevId(note.name()), result); } return noteMap; }