Fix VersionedMetaData for multiple commits in one batch
I noticed that if you make a modification to the notes tree (i.e. insert comments) and then make a modification to the commit at the meta ref (i.e. insert approvals) within one BatchMetaDataUpdate, then the notes tree update will be squashed by the second update. I added tests to show this case and corrected this by using the tree from the parent commit unless there are new contents in the DirCache to be written. Change-Id: I83f09e08f472c21dc4bc06f00c3706a18d170f9c
This commit is contained in:
@@ -240,13 +240,23 @@ public abstract class VersionedMetaData {
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectId res = newTree.writeTree(inserter);
|
||||
// Reuse tree from parent commit unless there are contents in newTree or
|
||||
// there is no tree for a parent commit.
|
||||
ObjectId res = newTree.getEntryCount() != 0 || srcTree == null
|
||||
? newTree.writeTree(inserter) : srcTree.copy();
|
||||
if (res.equals(srcTree) && !update.allowEmpty()
|
||||
&& (commit.getTreeId() == null)) {
|
||||
// If there are no changes to the content, don't create the commit.
|
||||
return;
|
||||
}
|
||||
|
||||
// If changes are made to the DirCache and those changes are written as
|
||||
// a commit and then the tree ID is set for the CommitBuilder, then
|
||||
// those previous DirCache changes will be ignored and the commit's
|
||||
// tree will be replaced with the ID in the CommitBuilder. The same is
|
||||
// true if you explicitly set tree ID in a commit and then make changes
|
||||
// to the DirCache; that tree ID will be ignored and replaced by that of
|
||||
// the tree for the updated DirCache.
|
||||
if (commit.getTreeId() == null) {
|
||||
commit.setTreeId(res);
|
||||
} else {
|
||||
|
||||
@@ -412,7 +412,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
builder.setTreeId(treeId);
|
||||
}
|
||||
}
|
||||
batch.write(builder);
|
||||
batch.write(this, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user