Search in sources :

Example 1 with Patch

use of com.google.gerrit.reviewdb.client.Patch in project gerrit by GerritCodeReview.

the class PatchScriptFactory method loadDrafts.

private void loadDrafts(Map<Patch.Key, Patch> byKey, Account.Id me, String file) throws OrmException {
    for (Comment c : commentsUtil.draftByChangeFileAuthor(db, control.getNotes(), file, me)) {
        comments.include(change.getId(), c);
        PatchSet.Id psId = new PatchSet.Id(change.getId(), c.key.patchSetId);
        Patch.Key pKey = new Patch.Key(psId, c.key.filename);
        Patch p = byKey.get(pKey);
        if (p != null) {
            p.setDraftCount(p.getDraftCount() + 1);
        }
    }
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId) Patch(com.google.gerrit.reviewdb.client.Patch)

Example 2 with Patch

use of com.google.gerrit.reviewdb.client.Patch in project gerrit by GerritCodeReview.

the class Dispatcher method change.

private static void change(final String token) {
    String rest = skip(token);
    int c = rest.lastIndexOf(',');
    String panel = null;
    if (0 <= c) {
        panel = rest.substring(c + 1);
        rest = rest.substring(0, c);
        int at = panel.lastIndexOf('@');
        if (at > 0) {
            rest += panel.substring(at);
            panel = panel.substring(0, at);
        }
    }
    Change.Id id;
    int s = rest.indexOf('/');
    if (0 <= s) {
        id = Change.Id.parse(rest.substring(0, s));
        rest = rest.substring(s + 1);
    } else {
        id = Change.Id.parse(rest);
        rest = "";
    }
    if (rest.isEmpty()) {
        FileTable.Mode mode = FileTable.Mode.REVIEW;
        if (panel != null && (panel.equals("edit") || panel.startsWith("edit/"))) {
            mode = FileTable.Mode.EDIT;
            panel = null;
        }
        Gerrit.display(token, panel == null ? new ChangeScreen(id, DiffObject.base(), null, false, mode) : new NotFoundScreen());
        return;
    }
    String psIdStr;
    s = rest.indexOf('/');
    if (0 <= s) {
        psIdStr = rest.substring(0, s);
        rest = rest.substring(s + 1);
    } else {
        psIdStr = rest;
        rest = "";
    }
    DiffObject base = DiffObject.base();
    PatchSet.Id ps;
    int dotdot = psIdStr.indexOf("..");
    if (1 <= dotdot) {
        base = DiffObject.parse(id, psIdStr.substring(0, dotdot));
        if (base == null) {
            Gerrit.display(token, new NotFoundScreen());
        }
        psIdStr = psIdStr.substring(dotdot + 2);
    }
    ps = toPsId(id, psIdStr);
    if (!rest.isEmpty()) {
        DisplaySide side = DisplaySide.B;
        int line = 0;
        int at = rest.lastIndexOf('@');
        if (at > 0) {
            String l = rest.substring(at + 1);
            if (l.startsWith("a")) {
                side = DisplaySide.A;
                l = l.substring(1);
            }
            line = Integer.parseInt(l);
            rest = rest.substring(0, at);
        }
        Patch.Key p = new Patch.Key(ps, KeyUtil.decode(rest));
        patch(token, base, p, side, line, panel);
    } else {
        if (panel == null) {
            Gerrit.display(token, new ChangeScreen(id, base, String.valueOf(ps.get()), false, FileTable.Mode.REVIEW));
        } else {
            Gerrit.display(token, new NotFoundScreen());
        }
    }
}
Also used : ChangeScreen(com.google.gerrit.client.change.ChangeScreen) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) FileTable(com.google.gerrit.client.change.FileTable) DisplaySide(com.google.gerrit.client.diff.DisplaySide) Patch(com.google.gerrit.reviewdb.client.Patch)

Example 3 with Patch

use of com.google.gerrit.reviewdb.client.Patch in project gerrit by GerritCodeReview.

the class PatchListEntry method toPatch.

Patch toPatch(final PatchSet.Id setId) {
    final Patch p = new Patch(new Patch.Key(setId, getNewName()));
    p.setChangeType(getChangeType());
    p.setPatchType(getPatchType());
    p.setSourceFileName(getOldName());
    p.setInsertions(insertions);
    p.setDeletions(deletions);
    return p;
}
Also used : Patch(com.google.gerrit.reviewdb.client.Patch)

Example 4 with Patch

use of com.google.gerrit.reviewdb.client.Patch in project gerrit by GerritCodeReview.

the class EventFactory method asPatchSetAttribute.

/**
   * Create a PatchSetAttribute for the given patchset suitable for serialization to JSON.
   *
   * @param db Review database
   * @param patchSet
   * @return object suitable for serialization to JSON
   */
public PatchSetAttribute asPatchSetAttribute(ReviewDb db, RevWalk revWalk, Change change, PatchSet patchSet) {
    PatchSetAttribute p = new PatchSetAttribute();
    p.revision = patchSet.getRevision().get();
    p.number = patchSet.getPatchSetId();
    p.ref = patchSet.getRefName();
    p.uploader = asAccountAttribute(patchSet.getUploader());
    p.createdOn = patchSet.getCreatedOn().getTime() / 1000L;
    p.isDraft = patchSet.isDraft();
    PatchSet.Id pId = patchSet.getId();
    try {
        p.parents = new ArrayList<>();
        RevCommit c = revWalk.parseCommit(ObjectId.fromString(p.revision));
        for (RevCommit parent : c.getParents()) {
            p.parents.add(parent.name());
        }
        UserIdentity author = toUserIdentity(c.getAuthorIdent());
        if (author.getAccount() == null) {
            p.author = new AccountAttribute();
            p.author.email = author.getEmail();
            p.author.name = author.getName();
            p.author.username = "";
        } else {
            p.author = asAccountAttribute(author.getAccount());
        }
        List<Patch> list = patchListCache.get(change, patchSet).toPatchList(pId);
        for (Patch pe : list) {
            if (!Patch.isMagic(pe.getFileName())) {
                p.sizeDeletions -= pe.getDeletions();
                p.sizeInsertions += pe.getInsertions();
            }
        }
        p.kind = changeKindCache.getChangeKind(db, change, patchSet);
    } catch (IOException e) {
        log.error("Cannot load patch set data for " + patchSet.getId(), e);
    } catch (PatchListNotAvailableException e) {
        log.error(String.format("Cannot get size information for %s.", pId), e);
    }
    return p;
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute) UserIdentity(com.google.gerrit.reviewdb.client.UserIdentity) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) PatchSetAttribute(com.google.gerrit.server.data.PatchSetAttribute) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) IOException(java.io.IOException) Patch(com.google.gerrit.reviewdb.client.Patch) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with Patch

use of com.google.gerrit.reviewdb.client.Patch 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

Patch (com.google.gerrit.reviewdb.client.Patch)7 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)6 ObjectId (org.eclipse.jgit.lib.ObjectId)4 Account (com.google.gerrit.reviewdb.client.Account)2 CurrentUser (com.google.gerrit.server.CurrentUser)2 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)2 PatchListNotAvailableException (com.google.gerrit.server.patch.PatchListNotAvailableException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 AutoValue (com.google.auto.value.AutoValue)1 Joiner (com.google.common.base.Joiner)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Throwables (com.google.common.base.Throwables)1 FluentIterable (com.google.common.collect.FluentIterable)1 HashBasedTable (com.google.common.collect.HashBasedTable)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1