Fix schema 115: Create a new MetaDataUpdate instance for each update

When using MetaDataUpdate with a BatchRefUpdate it is important to
create a new MetaDataUpdate instance for each update. Reusing the
MetaDataUpdate instance to update several branches leads to cross
contamination between the branches. The first branch is updated
correctly, but then the tree that was created for the first branch is
reused in VersionedMetaData to update all following branches. The
resulting commits for the following branches are merge commits with
one additional parent per update. This is due to the reusage of the
CommitBuilder from MetaDataUpdate for each update. On each update
VersionedMetaData is adding the source commit as another parent to the
commit builder. The source commit is the commit that was created by
the previous branch update. When many branches are updated this way it
leads to crazy octopus merges in the branches where only a single
non-merge commit is expected.

Change-Id: I09bbe1ae3a3e8bec6155bb8ccfd1819a314d8c5c
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2015-12-17 13:37:51 +01:00
parent 84142539dc
commit b55e248869

View File

@@ -131,18 +131,23 @@ public class Schema_115 extends SchemaVersion {
try (Repository git = mgr.openRepository(allUsersName);
RevWalk rw = new RevWalk(git)) {
BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
for (Map.Entry<Account.Id, DiffPreferencesInfo> e : imports.entrySet()) {
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED,
allUsersName, git, bru);
try {
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
for (Map.Entry<Account.Id, DiffPreferencesInfo> e : imports.entrySet()) {
VersionedAccountPreferences p =
VersionedAccountPreferences.forUser(e.getKey());
p.load(md);
storeSection(p.getConfig(), UserConfigSections.DIFF, null,
e.getValue(), DiffPreferencesInfo.defaults());
p.commit(md);
} finally {
md.close();
}
}
bru.execute(rw, NullProgressMonitor.INSTANCE);