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