mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-12 23:54:27 +02:00
Merge pull request #569 from eatdrinksleepcode/range-operator
Range operator
This commit is contained in:
commit
a719436d65
2 changed files with 51 additions and 16 deletions
|
@ -317,6 +317,18 @@ describe('Git', function() {
|
||||||
expect(commandMsg).toBe('C6\n');
|
expect(commandMsg).toBe('C6\n');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('range between branches', function() {
|
||||||
|
runCommand(SETUP + 'git rev-list left..right', function(commandMsg) {
|
||||||
|
expect(commandMsg).toBe('C5\nC4\n');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('range between commits', function() {
|
||||||
|
runCommand(SETUP + 'git rev-list C3..C5', function(commandMsg) {
|
||||||
|
expect(commandMsg).toBe('C5\nC4\n');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3070,39 +3070,62 @@ 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) {
|
var rangeRegex = /^(.*)\.\.(.*)$/;
|
||||||
return specifier.startsWith('^');
|
|
||||||
|
RevisionRange.prototype.processAsRange = function(specifier) {
|
||||||
|
var match = specifier.match(rangeRegex);
|
||||||
|
if(!match) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.tipsToExclude.push(match[1]);
|
||||||
|
this.tipsToInclude.push(match[2]);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
RevisionRange.prototype.processAsExclusion = function(specifier) {
|
||||||
|
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.processAsRange,
|
||||||
|
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 +3135,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 +3151,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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue