Search in sources :

Example 1 with PatchListEntry

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

the class PatchListCacheIT method listPatchesAgainstOtherPatchSetWithRebase.

@Test
public void listPatchesAgainstOtherPatchSetWithRebase() 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 a = commitBuilder().add(FILE_A, "1").rm(FILE_D).message(SUBJECT_2).create();
    pushHead(testRepo, "refs/for/master", false);
    // 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_C, -FILE_D)
    testRepo.cherryPick(a);
    RevCommit b = amendBuilder().add(FILE_C, "2").create();
    pushHead(testRepo, "refs/for/master", false);
    // Compare Change 1,1 with Change 1,2 (+FILE_C)
    List<PatchListEntry> entries = getPatches(a, b);
    assertThat(entries).hasSize(2);
    assertModified(Patch.COMMIT_MSG, entries.get(0));
    assertAdded(FILE_C, entries.get(1));
    // Compare Change 1,2 with Change 1,1 (-FILE_C)
    List<PatchListEntry> entriesReverse = getPatches(b, a);
    assertThat(entriesReverse).hasSize(2);
    assertModified(Patch.COMMIT_MSG, entriesReverse.get(0));
    assertDeleted(FILE_C, entriesReverse.get(1));
}
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 2 with PatchListEntry

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

the class PatchListCacheIT method listPatchesAgainstOtherPatchSet.

@Test
public void listPatchesAgainstOtherPatchSet() throws Exception {
    commitBuilder().add(FILE_D, "4").message(SUBJECT_1).create();
    pushHead(testRepo, "refs/heads/master", false);
    // Change 1,1 (+FILE_A, +FILE_C, -FILE_D)
    RevCommit a = commitBuilder().add(FILE_A, "1").add(FILE_C, "3").rm(FILE_D).message(SUBJECT_2).create();
    pushHead(testRepo, "refs/for/master", false);
    // Change 1,2 (+FILE_A, +FILE_B, -FILE_D)
    RevCommit b = amendBuilder().add(FILE_B, "2").rm(FILE_C).create();
    pushHead(testRepo, "refs/for/master", false);
    // Compare Change 1,1 with Change 1,2 (+FILE_B, -FILE_C)
    List<PatchListEntry> entries = getPatches(a, b);
    assertThat(entries).hasSize(3);
    assertModified(Patch.COMMIT_MSG, entries.get(0));
    assertAdded(FILE_B, entries.get(1));
    assertDeleted(FILE_C, entries.get(2));
    // Compare Change 1,2 with Change 1,1 (-FILE_B, +FILE_C)
    List<PatchListEntry> entriesReverse = getPatches(b, a);
    assertThat(entriesReverse).hasSize(3);
    assertModified(Patch.COMMIT_MSG, entriesReverse.get(0));
    assertDeleted(FILE_B, entriesReverse.get(1));
    assertAdded(FILE_C, entriesReverse.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 3 with PatchListEntry

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

the class PatchListCacheIT method listPatchesAgainstBase.

@Test
public void listPatchesAgainstBase() 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).insertChangeId().create();
    String id = getChangeId(testRepo, c).get();
    pushHead(testRepo, "refs/for/master", false);
    // Compare Change 1,1 with Base (+FILE_A, -FILE_D)
    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 1,2 (+FILE_A, +FILE_B, -FILE_D)
    c = amendBuilder().add(FILE_B, "2").create();
    pushHead(testRepo, "refs/for/master", false);
    entries = getCurrentPatches(id);
    // Compare Change 1,2 with Base (+FILE_A, +FILE_B, -FILE_D)
    assertThat(entries).hasSize(4);
    assertAdded(Patch.COMMIT_MSG, entries.get(0));
    assertAdded(FILE_A, entries.get(1));
    assertAdded(FILE_B, entries.get(2));
    assertDeleted(FILE_D, entries.get(3));
}
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 4 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 5 with PatchListEntry

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

the class PRED_commit_delta_4 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.cont = cont;
    engine.setB0();
    Term a1 = arg1.dereference();
    if (a1 instanceof VariableTerm) {
        throw new PInstantiationException(this, 1);
    }
    if (!(a1 instanceof SymbolTerm)) {
        throw new IllegalTypeException(this, 1, "symbol", a1);
    }
    Pattern regex = Pattern.compile(a1.name());
    engine.r1 = new JavaObjectTerm(regex);
    engine.r2 = arg2;
    engine.r3 = arg3;
    engine.r4 = arg4;
    PatchList pl = StoredValues.PATCH_LIST.get(engine);
    Iterator<PatchListEntry> iter = pl.getPatches().iterator();
    engine.r5 = new JavaObjectTerm(iter);
    return engine.jtry5(commit_delta_check, commit_delta_next);
}
Also used : Pattern(java.util.regex.Pattern) PatchList(com.google.gerrit.server.patch.PatchList) IllegalTypeException(com.googlecode.prolog_cafe.exceptions.IllegalTypeException) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) PatchListEntry(com.google.gerrit.server.patch.PatchListEntry) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) Term(com.googlecode.prolog_cafe.lang.Term) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) PInstantiationException(com.googlecode.prolog_cafe.exceptions.PInstantiationException)

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