Revert "Some equal git branches are more equal than others"
This reverts commit 4d540a5b1cb52e84f58967bc41004f59ba389953.
Change-Id: Idc9be14dddfe6e338d37161f3ddad7ace7c2289b
Reviewed-on: https://chromium-review.googlesource.com/c/infra/gerrit-plugins/git-numberer/+/3361155
Reviewed-by: Anthony Polito <apolito@google.com>
diff --git a/src/main/java/com/googlesource/chromium/plugins/gitnumberer/CommitValidator.java b/src/main/java/com/googlesource/chromium/plugins/gitnumberer/CommitValidator.java
index a059670..93a2d63 100644
--- a/src/main/java/com/googlesource/chromium/plugins/gitnumberer/CommitValidator.java
+++ b/src/main/java/com/googlesource/chromium/plugins/gitnumberer/CommitValidator.java
@@ -183,16 +183,14 @@
return;
case 1:
RevCommit parent = commit.getParent(0);
- String usedRef;
walk.parseBody(parent);
log.debug("validating {} with 1 parent {}", commit, parent);
PositionFooters pFooters = extractAndValidateParentFooters(parent);
checkState(pFooters.position != null);
- usedRef = Generator.treatAsEqualRefs(destBranch, pFooters.position.branch, equalRefs);
- if (usedRef != null) {
+ if (Generator.treatAsEqualRefs(destBranch, pFooters.position.branch, equalRefs)) {
// The same branch for parent and this commit, and the same lineage.
validateCommitFooters(
- commit, usedRef, pFooters.position.number + 1, pFooters.branchedFrom);
+ commit, destBranch, pFooters.position.number + 1, pFooters.branchedFrom);
} else {
// New commit is on a new branch, and so should have 1 extra lineage
// comparing to parent branch.
diff --git a/src/main/java/com/googlesource/chromium/plugins/gitnumberer/Generator.java b/src/main/java/com/googlesource/chromium/plugins/gitnumberer/Generator.java
index bdcb1f9..a8fec06 100644
--- a/src/main/java/com/googlesource/chromium/plugins/gitnumberer/Generator.java
+++ b/src/main/java/com/googlesource/chromium/plugins/gitnumberer/Generator.java
@@ -23,29 +23,24 @@
pluginConfig.getStringList(ConfigFields.GENERATE_DISABLED));
}
- public static String treatAsEqualRefs(String ref1, String ref2, PluginConfig pluginConfig) {
+ public static boolean treatAsEqualRefs(String ref1, String ref2, PluginConfig pluginConfig) {
return treatAsEqualRefs(ref1, ref2, pluginConfig.getStringList(ConfigFields.EQUAL_BRANCHES));
}
- // Returns the string value to use as the "equal" ref, or null if they are not equal
- public static String treatAsEqualRefs(String ref1, String ref2, String[] equalRefLists) {
+ public static boolean treatAsEqualRefs(String ref1, String ref2, String[] equalRefLists) {
if (ref1.equals(ref2)) {
- return ref1;
+ return true;
}
- for (String refs : equalRefLists) {
- String usedRef = null;
+ for (String refs : equalRefLists) {
Set<String> refSet = new HashSet<>();
for (String ref : refs.split(",")) {
- if (usedRef == null) {
- usedRef = ref;
- }
refSet.add(ref.trim());
}
if (refSet.contains(ref1) && refSet.contains(ref2)) {
- return usedRef;
+ return true;
}
}
- return null;
+ return false;
}
/**
@@ -74,9 +69,9 @@
StringBuilder newMessage = MessageTweaker.copyAndModifyingFooters(childCommitMessage);
// Post-condition: we are appending lines to last paragraph
// and all prior footers like Change-Id are already in this paragraph.
- String usedRef = treatAsEqualRefs(destRef, pfParent.position.branch, equalRefs);
- if (usedRef != null) {
- PositionFooters.appendCommitPosition(newMessage, usedRef, pfParent.position.number + 1);
+
+ if (treatAsEqualRefs(destRef, pfParent.position.branch, equalRefs)) {
+ PositionFooters.appendCommitPosition(newMessage, destRef, pfParent.position.number + 1);
} else {
PositionFooters.appendCommitPosition(newMessage, destRef, 1);
PositionFooters.appendBranchedFrom(newMessage, expectedParent.getName(), pfParent.position);
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index affe661..a23421c 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -45,8 +45,7 @@
plugin.@PLUGIN@.equal-branches-list
: refs sets (as csv) that are to be treated as equal for the purposes of numbering.
- The first ref set in each list will be used by plugin.
- equal-branches-list(s) are *not* inherited by child projects.
+ equa-branches-list(s) are *not* inherited by child projects.
Plugin @PLUGIN@ validates commits on some ref **if and only if all conditions
below are met**:
diff --git a/src/test/java/com/googlesource/chromium/plugins/gitnumberer/GeneratorTest.java b/src/test/java/com/googlesource/chromium/plugins/gitnumberer/GeneratorTest.java
index 7b49bf6..b9170de 100644
--- a/src/test/java/com/googlesource/chromium/plugins/gitnumberer/GeneratorTest.java
+++ b/src/test/java/com/googlesource/chromium/plugins/gitnumberer/GeneratorTest.java
@@ -44,12 +44,7 @@
.Parent("Parent", "", "Cr-Commit-Position: refs/heads/main@{#3}")
.Child("Child")
.DestinationBranch("refs/heads/master")
- .assertGenerated(equalRefs, "Child", "", "Cr-Commit-Position: refs/heads/main@{#4}");
- new TestBuilder()
- .Parent("Parent", "", "Cr-Commit-Position: refs/heads/main@{#3}")
- .Child("Child")
- .DestinationBranch("refs/heads/main")
- .assertGenerated(equalRefs, "Child", "", "Cr-Commit-Position: refs/heads/main@{#4}");
+ .assertGenerated(equalRefs, "Child", "", "Cr-Commit-Position: refs/heads/master@{#4}");
}
@Test