Example usage for org.eclipse.jgit.lib ObjectId equals

List of usage examples for org.eclipse.jgit.lib ObjectId equals

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ObjectId equals.

Prototype

@SuppressWarnings({ "NonOverridingEquals", "AmbiguousMethodReference" })
public final boolean equals(AnyObjectId other) 

Source Link

Document

Determine if this ObjectId has exactly the same value as another.

Usage

From source file:com.google.gerrit.server.notedb.NoteDbChangeState.java

License:Apache License

public static NoteDbChangeState applyDelta(Change change, Delta delta) {
    if (delta == null) {
        return null;
    }/*from w  ww.  ja v a 2s  . c  o m*/
    String oldStr = change.getNoteDbState();
    if (oldStr == null && !delta.newChangeMetaId().isPresent()) {
        // Neither an old nor a new meta ID was present, most likely because we
        // aren't writing a NoteDb graph at all for this change at this point. No
        // point in proceeding.
        return null;
    }
    NoteDbChangeState oldState = parse(change.getId(), oldStr);

    ObjectId changeMetaId;
    if (delta.newChangeMetaId().isPresent()) {
        changeMetaId = delta.newChangeMetaId().get();
        if (changeMetaId.equals(ObjectId.zeroId())) {
            change.setNoteDbState(null);
            return null;
        }
    } else {
        changeMetaId = oldState.changeMetaId;
    }

    Map<Account.Id, ObjectId> draftIds = new HashMap<>();
    if (oldState != null) {
        draftIds.putAll(oldState.draftIds);
    }
    for (Map.Entry<Account.Id, ObjectId> e : delta.newDraftIds().entrySet()) {
        if (e.getValue().equals(ObjectId.zeroId())) {
            draftIds.remove(e.getKey());
        } else {
            draftIds.put(e.getKey(), e.getValue());
        }
    }

    NoteDbChangeState state = new NoteDbChangeState(change.getId(), changeMetaId, draftIds);
    change.setNoteDbState(state.toString());
    return state;
}

From source file:com.google.gerrit.server.notedb.NoteDbUpdateManager.java

License:Apache License

private static <U extends AbstractChangeUpdate> void addUpdates(ListMultimap<String, U> all, OpenRepo or)
        throws OrmException, IOException {
    for (Map.Entry<String, Collection<U>> e : all.asMap().entrySet()) {
        String refName = e.getKey();
        Collection<U> updates = e.getValue();
        ObjectId old = firstNonNull(or.cmds.getObjectId(or.repo, refName), ObjectId.zeroId());
        // Only actually write to the ref if one of the updates explicitly allows
        // us to do so, i.e. it is known to represent a new change. This avoids
        // writing partial change meta if the change hasn't been backfilled yet.
        if (!allowWrite(updates, old)) {
            continue;
        }/*from  w  ww  . java2 s  . co m*/

        ObjectId curr = old;
        for (U u : updates) {
            ObjectId next = u.apply(or.rw, or.ins, curr);
            if (next == null) {
                continue;
            }
            curr = next;
        }
        if (!old.equals(curr)) {
            or.cmds.add(new ReceiveCommand(old, curr, refName));
        }
    }
}

From source file:com.google.gerrit.server.notedb.NoteDbUpdateManager.java

License:Apache License

private static <U extends AbstractChangeUpdate> boolean allowWrite(Collection<U> updates, ObjectId old) {
    if (!old.equals(ObjectId.zeroId())) {
        return true;
    }/*w  w  w  . j a v  a  2 s.  com*/
    return updates.iterator().next().allowWriteToNewRef();
}

From source file:com.google.gerrit.server.notedb.RobotCommentUpdate.java

License:Apache License

private RevisionNoteMap<RobotCommentsRevisionNote> getRevisionNoteMap(RevWalk rw, ObjectId curr)
        throws ConfigInvalidException, OrmException, IOException {
    if (curr.equals(ObjectId.zeroId())) {
        return RevisionNoteMap.emptyMap();
    }// w  ww .  ja  v  a  2 s  .  c  o m
    if (migration.readChanges()) {
        // If reading from changes is enabled, then the old RobotCommentNotes
        // already parsed the revision notes. We can reuse them as long as the ref
        // hasn't advanced.
        ChangeNotes changeNotes = getNotes();
        if (changeNotes != null) {
            RobotCommentNotes robotCommentNotes = changeNotes.load().getRobotCommentNotes();
            if (robotCommentNotes != null) {
                ObjectId idFromNotes = firstNonNull(robotCommentNotes.getRevision(), ObjectId.zeroId());
                RevisionNoteMap<RobotCommentsRevisionNote> rnm = robotCommentNotes.getRevisionNoteMap();
                if (idFromNotes.equals(curr) && rnm != null) {
                    return rnm;
                }
            }
        }
    }
    NoteMap noteMap;
    if (!curr.equals(ObjectId.zeroId())) {
        noteMap = NoteMap.read(rw.getObjectReader(), rw.parseCommit(curr));
    } else {
        noteMap = NoteMap.newEmptyMap();
    }
    // Even though reading from changes might not be enabled, we need to
    // parse any existing revision notes so we can merge them.
    return RevisionNoteMap.parseRobotComments(noteUtil, rw.getObjectReader(), noteMap);
}

From source file:com.google.gerrit.server.update.RepoView.java

License:Apache License

private static Optional<ObjectId> toOptional(ObjectId id) {
    return id.equals(ObjectId.zeroId()) ? Optional.empty() : Optional.of(id);
}

From source file:com.google.gitiles.ArchiveServlet.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    GitilesView view = ViewFilter.getView(req);
    Revision rev = view.getRevision();/*from   w w  w .ja v  a2  s .com*/
    Repository repo = ServletUtils.getRepository(req);

    ObjectId treeId = getTree(view, repo, rev);
    if (treeId.equals(ObjectId.zeroId())) {
        res.sendError(SC_NOT_FOUND);
        return;
    }

    Optional<ArchiveFormat> format = ArchiveFormat.byExtension(view.getExtension(), getAccess(req).getConfig());
    if (!format.isPresent()) {
        res.setStatus(SC_NOT_FOUND);
        return;
    }
    String filename = getFilename(view, rev, view.getExtension());
    setDownloadHeaders(res, filename, format.get().getMimeType());
    res.setStatus(SC_OK);

    try {
        new ArchiveCommand(repo).setFormat(format.get().getRegisteredName()).setTree(treeId)
                .setOutputStream(res.getOutputStream()).call();
    } catch (GitAPIException e) {
        throw new IOException(e);
    }
}

From source file:com.google.gitiles.DiffServlet.java

License:Open Source License

private static AbstractTreeIterator getTreeIterator(RevWalk walk, ObjectId id) throws IOException {
    if (!id.equals(ObjectId.zeroId())) {
        CanonicalTreeParser p = new CanonicalTreeParser();
        p.reset(walk.getObjectReader(), walk.parseTree(id));
        return p;
    } else {/*from   w w w .  j  a v  a  2s .c  o m*/
        return new EmptyTreeIterator();
    }
}

From source file:com.google.gitiles.VisibilityCache.java

License:Open Source License

private boolean isVisible(Repository repo, RevWalk walk, ObjectId id) throws IOException {
    RevCommit commit;/*from ww  w  . j  av a  2 s  . c  o  m*/
    try {
        commit = walk.parseCommit(id);
    } catch (IncorrectObjectTypeException e) {
        return false;
    }

    // If any reference directly points at the requested object, permit display.
    // Common for displays of pending patch sets in Gerrit Code Review, or
    // bookmarks to the commit a tag points at.
    Collection<Ref> allRefs = repo.getRefDatabase().getRefs(RefDatabase.ALL).values();
    for (Ref ref : allRefs) {
        ref = repo.getRefDatabase().peel(ref);
        if (id.equals(ref.getObjectId()) || id.equals(ref.getPeeledObjectId())) {
            return true;
        }
    }

    // Check heads first under the assumption that most requests are for refs
    // close to a head. Tags tend to be much further back in history and just
    // clutter up the priority queue in the common case.
    return isReachableFrom(walk, commit, filter(allRefs, refStartsWith(Constants.R_HEADS)))
            || isReachableFrom(walk, commit, filter(allRefs, refStartsWith(Constants.R_TAGS)))
            || isReachableFrom(walk, commit, filter(allRefs, not(refStartsWith("refs/changes/"))));
}

From source file:com.itemis.maven.plugins.unleash.scm.providers.merge.UnleashGitMerger.java

License:Eclipse Distribution License

private InputStream getInputStream(ObjectId id) throws IOException {
    if (id.equals(ObjectId.zeroId())) {
        return null;
    }/*from  w w w  .  j av  a2 s  .  c  o m*/
    return this.reader.open(id, OBJ_BLOB).openStream();
}

From source file:com.itemis.maven.plugins.unleash.scm.providers.merge.UnleashGitMerger.java

License:Eclipse Distribution License

private static RawText getRawText(ObjectId id, ObjectReader reader) throws IOException {
    if (id.equals(ObjectId.zeroId())) {
        return new RawText(new byte[] {});
    }/*from   w w w  . j  av  a  2 s  .  c  om*/
    return new RawText(reader.open(id, OBJ_BLOB).getCachedBytes());
}