Convert revision range processing to pipeline model

This commit is contained in:
David Nelson 2019-04-22 14:17:08 -05:00
parent b856d28904
commit 9b4b6627b6

View file

@ -3070,39 +3070,49 @@ var Tag = Ref.extend({
function RevisionRange(engine, specifiers) { function RevisionRange(engine, specifiers) {
this.engine = engine; this.engine = engine;
this.included = {}; this.tipsToInclude = [];
this.excluded = {}; this.tipsToExclude = [];
this.includedRefs = {};
this.excludedRefs = {};
this.revisions = []; this.revisions = [];
this.processSpecifiers(specifiers); this.processSpecifiers(specifiers);
} }
RevisionRange.prototype.isExclusion = function(specifier) { RevisionRange.prototype.processAsExclusion = function(specifier) {
return specifier.startsWith('^'); if(!specifier.startsWith('^')) {
return false;
}
this.tipsToExclude.push(specifier.slice(1));
return true;
};
RevisionRange.prototype.processAsInclusion = function(specifier) {
this.tipsToInclude.push(specifier);
return true;
}; };
RevisionRange.prototype.processSpecifiers = function(specifiers) { RevisionRange.prototype.processSpecifiers = function(specifiers) {
var self = this; var self = this;
var inclusions = []; var processors = [
var exclusions = []; this.processAsExclusion
];
specifiers.forEach(function(specifier) { specifiers.forEach(function(specifier) {
if(self.isExclusion(specifier)) { if(!processors.some(function(processor) { return processor.bind(self)(specifier); })) {
exclusions.push(specifier.slice(1)); self.processAsInclusion(specifier);
} else {
inclusions.push(specifier);
} }
}); });
exclusions.forEach(function(exclusion) { this.tipsToExclude.forEach(function(exclusion) {
self.addExcluded(Graph.getUpstreamSet(self.engine, exclusion)); self.addExcluded(Graph.getUpstreamSet(self.engine, exclusion));
}); });
inclusions.forEach(function(inclusion) { this.tipsToInclude.forEach(function(inclusion) {
self.addIncluded(Graph.getUpstreamSet(self.engine, inclusion)); self.addIncluded(Graph.getUpstreamSet(self.engine, inclusion));
}); });
var includedKeys = Array.from(Object.keys(self.included)); var includedKeys = Array.from(Object.keys(self.includedRefs));
self.revisions = includedKeys.map(function(revision) { self.revisions = includedKeys.map(function(revision) {
return self.engine.resolveStringRef(revision); return self.engine.resolveStringRef(revision);
@ -3112,14 +3122,14 @@ RevisionRange.prototype.processSpecifiers = function(specifiers) {
}; };
RevisionRange.prototype.isExcluded = function(revision) { RevisionRange.prototype.isExcluded = function(revision) {
return this.excluded.hasOwnProperty(revision); return this.excludedRefs.hasOwnProperty(revision);
}; };
RevisionRange.prototype.addExcluded = function(setToExclude) { RevisionRange.prototype.addExcluded = function(setToExclude) {
var self = this; var self = this;
Object.keys(setToExclude).forEach(function(toExclude) { Object.keys(setToExclude).forEach(function(toExclude) {
if(!self.isExcluded(toExclude)) { if(!self.isExcluded(toExclude)) {
self.excluded[toExclude] = true; self.excludedRefs[toExclude] = true;
} }
}); });
}; };
@ -3128,7 +3138,7 @@ RevisionRange.prototype.addIncluded = function(setToInclude) {
var self = this; var self = this;
Object.keys(setToInclude).forEach(function(toInclude) { Object.keys(setToInclude).forEach(function(toInclude) {
if(!self.isExcluded(toInclude)) { if(!self.isExcluded(toInclude)) {
self.included[toInclude] = true; self.includedRefs[toInclude] = true;
} }
}); });
}; };