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));
}
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));
}
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));
}
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;
}
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);
}
Aggregations