Merge "Fix MergeabilityChecker failure when making new projects"

This commit is contained in:
Shawn Pearce
2013-12-09 17:16:38 +00:00
committed by Gerrit Code Review

View File

@@ -47,6 +47,7 @@ import com.google.inject.Provider;
import com.google.inject.ProvisionException;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.slf4j.Logger;
@@ -116,16 +117,9 @@ public class MergeabilityChecker implements GitReferenceUpdatedListener {
if (ref.equals(GitRepositoryManager.REF_CONFIG)) {
Project.NameKey p = new Project.NameKey(event.getProjectName());
try {
ProjectConfig oldCfg =
ProjectConfig.read(metaDataUpdateFactory.create(p),
ObjectId.fromString(event.getOldObjectId()));
ProjectConfig newCfg =
ProjectConfig.read(metaDataUpdateFactory.create(p),
ObjectId.fromString(event.getNewObjectId()));
if (!oldCfg.getProject().getSubmitType().equals(newCfg.getProject().getSubmitType())
|| oldCfg.getProject().getUseContentMerge() != newCfg.getProject().getUseContentMerge()
|| (oldCfg.getRulesId() == null ? newCfg.getRulesId() != null
: !oldCfg.getRulesId().equals(newCfg.getRulesId()))) {
ProjectConfig oldCfg = parseConfig(p, event.getOldObjectId());
ProjectConfig newCfg = parseConfig(p, event.getNewObjectId());
if (recheckMerges(oldCfg, newCfg)) {
try {
new ProjectUpdateTask(schemaFactory, p).call();
} catch (Exception e) {
@@ -145,6 +139,26 @@ public class MergeabilityChecker implements GitReferenceUpdatedListener {
}
}
private boolean recheckMerges(ProjectConfig oldCfg, ProjectConfig newCfg) {
if (oldCfg == null || newCfg == null) {
return true;
}
return !oldCfg.getProject().getSubmitType().equals(newCfg.getProject().getSubmitType())
|| oldCfg.getProject().getUseContentMerge() != newCfg.getProject().getUseContentMerge()
|| (oldCfg.getRulesId() == null
? newCfg.getRulesId() != null
: !oldCfg.getRulesId().equals(newCfg.getRulesId()));
}
private ProjectConfig parseConfig(Project.NameKey p, String idStr)
throws IOException, ConfigInvalidException, RepositoryNotFoundException {
ObjectId id = ObjectId.fromString(idStr);
if (ObjectId.zeroId().equals(id)) {
return null;
}
return ProjectConfig.read(metaDataUpdateFactory.create(p), id);
}
/**
* Updates the mergeability flag of the change asynchronously. If the
* mergeability flag is updated the change is reindexed.