Fix MergeabilityChecker failure when making new projects
Creating refs/meta/config should not crash the MergeabilityChecker. Instead return true to recheck merges in this project, which should be empty and therefore quite fast. During creation the oldObjectId is "0"x40 and this SHA-1 does not exist in empty repositories, causing a stack trace to be thrown in the checker, polluting the logs unnecessarily. Change-Id: Ic399521d63b7c7a4312a59c0e603d1c54440974e
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user