SubmoduleOp: Allow all branches to be subscribed
This eases the way of handling many different branches for the superproject subscription. As the superproject subscriptions are not yet in a release, we can still play around with them. When a user sees "refs = refs/heads/*:refs/heads/*" they cannot tell whether this is 1:1 matching or any match to any match without consulting the documentation. Differentiate the matching strategy by keys, such that we have "all = <refspec>" as well as "matching = <refspec>". The "all" key implies there is no interaction between the wildcards on the left and right side, e.g. all=refs/heads/*:refs/heads* indicates that any branch can be subscribed to any other branch in the given superproject. "matching" however substitutes the wildcard on the right with the captured value on the left. matching=refs/heads/*:refs/heads* allows a subscription of refs/heads/foo in the submodule to the refs/heads/foo in the superproject. Change-Id: I84d3a72c00f76570798880adf54ce56f974466ff
This commit is contained in:
@@ -29,20 +29,28 @@ import java.util.List;
|
||||
@GwtIncompatible("Unemulated org.eclipse.jgit.transport.RefSpec")
|
||||
public class SubscribeSection {
|
||||
|
||||
private final List<RefSpec> refSpecs;
|
||||
private final List<RefSpec> multiMatchRefSpecs;
|
||||
private final List<RefSpec> matchingRefSpecs;
|
||||
private final Project.NameKey project;
|
||||
|
||||
public SubscribeSection(Project.NameKey p) {
|
||||
project = p;
|
||||
refSpecs = new ArrayList<>();
|
||||
matchingRefSpecs = new ArrayList<>();
|
||||
multiMatchRefSpecs = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addRefSpec(RefSpec spec) {
|
||||
refSpecs.add(spec);
|
||||
public void addMatchingRefSpec(RefSpec spec) {
|
||||
matchingRefSpecs.add(spec);
|
||||
}
|
||||
|
||||
public void addRefSpec(String spec) {
|
||||
refSpecs.add(new RefSpec(spec));
|
||||
public void addMatchingRefSpec(String spec) {
|
||||
RefSpec r = new RefSpec(spec);
|
||||
matchingRefSpecs.add(r);
|
||||
}
|
||||
|
||||
public void addMultiMatchRefSpec(String spec) {
|
||||
RefSpec r = new RefSpec(spec, RefSpec.WildcardMode.ALLOW_MISMATCH);
|
||||
multiMatchRefSpecs.add(r);
|
||||
}
|
||||
|
||||
public Project.NameKey getProject() {
|
||||
@@ -57,7 +65,12 @@ public class SubscribeSection {
|
||||
* @return if the branch could trigger a superproject update
|
||||
*/
|
||||
public boolean appliesTo(Branch.NameKey branch) {
|
||||
for (RefSpec r : refSpecs) {
|
||||
for (RefSpec r : matchingRefSpecs) {
|
||||
if (r.matchSource(branch.get())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (RefSpec r : multiMatchRefSpecs) {
|
||||
if (r.matchSource(branch.get())) {
|
||||
return true;
|
||||
}
|
||||
@@ -65,8 +78,12 @@ public class SubscribeSection {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<RefSpec> getRefSpecs() {
|
||||
return Collections.unmodifiableCollection(refSpecs);
|
||||
public Collection<RefSpec> getMatchingRefSpecs() {
|
||||
return Collections.unmodifiableCollection(matchingRefSpecs);
|
||||
}
|
||||
|
||||
public Collection<RefSpec> getMultiMatchRefSpecs() {
|
||||
return Collections.unmodifiableCollection(multiMatchRefSpecs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,10 +91,19 @@ public class SubscribeSection {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("[SubscribeSection, project=");
|
||||
ret.append(project);
|
||||
ret.append(", refs=[");
|
||||
for (RefSpec r : refSpecs) {
|
||||
ret.append(r.toString());
|
||||
ret.append(", ");
|
||||
if (!matchingRefSpecs.isEmpty()) {
|
||||
ret.append(", matching=[");
|
||||
for (RefSpec r : matchingRefSpecs) {
|
||||
ret.append(r.toString());
|
||||
ret.append(", ");
|
||||
}
|
||||
}
|
||||
if (!multiMatchRefSpecs.isEmpty()) {
|
||||
ret.append(", all=[");
|
||||
for (RefSpec r : multiMatchRefSpecs) {
|
||||
ret.append(r.toString());
|
||||
ret.append(", ");
|
||||
}
|
||||
}
|
||||
ret.append("]");
|
||||
return ret.toString();
|
||||
|
||||
Reference in New Issue
Block a user