Implement rev-list

This commit introduces the RevisionRange, which more closely follows real git
in terms of identifying a range of revisions than the current implementation of
log. RevisionRange is being used in the new rev-list command first because it
is easy to test for ordering. A future commit will replace the existing
implementation of log with RevisionRange.
This commit is contained in:
David Nelson 2019-04-18 20:57:06 -05:00
parent 6e5d6a64e9
commit 8529a3aac7
3 changed files with 128 additions and 0 deletions

View file

@ -574,6 +574,18 @@ var commandConfig = {
}
},
revlist: {
dontCountForGolf: true,
displayName: 'rev-list',
regex: /^git +rev-list($|\s)/,
execute: function(engine, command) {
var generalArgs = command.getGeneralArgs();
command.validateArgBounds(generalArgs, 1);
engine.revlist(generalArgs);
}
},
log: {
dontCountForGolf: true,
regex: /^git +log($|\s)/,

View file

@ -2740,6 +2740,20 @@ GitEngine.prototype.logWithout = function(ref, omitBranch) {
this.log(ref, Graph.getUpstreamSet(this, omitBranch));
};
GitEngine.prototype.revlist = function(refs) {
var range = new RevisionRange(this, refs);
// now go through and collect ids
var bigLogStr = '';
range.revisions.forEach(function(c) {
bigLogStr += c.id + '\n';
});
throw new CommandResult({
msg: bigLogStr
});
};
GitEngine.prototype.log = function(ref, omitSet) {
// omit set is for doing stuff like git log branchA ^branchB
omitSet = omitSet || {};
@ -3079,6 +3093,71 @@ var Tag = Ref.extend({
}
});
function RevisionRange(engine, specifiers) {
this.engine = engine;
this.included = {};
this.excluded = {};
this.revisions = [];
this.processSpecifiers(specifiers);
}
RevisionRange.prototype.isExclusion = function(specifier) {
return specifier.startsWith('^');
};
RevisionRange.prototype.processSpecifiers = function(specifiers) {
var self = this;
var inclusions = [];
var exclusions = [];
specifiers.forEach(function(specifier) {
if(self.isExclusion(specifier)) {
exclusions.push(specifier.slice(1));
} else {
inclusions.push(specifier);
}
});
exclusions.forEach(function(exclusion) {
self.addExcluded(Graph.getUpstreamSet(self.engine, exclusion));
});
inclusions.forEach(function(inclusion) {
self.addIncluded(Graph.getUpstreamSet(self.engine, inclusion));
});
var includedKeys = Array.from(Object.keys(self.included));
self.revisions = includedKeys.map(function(revision) {
return self.engine.resolveStringRef(revision);
});
self.revisions.sort(self.engine.dateSortFunc);
self.revisions.reverse();
};
RevisionRange.prototype.isExcluded = function(revision) {
return this.excluded.hasOwnProperty(revision);
};
RevisionRange.prototype.addExcluded = function(setToExclude) {
var self = this;
Object.keys(setToExclude).forEach(function(toExclude) {
if(!self.isExcluded(toExclude)) {
self.excluded[toExclude] = true;
}
});
};
RevisionRange.prototype.addIncluded = function(setToInclude) {
var self = this;
Object.keys(setToInclude).forEach(function(toInclude) {
if(!self.isExcluded(toInclude)) {
self.included[toInclude] = true;
}
});
};
exports.GitEngine = GitEngine;
exports.Commit = Commit;
exports.Branch = Branch;