Search in sources :

Example 6 with PatchListEntry

use of com.google.gerrit.server.patch.PatchListEntry in project gerrit by GerritCodeReview.

the class FileInfoJson method toFileInfoMap.

private Map<String, FileInfo> toFileInfoMap(Change change, PatchListKey key) throws PatchListNotAvailableException {
    PatchList list = patchListCache.get(key, change.getProject());
    Map<String, FileInfo> files = new TreeMap<>();
    for (PatchListEntry e : list.getPatches()) {
        FileInfo d = new FileInfo();
        d.status = e.getChangeType() != Patch.ChangeType.MODIFIED ? e.getChangeType().getCode() : null;
        d.oldPath = e.getOldName();
        d.sizeDelta = e.getSizeDelta();
        d.size = e.getSize();
        if (e.getPatchType() == Patch.PatchType.BINARY) {
            d.binary = true;
        } else {
            d.linesInserted = e.getInsertions() > 0 ? e.getInsertions() : null;
            d.linesDeleted = e.getDeletions() > 0 ? e.getDeletions() : null;
        }
        FileInfo o = files.put(e.getNewName(), d);
        if (o != null) {
            // This should only happen on a delete-add break created by JGit
            // when the file was rewritten and too little content survived. Write
            // a single record with data from both sides.
            d.status = Patch.ChangeType.REWRITE.getCode();
            d.sizeDelta = o.sizeDelta;
            d.size = o.size;
            if (o.binary != null && o.binary) {
                d.binary = true;
            }
            if (o.linesInserted != null) {
                d.linesInserted = o.linesInserted;
            }
            if (o.linesDeleted != null) {
                d.linesDeleted = o.linesDeleted;
            }
        }
    }
    return files;
}
Also used : PatchList(com.google.gerrit.server.patch.PatchList) FileInfo(com.google.gerrit.extensions.common.FileInfo) PatchListEntry(com.google.gerrit.server.patch.PatchListEntry) TreeMap(java.util.TreeMap)

Example 7 with PatchListEntry

use of com.google.gerrit.server.patch.PatchListEntry in project gerrit by GerritCodeReview.

the class PatchListCacheIT method listPatchesAgainstBaseWithRebase.

@Test
public void listPatchesAgainstBaseWithRebase() throws Exception {
    commitBuilder().add(FILE_D, "4").message(SUBJECT_1).create();
    pushHead(testRepo, "refs/heads/master", false);
    // Change 1,1 (+FILE_A, -FILE_D)
    RevCommit c = commitBuilder().add(FILE_A, "1").rm(FILE_D).message(SUBJECT_2).create();
    String id = getChangeId(testRepo, c).get();
    pushHead(testRepo, "refs/for/master", false);
    List<PatchListEntry> entries = getCurrentPatches(id);
    assertThat(entries).hasSize(3);
    assertAdded(Patch.COMMIT_MSG, entries.get(0));
    assertAdded(FILE_A, entries.get(1));
    assertDeleted(FILE_D, entries.get(2));
    // Change 2,1 (+FILE_B)
    testRepo.reset("HEAD~1");
    commitBuilder().add(FILE_B, "2").message(SUBJECT_3).create();
    pushHead(testRepo, "refs/for/master", false);
    // Change 1,2 (+FILE_A, -FILE_D))
    testRepo.cherryPick(c);
    pushHead(testRepo, "refs/for/master", false);
    // Compare Change 1,2 with Base (+FILE_A, -FILE_D))
    entries = getCurrentPatches(id);
    assertThat(entries).hasSize(3);
    assertAdded(Patch.COMMIT_MSG, entries.get(0));
    assertAdded(FILE_A, entries.get(1));
    assertDeleted(FILE_D, entries.get(2));
}
Also used : PatchListEntry(com.google.gerrit.server.patch.PatchListEntry) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 8 with PatchListEntry

use of com.google.gerrit.server.patch.PatchListEntry in project gerrit by GerritCodeReview.

the class EventFactory method addPatchSetFileNames.

public void addPatchSetFileNames(PatchSetAttribute patchSetAttribute, Change change, PatchSet patchSet) {
    try {
        PatchList patchList = patchListCache.get(change, patchSet);
        for (PatchListEntry patch : patchList.getPatches()) {
            if (patchSetAttribute.files == null) {
                patchSetAttribute.files = new ArrayList<>();
            }
            PatchAttribute p = new PatchAttribute();
            p.file = patch.getNewName();
            p.fileOld = patch.getOldName();
            p.type = patch.getChangeType();
            p.deletions -= patch.getDeletions();
            p.insertions = patch.getInsertions();
            patchSetAttribute.files.add(p);
        }
    } catch (PatchListNotAvailableException e) {
        log.warn("Cannot get patch list", e);
    }
}
Also used : PatchAttribute(com.google.gerrit.server.data.PatchAttribute) PatchList(com.google.gerrit.server.patch.PatchList) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) PatchListEntry(com.google.gerrit.server.patch.PatchListEntry)

Example 9 with PatchListEntry

use of com.google.gerrit.server.patch.PatchListEntry in project gerrit by GerritCodeReview.

the class ChangeEmail method getChangeDetail.

/** Create the change message and the affected file list. */
public String getChangeDetail() {
    try {
        StringBuilder detail = new StringBuilder();
        if (patchSetInfo != null) {
            detail.append(patchSetInfo.getMessage().trim()).append("\n");
        } else {
            detail.append(change.getSubject().trim()).append("\n");
        }
        if (patchSet != null) {
            detail.append("---\n");
            PatchList patchList = getPatchList();
            for (PatchListEntry p : patchList.getPatches()) {
                if (Patch.isMagic(p.getNewName())) {
                    continue;
                }
                detail.append(p.getChangeType().getCode()).append(" ").append(p.getNewName()).append("\n");
            }
            detail.append(MessageFormat.format(//
            "" + //
            "{0,choice,0#0 files|1#1 file|1<{0} files} changed, " + //
            "{1,choice,0#0 insertions|1#1 insertion|1<{1} insertions}(+), " + //
            "{2,choice,0#0 deletions|1#1 deletion|1<{2} deletions}(-)" + "\n", //
            patchList.getPatches().size() - 1, //
            patchList.getInsertions(), patchList.getDeletions()));
            detail.append("\n");
        }
        return detail.toString();
    } catch (Exception err) {
        log.warn("Cannot format change detail", err);
        return "";
    }
}
Also used : PatchList(com.google.gerrit.server.patch.PatchList) PatchListEntry(com.google.gerrit.server.patch.PatchListEntry) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) OrmException(com.google.gwtorm.server.OrmException) PatchSetInfoNotAvailableException(com.google.gerrit.server.patch.PatchSetInfoNotAvailableException) EmailException(com.google.gerrit.common.errors.EmailException) IOException(java.io.IOException)

Aggregations

PatchListEntry (com.google.gerrit.server.patch.PatchListEntry)9 PatchList (com.google.gerrit.server.patch.PatchList)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 Test (org.junit.Test)4 PatchListNotAvailableException (com.google.gerrit.server.patch.PatchListNotAvailableException)2 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)2 Term (com.googlecode.prolog_cafe.lang.Term)2 VariableTerm (com.googlecode.prolog_cafe.lang.VariableTerm)2 IOException (java.io.IOException)2 Pattern (java.util.regex.Pattern)2 EmailException (com.google.gerrit.common.errors.EmailException)1 FileInfo (com.google.gerrit.extensions.common.FileInfo)1 PatchAttribute (com.google.gerrit.server.data.PatchAttribute)1 PatchSetInfoNotAvailableException (com.google.gerrit.server.patch.PatchSetInfoNotAvailableException)1 Text (com.google.gerrit.server.patch.Text)1 OrmException (com.google.gwtorm.server.OrmException)1 IllegalTypeException (com.googlecode.prolog_cafe.exceptions.IllegalTypeException)1 JavaException (com.googlecode.prolog_cafe.exceptions.JavaException)1 PInstantiationException (com.googlecode.prolog_cafe.exceptions.PInstantiationException)1