private static ChangeKind getChangeKindInternal( ChangeKindCache cache, ReviewDb db, Change change, PatchSet patch, ChangeData.Factory changeDataFactory, ProjectCache projectCache, GitRepositoryManager repoManager) { Repository repo = null; // TODO - dborowitz: add NEW_CHANGE type for default. ChangeKind kind = ChangeKind.REWORK; // Trivial case: if we're on the first patch, we don't need to open // the repository. if (patch.getId().get() > 1) { try { ProjectState projectState = projectCache.checkedGet(change.getProject()); repo = repoManager.openRepository(change.getProject()); ChangeData cd = changeDataFactory.create(db, change); Collection<PatchSet> patchSetCollection = cd.patches(); PatchSet priorPs = patch; for (PatchSet ps : patchSetCollection) { if (ps.getId().get() < patch.getId().get() && (ps.getId().get() > priorPs.getId().get() || priorPs == patch)) { // We only want the previous patch set, so walk until the last one priorPs = ps; } } // If we still think the previous patch is the current patch, // we only have one patch set. Return the default. // This can happen if a user creates a draft, uploads a second patch, // and deletes the draft. if (priorPs != patch) { kind = cache.getChangeKind( projectState, repo, ObjectId.fromString(priorPs.getRevision().get()), ObjectId.fromString(patch.getRevision().get())); } } catch (IOException | OrmException e) { // Do nothing; assume we have a complex change log.warn( "Unable to get change kind for patchSet " + patch.getPatchSetId() + "of change " + change.getChangeId(), e); } finally { if (repo != null) { repo.close(); } } } return kind; }
private boolean inProject(Change change) { if (projectControl != null) { return projectControl.getProject().getNameKey().equals(change.getProject()); } else { // No --project option, so they want every project. return true; } }
protected boolean isVisibleTo(Change change, CurrentUser user) throws OrmException { if (change == null) { return false; } ProjectState pe = projectCache.get(change.getProject()); if (pe == null) { return false; } ProjectControl pc = pe.controlFor(user); ReviewDb db = dbProvider.get(); return pc.controlFor(db, change).isVisible(db); }
public void fire(Change change, PatchSet ps, Account restorer, String reason, Timestamp when) { if (!listeners.iterator().hasNext()) { return; } try { fire( util.changeInfo(change), util.revisionInfo(change.getProject(), ps), util.accountInfo(restorer), reason, when); } catch (PatchListNotAvailableException | GpgException | IOException | OrmException e) { log.error("Couldn't fire event", e); } }
private ChangeNotesParser newParser(ObjectId tip) throws Exception { Change c = newChange(); return new ChangeNotesParser( c.getProject(), c.getId(), tip, walk, repoManager, noteUtil, args.metrics); }