Search in sources :

Example 1 with CommentDetail

use of com.google.gerrit.common.data.CommentDetail in project gerrit by GerritCodeReview.

the class PatchScriptFactory method loadCommentsAndHistory.

private void loadCommentsAndHistory(ChangeNotes notes, ChangeType changeType, String oldName, String newName) throws OrmException {
    Map<Patch.Key, Patch> byKey = new HashMap<>();
    if (loadHistory) {
        // This seems like a cheap trick. It doesn't properly account for a
        // file that gets renamed between patch set 1 and patch set 2. We
        // will wind up packing the wrong Patch object because we didn't do
        // proper rename detection between the patch sets.
        //
        history = new ArrayList<>();
        for (PatchSet ps : psUtil.byChange(db, notes)) {
            if (!control.isPatchVisible(ps, db)) {
                continue;
            }
            String name = fileName;
            if (psa != null) {
                switch(changeType) {
                    case COPIED:
                    case RENAMED:
                        if (ps.getId().equals(psa)) {
                            name = oldName;
                        }
                        break;
                    case MODIFIED:
                    case DELETED:
                    case ADDED:
                    case REWRITE:
                        break;
                }
            }
            Patch p = new Patch(new Patch.Key(ps.getId(), name));
            history.add(p);
            byKey.put(p.getKey(), p);
        }
        if (edit != null && edit.isPresent()) {
            Patch p = new Patch(new Patch.Key(new PatchSet.Id(psb.getParentKey(), 0), fileName));
            history.add(p);
            byKey.put(p.getKey(), p);
        }
    }
    if (loadComments && edit == null) {
        comments = new CommentDetail(psa, psb);
        switch(changeType) {
            case ADDED:
            case MODIFIED:
                loadPublished(byKey, newName);
                break;
            case DELETED:
                loadPublished(byKey, newName);
                break;
            case COPIED:
            case RENAMED:
                if (psa != null) {
                    loadPublished(byKey, oldName);
                }
                loadPublished(byKey, newName);
                break;
            case REWRITE:
                break;
        }
        CurrentUser user = control.getUser();
        if (user.isIdentifiedUser()) {
            Account.Id me = user.getAccountId();
            switch(changeType) {
                case ADDED:
                case MODIFIED:
                    loadDrafts(byKey, me, newName);
                    break;
                case DELETED:
                    loadDrafts(byKey, me, newName);
                    break;
                case COPIED:
                case RENAMED:
                    if (psa != null) {
                        loadDrafts(byKey, me, oldName);
                    }
                    loadDrafts(byKey, me, newName);
                    break;
                case REWRITE:
                    break;
            }
        }
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) CurrentUser(com.google.gerrit.server.CurrentUser) HashMap(java.util.HashMap) CommentDetail(com.google.gerrit.common.data.CommentDetail) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId) Patch(com.google.gerrit.reviewdb.client.Patch)

Aggregations

CommentDetail (com.google.gerrit.common.data.CommentDetail)1 Account (com.google.gerrit.reviewdb.client.Account)1 Patch (com.google.gerrit.reviewdb.client.Patch)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 HashMap (java.util.HashMap)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1