Search in sources :

Example 1 with RefDatabase

use of org.eclipse.jgit.lib.RefDatabase in project gitiles by GerritCodeReview.

the class RefServlet method getBranchesSoyData.

static List<Map<String, Object>> getBranchesSoyData(HttpServletRequest req, int limit) throws IOException {
    RefDatabase refdb = ServletUtils.getRepository(req).getRefDatabase();
    Ref head = refdb.exactRef(Constants.HEAD);
    Ref headLeaf = head != null && head.isSymbolic() ? head.getLeaf() : null;
    return getRefsSoyData(refdb, ViewFilter.getView(req), Constants.R_HEADS, branchComparator(headLeaf), headLeaf, limit);
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefDatabase(org.eclipse.jgit.lib.RefDatabase)

Example 2 with RefDatabase

use of org.eclipse.jgit.lib.RefDatabase in project gerrit by GerritCodeReview.

the class RebuildNoteDb method deleteRefs.

private void deleteRefs(String prefix, Repository allUsersRepo) throws IOException {
    RefDatabase refDb = allUsersRepo.getRefDatabase();
    Map<String, Ref> allRefs = refDb.getRefs(prefix);
    BatchRefUpdate bru = refDb.newBatchUpdate();
    for (Map.Entry<String, Ref> ref : allRefs.entrySet()) {
        bru.addCommand(new ReceiveCommand(ref.getValue().getObjectId(), ObjectId.zeroId(), prefix + ref.getKey()));
    }
    execute(bru, allUsersRepo);
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) Ref(org.eclipse.jgit.lib.Ref) RefDatabase(org.eclipse.jgit.lib.RefDatabase) Map(java.util.Map) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate)

Example 3 with RefDatabase

use of org.eclipse.jgit.lib.RefDatabase in project gerrit by GerritCodeReview.

the class Schema_108 method updateProjectGroups.

private void updateProjectGroups(ReviewDb db, Repository repo, RevWalk rw, Set<Change.Id> changes, UpdateUI ui) throws OrmException, IOException {
    // Match sorting in ReceiveCommits.
    rw.reset();
    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(), ui);
        if (c != null) {
            rw.markUninteresting(c);
        }
    }
    ListMultimap<ObjectId, Ref> changeRefsBySha = MultimapBuilder.hashKeys().arrayListValues().build();
    ListMultimap<ObjectId, PatchSet.Id> patchSetsBySha = MultimapBuilder.hashKeys().arrayListValues().build();
    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, ui);
            if (c != null) {
                rw.markStart(c);
            }
        }
    }
    GroupCollector collector = GroupCollector.createForSchemaUpgradeOnly(changeRefsBySha, db);
    RevCommit c;
    while ((c = rw.next()) != null) {
        collector.visit(c);
    }
    updateGroups(db, collector, patchSetsBySha);
}
Also used : GroupCollector(com.google.gerrit.server.git.GroupCollector) Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId) RefDatabase(org.eclipse.jgit.lib.RefDatabase) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with RefDatabase

use of org.eclipse.jgit.lib.RefDatabase in project gerrit by GerritCodeReview.

the class RefUtil method verifyConnected.

public static RevWalk verifyConnected(Repository repo, ObjectId revid) throws InvalidRevisionException {
    try {
        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();
    }
}
Also used : ObjectWalk(org.eclipse.jgit.revwalk.ObjectWalk) Ref(org.eclipse.jgit.lib.Ref) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) RefDatabase(org.eclipse.jgit.lib.RefDatabase) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException)

Example 5 with RefDatabase

use of org.eclipse.jgit.lib.RefDatabase in project gerrit by GerritCodeReview.

the class IncludedInResolver method resolve.

private Result 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);
    allTagsAndBranches.addAll(branches);
    parseCommits(allTagsAndBranches);
    Set<String> allMatchingTagsAndBranches = includedIn(tipsByCommitTime, 0);
    Result detail = new Result();
    detail.setBranches(getMatchingRefNames(allMatchingTagsAndBranches, branches));
    detail.setTags(getMatchingRefNames(allMatchingTagsAndBranches, tags));
    return detail;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefDatabase(org.eclipse.jgit.lib.RefDatabase)

Aggregations

Ref (org.eclipse.jgit.lib.Ref)5 RefDatabase (org.eclipse.jgit.lib.RefDatabase)5 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 GroupCollector (com.google.gerrit.server.git.GroupCollector)1 IOException (java.io.IOException)1 Map (java.util.Map)1 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)1 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)1 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 ObjectWalk (org.eclipse.jgit.revwalk.ObjectWalk)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)1