Add 'Parent $x' options to diff for merge commits
Add 'Parent $x' options to the diff base drop down for merge commits. This way users are able to see changes brought by merge commit in addition to the merge conflicts resolution. Two main challenges of this change are: * server: enable commenting on a Parent-N of a merge commit * client: pass around the diff-base info which for merge commits can be: Auto-Merge, Parent-1, Parent-2, ... , Parent-N Currently the patch_comments.side field uses two values: 1 = REVISION 0 = PARENT For non-merge commits, side == 0 means comment of the Base (the parent) of this patch-set. For a merge commit, side == 0 means comment on the Auto-Merge of this (merge) patch-set. This change uses side == -N to store comment on the Parent-N of this (merge) patch-set. For Parent-1 the side is -1, for Parent-2 the side is -2, etc.. This avoids need for a schema migration. In NoteDb the parent number is stored in a new field: "Parent-number: 1". CommentInfo was extended with the new "parent" field which is 1-based parent number. Some REST API endpoints expose a new --parent option to enable referencing a specific parent of a merge commit. On the client side we typically pass around two PatchSet.Id's: base and revision to represent the state of the UI. The base had two meanings: * when it was non-null it was representing another patch-set * when it was null it represented the parent for a non-merge commit and the auto-merge for a merge commit. For a merge commit we need to also pass around Parent-N as (diff) base for a merge commit. To keep the number of changes minimal this change proposes (re)using the base patch-set for that where its patch-set number is negative. Therefore, when base is not null but its patch-set number is negative (-N) it represents Parent-N of the patch-set represented by the revision patch-set. This is also expressed in the client URL token which uses negative numbers for parent(s) of a merge commit. For example: -1..2 represents comparison of the second patch-set against its first parent. -2..2 would represent comparison of the patch-set 2 against its second parent. I experimented with introducing a DiffBase class which would be a combination of a base patch-set plus a parent number: class DiffBase { PatchSet.Id base; int parent; } which would avoid the ugliness of using a base with negative patch-set number. However, this produced neither a smaller nor a more elegant change. The number of changed files actually increased and, still, all places where base is used had to handle the case where base is null and parent is greater than zero. Bug: Issue 106 Change-Id: If0d7b13fad9051ec2943f6d51c99e84f7d2af708 Also-by: Dariusz Luksza <dariusz@luksza.org> Also-by: Saša Živkov <zivkov@gmail.com>
This commit is contained in:

committed by
Saša Živkov

parent
38f96373e0
commit
5904524de6
@@ -19,9 +19,13 @@ import static com.google.gerrit.acceptance.GitUtil.initSsh;
|
||||
import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.NON_VISIBLE_CHANGES;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
|
||||
import static org.eclipse.jgit.lib.Constants.HEAD;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.primitives.Chars;
|
||||
@@ -490,6 +494,29 @@ public abstract class AbstractDaemonTest {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected PushOneCommit.Result createMergeCommitChange(String ref)
|
||||
throws Exception {
|
||||
ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
|
||||
|
||||
PushOneCommit.Result p1 = pushFactory.create(db, admin.getIdent(),
|
||||
testRepo, "parent 1", ImmutableMap.of("foo", "foo-1", "bar", "bar-1"))
|
||||
.to(ref);
|
||||
|
||||
// reset HEAD in order to create a sibling of the first change
|
||||
testRepo.reset(initial);
|
||||
|
||||
PushOneCommit.Result p2 = pushFactory.create(db, admin.getIdent(),
|
||||
testRepo, "parent 2", ImmutableMap.of("foo", "foo-2", "bar", "bar-2"))
|
||||
.to(ref);
|
||||
|
||||
PushOneCommit m = pushFactory.create(db, admin.getIdent(), testRepo, "merge",
|
||||
ImmutableMap.of("foo", "foo-1", "bar", "bar-2"));
|
||||
m.setParents(ImmutableList.of(p1.getCommit(), p2.getCommit()));
|
||||
PushOneCommit.Result result = m.to(ref);
|
||||
result.assertOkStatus();
|
||||
return result;
|
||||
}
|
||||
|
||||
protected PushOneCommit.Result createDraftChange() throws Exception {
|
||||
return pushTo("refs/drafts/master");
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.acceptance.GitUtil.pushHead;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
@@ -44,6 +45,7 @@ import org.eclipse.jgit.transport.RemoteRefUpdate;
|
||||
import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PushOneCommit {
|
||||
public static final String SUBJECT = "test commit";
|
||||
@@ -87,6 +89,13 @@ public class PushOneCommit {
|
||||
@Assisted("fileName") String fileName,
|
||||
@Assisted("content") String content);
|
||||
|
||||
PushOneCommit create(
|
||||
ReviewDb db,
|
||||
PersonIdent i,
|
||||
TestRepository<?> testRepo,
|
||||
@Assisted String subject,
|
||||
@Assisted Map<String, String> files);
|
||||
|
||||
PushOneCommit create(
|
||||
ReviewDb db,
|
||||
PersonIdent i,
|
||||
@@ -123,8 +132,7 @@ public class PushOneCommit {
|
||||
private final TestRepository<?> testRepo;
|
||||
|
||||
private final String subject;
|
||||
private final String fileName;
|
||||
private final String content;
|
||||
private final Map<String, String> files;
|
||||
private String changeId;
|
||||
private Tag tag;
|
||||
private boolean force;
|
||||
@@ -168,6 +176,19 @@ public class PushOneCommit {
|
||||
db, i, testRepo, subject, fileName, content, null);
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
PushOneCommit(ChangeNotes.Factory notesFactory,
|
||||
ApprovalsUtil approvalsUtil,
|
||||
Provider<InternalChangeQuery> queryProvider,
|
||||
@Assisted ReviewDb db,
|
||||
@Assisted PersonIdent i,
|
||||
@Assisted TestRepository<?> testRepo,
|
||||
@Assisted String subject,
|
||||
@Assisted Map<String, String> files) throws Exception {
|
||||
this(notesFactory, approvalsUtil, queryProvider, db, i, testRepo,
|
||||
subject, files, null);
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
PushOneCommit(ChangeNotes.Factory notesFactory,
|
||||
ApprovalsUtil approvalsUtil,
|
||||
@@ -179,14 +200,26 @@ public class PushOneCommit {
|
||||
@Assisted("fileName") String fileName,
|
||||
@Assisted("content") String content,
|
||||
@Nullable @Assisted("changeId") String changeId) throws Exception {
|
||||
this(notesFactory, approvalsUtil, queryProvider, db, i, testRepo,
|
||||
subject, ImmutableMap.of(fileName, content), changeId);
|
||||
}
|
||||
|
||||
private PushOneCommit(ChangeNotes.Factory notesFactory,
|
||||
ApprovalsUtil approvalsUtil,
|
||||
Provider<InternalChangeQuery> queryProvider,
|
||||
ReviewDb db,
|
||||
PersonIdent i,
|
||||
TestRepository<?> testRepo,
|
||||
String subject,
|
||||
Map<String, String> files,
|
||||
String changeId) throws Exception {
|
||||
this.db = db;
|
||||
this.testRepo = testRepo;
|
||||
this.notesFactory = notesFactory;
|
||||
this.approvalsUtil = approvalsUtil;
|
||||
this.queryProvider = queryProvider;
|
||||
this.subject = subject;
|
||||
this.fileName = fileName;
|
||||
this.content = content;
|
||||
this.files = files;
|
||||
this.changeId = changeId;
|
||||
if (changeId != null) {
|
||||
commitBuilder = testRepo.amendRef("HEAD")
|
||||
@@ -207,12 +240,16 @@ public class PushOneCommit {
|
||||
}
|
||||
|
||||
public Result to(String ref) throws Exception {
|
||||
commitBuilder.add(fileName, content);
|
||||
for (Map.Entry<String, String> e : files.entrySet()) {
|
||||
commitBuilder.add(e.getKey(), e.getValue());
|
||||
}
|
||||
return execute(ref);
|
||||
}
|
||||
|
||||
public Result rm(String ref) throws Exception {
|
||||
commitBuilder.rm(fileName);
|
||||
for (String fileName : files.keySet()) {
|
||||
commitBuilder.rm(fileName);
|
||||
}
|
||||
return execute(ref);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user