Include a magic /MERGE_LIST file for merge commits

The /MERGE_LIST file is generated by Gerrit and is automatically
included in all changes for merge commits. It contains a list with the
commits that are integrated by accepting the merge commit. When
comparing against the auto-merge or a previous patch set it is assumed
that the first parent is uninteresting, so that the file lists all
commits which are reachable by the other parents, but not by the first
parent. If a comparison against a selected parent is done, that parent
is marked as uninteresting. This means the content of the file depends
on the selection in 'Diff Against' drop-down box.

By having the /MERGE_LIST file reviewers can immediately see which
commits get integrated by this merge commit. This is important since
for merge commits reviewers are supposed to review and approve these
commits. Having a file for this allow reviewers to comment on the list
and also see diffs between patch sets.

In edit mode the /MERGE_LIST file is not editable.

Change-Id: Iafcfe3f274ed334e9a40c13de5040a7509389e27
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-09-13 12:33:08 +02:00
parent b5b60f3aed
commit c6ea7bb81c
27 changed files with 610 additions and 205 deletions

View File

@@ -24,6 +24,8 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.patch.ComparisonType;
import com.google.gerrit.server.patch.Text;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@@ -68,6 +70,12 @@ public class GetContent implements RestReadView<FileResource> {
return BinaryResult.create(msg)
.setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
.base64();
} else if (Patch.MERGE_LIST.equals(path)) {
byte[] mergeList = getMergeList(
rsrc.getRevision().getChangeResource().getNotes());
return BinaryResult.create(mergeList)
.setContentType(FileContentUtil.TEXT_X_GERRIT_MERGE_LIST)
.base64();
}
return fileContentUtil.getContent(
rsrc.getRevision().getControl().getProjectControl().getProjectState(),
@@ -92,4 +100,22 @@ public class GetContent implements RestReadView<FileResource> {
throw new NoSuchChangeException(changeId, e);
}
}
private byte[] getMergeList(ChangeNotes notes)
throws NoSuchChangeException, OrmException, IOException {
Change.Id changeId = notes.getChangeId();
PatchSet ps = psUtil.current(db.get(), notes);
if (ps == null) {
throw new NoSuchChangeException(changeId);
}
try (Repository git = gitManager.openRepository(notes.getProjectName());
RevWalk revWalk = new RevWalk(git)) {
return Text.forMergeList(ComparisonType.againstAutoMerge(),
revWalk.getObjectReader(),
ObjectId.fromString(ps.getRevision().get())).getContent();
} catch (RepositoryNotFoundException e) {
throw new NoSuchChangeException(changeId, e);
}
}
}