Don't create a new commit when creating an edit

The first step to make an edit just needs to establish the ref.
There is no need to immediately amend the commit with the caller
as committer. After creating the edit ref another operation will
happen to record a new message or a new file contents, and that
will write out a new (amended) commit object for the caller.

Change-Id: I7b51e813ece58ecdbc6e75e0e19b49a25f513247
This commit is contained in:
Shawn Pearce
2014-12-19 11:54:18 -08:00
parent 186d72782e
commit e7be120177
2 changed files with 5 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ import com.google.common.collect.Iterables;
import com.google.gerrit.acceptance.AbstractDaemonTest; import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.GitUtil.Commit; import com.google.gerrit.acceptance.GitUtil.Commit;
import com.google.gerrit.acceptance.PushOneCommit; import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.RestSession;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.change.GetRelated.ChangeAndCommit; import com.google.gerrit.server.change.GetRelated.ChangeAndCommit;
@@ -166,6 +167,8 @@ public class GetRelatedIT extends AbstractDaemonTest {
Change ch2 = getChange(c2); Change ch2 = getChange(c2);
editModifier.createEdit(ch2, getPatchSet(ch2)); editModifier.createEdit(ch2, getPatchSet(ch2));
editModifier.modifyFile(editUtil.byChange(ch2).get(), "a.txt",
RestSession.newRawInput(new byte[] {'a'}));
String editRev = editUtil.byChange(ch2).get().getRevision().get(); String editRev = editUtil.byChange(ch2).get().getRevision().get();
List<ChangeAndCommit> related = getRelated(ch2.getId(), 0); List<ChangeAndCommit> related = getRelated(ch2.getId(), 0);

View File

@@ -124,18 +124,13 @@ public class ChangeEditModifier {
} }
RevWalk rw = new RevWalk(repo); RevWalk rw = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter();
try { try {
RevCommit revision = rw.parseCommit(ObjectId.fromString( ObjectId revision = ObjectId.fromString(ps.getRevision().get());
ps.getRevision().get()));
ObjectId commit = createCommit(me, inserter, revision, revision.getTree());
inserter.flush();
String editRefName = editRefName(me.getAccountId(), change.getId(), String editRefName = editRefName(me.getAccountId(), change.getId(),
ps.getId()); ps.getId());
return update(repo, me, editRefName, rw, ObjectId.zeroId(), commit); return update(repo, me, editRefName, rw, ObjectId.zeroId(), revision);
} finally { } finally {
rw.release(); rw.release();
inserter.release();
} }
} finally { } finally {
repo.close(); repo.close();