diff --git a/Gruntfile.js b/Gruntfile.js index 4d007c18..ab271d4a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -62,7 +62,7 @@ module.exports = function(grunt) { hashedMinFile = 'bundle.js'; } var jsRegex = /bundle\.min\.\w+\.js/; - _.each(buildFiles, function(jsFile) { + buildFiles.forEach(function(jsFile) { if (jsRegex.test(jsFile)) { if (hashedMinFile) { throw new Error('more than one hashed file: ' + jsFile + hashedMinFile); @@ -76,7 +76,7 @@ module.exports = function(grunt) { var styleRegex = /main\.\w+\.css/; var hashedStyleFile; - _.each(buildFiles, function(styleFile) { + buildFiles.forEach(function(styleFile) { if (styleRegex.test(styleFile)) { if (hashedStyleFile) { throw new Error('more than one hashed style: ' + styleFile + hashedStyleFile); @@ -253,4 +253,3 @@ module.exports = function(grunt) { grunt.registerTask('test', ['jasmine_node']); grunt.registerTask('casperTest', ['shell:casperTest']); }; - diff --git a/src/js/commands/index.js b/src/js/commands/index.js index 2f896e1c..64706d34 100644 --- a/src/js/commands/index.js +++ b/src/js/commands/index.js @@ -34,7 +34,7 @@ var commands = { if (result.multiDelegate) { // we need to do multiple delegations with // a different command at each step - _.each(result.multiDelegate, function(delConfig) { + result.multiDelegate.forEach(function(delConfig) { // copy command, and then set opts commandObj.setOptionsMap(delConfig.options || {}); commandObj.setGeneralArgs(delConfig.args || []); @@ -70,7 +70,7 @@ var commands = { var displayName = config.displayName || name; var thisMap = {}; // start all options off as disabled - _.each(config.options, function(option) { + (config.options || []).forEach(function(option) { thisMap[option] = false; }); optionMap[vcs][displayName] = thisMap; diff --git a/src/js/git/commands.js b/src/js/git/commands.js index cdec783b..949f47ae 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -431,7 +431,7 @@ var commandConfig = { names = names.concat(generalArgs); command.validateArgBounds(names, 1, Number.MAX_VALUE, '-d'); - _.each(names, function(name) { + names.forEach(function(name) { engine.validateAndDeleteBranch(name); }); return; @@ -856,4 +856,3 @@ var instantCommands = [ exports.commandConfig = commandConfig; exports.instantCommands = instantCommands; - diff --git a/src/js/git/index.js b/src/js/git/index.js index 2e163168..e38fe572 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -170,7 +170,7 @@ GitEngine.prototype.exportTreeForBranch = function(branchName) { // now loop through and delete commits var commitsToLoop = tree.commits; tree.commits = {}; - _.each(commitsToLoop, function(commit, id) { + commitsToLoop.forEach(function(commit, id) { if (set[id]) { // if included in target branch tree.commits[id] = commit; @@ -179,7 +179,7 @@ GitEngine.prototype.exportTreeForBranch = function(branchName) { var branchesToLoop = tree.branches; tree.branches = {}; - _.each(branchesToLoop, function(branch, id) { + branchesToLoop.forEach(function(branch, id) { if (id === branchName) { tree.branches[id] = branch; } @@ -200,30 +200,28 @@ GitEngine.prototype.exportTree = function() { HEAD: null }; - _.each(this.branchCollection.toJSON(), function(branch) { + this.branchCollection.toJSON().forEach(function(branch) { branch.target = branch.target.get('id'); delete branch.visBranch; totalExport.branches[branch.id] = branch; }); - _.each(this.commitCollection.toJSON(), function(commit) { + this.commitCollection.toJSON().forEach(function(commit) { // clear out the fields that reference objects and create circular structure - _.each(Commit.prototype.constants.circularFields, function(field) { + Commit.prototype.constants.circularFields.forEach(function(field) { delete commit[field]; - }, this); + }); // convert parents - var parents = []; - _.each(commit.parents, function(par) { - parents.push(par.get('id')); + commit.parents = (commit.parents || []).map(function(par) { + return par.get('id'); }); - commit.parents = parents; totalExport.commits[commit.id] = commit; }, this); - _.each(this.tagCollection.toJSON(), function(tag) { + this.tagCollection.toJSON().forEach(function(tag) { delete tag.visTag; tag.target = tag.target.get('id'); @@ -558,9 +556,8 @@ GitEngine.prototype.getOrMakeRecursive = function( // for commits, we need to grab all the parents var commitJSON = tree.commits[objID]; - var parentObjs = []; - _.each(commitJSON.parents, function(parentID) { - parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID)); + var parentObjs = commitJSON.parents.map(function(parentID) { + return this.getOrMakeRecursive(tree, createdSoFar, parentID); }, this); var commit = new Commit(Object.assign( @@ -774,17 +771,16 @@ GitEngine.prototype.printBranchesWithout = function(without) { var commitToBranches = this.getUpstreamBranchSet(); var commitID = this.getCommitFromRef(without).get('id'); - var toPrint = []; - _.each(commitToBranches[commitID], function(branchJSON) { + var toPrint = commitToBranches[commitID].map(function (branchJSON) { branchJSON.selected = this.HEAD.get('target').get('id') == branchJSON.id; - toPrint.push(branchJSON); + return branchJSON; }, this); this.printBranches(toPrint); }; GitEngine.prototype.printBranches = function(branches) { var result = ''; - _.each(branches, function(branch) { + branches.forEach(function (branch) { result += (branch.selected ? '* ' : '') + branch.id + '\n'; }); throw new CommandResult({ @@ -794,7 +790,7 @@ GitEngine.prototype.printBranches = function(branches) { GitEngine.prototype.printTags = function(tags) { var result = ''; - _.each(tags, function(tag) { + tags.forEach(function (tag) { result += tag.id + '\n'; }); throw new CommandResult({ @@ -895,11 +891,11 @@ GitEngine.prototype.revert = function(whichCommits) { }.bind(this); // set up the promise chain - _.each(toRevert, function(commit) { + toRevert.forEach(function (commit) { chain = chain.then(function() { return chainStep(commit); }); - }, this); + }); // done! update our location chain = chain.then(function() { @@ -934,7 +930,7 @@ GitEngine.prototype.setupCherrypickChain = function(toCherrypick) { ); }.bind(this); - _.each(toCherrypick, function(arg) { + toCherrypick.forEach(function (arg) { chain = chain.then(function() { return chainStep(arg); }); @@ -1015,7 +1011,7 @@ GitEngine.prototype.getTargetGraphDifference = function( while (toExplore.length) { var here = toExplore.pop(); difference.push(here); - _.each(here.parents, pushParent); + here.parents.forEach(pushParent); } // filter because we weren't doing graph search @@ -1160,7 +1156,7 @@ GitEngine.prototype.push = function(options) { var deferred = Q.defer(); var chain = deferred.promise; - _.each(commitsToMake, function(commitJSON) { + commitsToMake.forEach(function(commitJSON) { chain = chain.then(function() { return this.animationFactory.playHighlightPromiseAnimation( this.refs[commitJSON.id], @@ -1267,7 +1263,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { // first check if our local remote branch is upstream of the origin branch set. // this check essentially pretends the local remote branch is in origin and // could be fast forwarded (basic sanity check) - _.each(sourceDestPairs, function(pair) { + sourceDestPairs.forEach(function (pair) { this.checkUpstreamOfSource( this, this.origin, @@ -1278,7 +1274,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { // then we get the difference in commits between these two graphs var commitsToMake = []; - _.each(sourceDestPairs, function(pair) { + sourceDestPairs.forEach(function (pair) { commitsToMake = commitsToMake.concat(this.getTargetGraphDifference( this, this.origin, @@ -1341,7 +1337,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { } var originBranchSet = this.origin.getUpstreamBranchSet(); - _.each(commitsToMake, function(commitJSON) { + commitsToMake.forEach(function (commitJSON) { // technically we could grab the wrong one here // but this works for now var originBranch = originBranchSet[commitJSON.id][0].obj; @@ -1364,7 +1360,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { chain = chain.then(function() { // update all the destinations - _.each(sourceDestPairs, function(pair) { + sourceDestPairs.forEach(function (pair) { var ours = this.refs[pair.destination]; var theirCommitID = this.origin.getCommitFromRef(pair.source).get('id'); // by definition we just made the commit with this id, @@ -1736,8 +1732,8 @@ GitEngine.prototype.updateBranchesFromSet = function(commitSet) { var branchesToUpdate = {}; // now loop over the set we got passed in and find which branches // that means (aka intersection) - _.each(commitSet, function(val, id) { - _.each(upstreamSet[id], function(branchJSON) { + commitSet.forEach(function (val, id) { + upstreamSet[id].forEach(function (branchJSON) { branchesToUpdate[branchJSON.id] = true; }); }, this); @@ -1777,7 +1773,7 @@ GitEngine.prototype.syncRemoteBranchFills = function() { GitEngine.prototype.updateBranchesForHg = function(branchList) { var hasUpdated = false; - _.each(branchList, function(branchID) { + branchList.forEach(function (branchID) { // ok now just check if this branch has a more recent commit available. // that mapping is easy because we always do rebase alt id -- // theres no way to have C3' and C3''' but no C3''. so just @@ -1846,7 +1842,7 @@ GitEngine.prototype.pruneTree = function() { this.command.addWarning(intl.str('hg-prune-tree')); } - _.each(toDelete, function(commit) { + toDelete.forEach(function (commit) { commit.removeFromParents(); this.commitCollection.remove(commit); @@ -1877,7 +1873,7 @@ GitEngine.prototype.getUpstreamCollectionSet = function(collection) { var inArray = function(arr, id) { var found = false; - _.each(arr, function(wrapper) { + arr.forEach(function (wrapper) { if (wrapper.id == id) { found = true; } @@ -1902,7 +1898,7 @@ GitEngine.prototype.getUpstreamCollectionSet = function(collection) { collection.each(function(ref) { var set = bfsSearch(ref.get('target')); - _.each(set, function(id) { + set.forEach(function (id) { commitToSet[id] = commitToSet[id] || []; // only add it if it's not there, so hue blending is ok @@ -2156,7 +2152,7 @@ GitEngine.prototype.rebase = function(targetSource, currentLocation, options) { GitEngine.prototype.getUpstreamDiffSetFromSet = function(stopSet, location) { var set = {}; - _.each(this.getUpstreamDiffFromSet(stopSet, location), function(commit) { + this.getUpstreamDiffFromSet(stopSet, location).forEach(function (commit) { set[commit.get('id')] = true; }); return set; @@ -2189,7 +2185,7 @@ GitEngine.prototype.getInteractiveRebaseCommits = function(targetSource, current // throw out merge's real fast and see if we have anything to do var toRebase = []; - _.each(toRebaseRough, function(commit) { + toRebaseRough.forEach(function (commit) { if (commit.get('parents').length == 1) { toRebase.push(commit); } @@ -2211,7 +2207,7 @@ GitEngine.prototype.rebaseInteractiveTest = function(targetSource, currentLocati var toRebase = this.getInteractiveRebaseCommits(targetSource, currentLocation); var rebaseMap = {}; - _.each(toRebase, function(commit) { + toRebase.forEach(function (commit) { var id = commit.get('id'); rebaseMap[id] = commit; }); @@ -2228,7 +2224,7 @@ GitEngine.prototype.rebaseInteractiveTest = function(targetSource, currentLocati // Verify each chosen commit exists in the list of commits given to the user var extraCommits = []; rebaseOrder = []; - _.each(idsToRebase, function(id) { + idsToRebase.forEach(function (id) { if (id in rebaseMap) { rebaseOrder.push(rebaseMap[id]); } else { @@ -2281,13 +2277,13 @@ GitEngine.prototype.rebaseInteractive = function(targetSource, currentLocation, var initialCommitOrdering; if (options.initialCommitOrdering && options.initialCommitOrdering.length > 0) { var rebaseMap = {}; - _.each(toRebase, function(commit) { + toRebase.forEach(function (commit) { rebaseMap[commit.get('id')] = true; }); // Verify each chosen commit exists in the list of commits given to the user initialCommitOrdering = []; - _.each(options.initialCommitOrdering[0].split(','), function(id) { + options.initialCommitOrdering[0].split(',').forEach(function (id) { if (!rebaseMap[id]) { throw new GitError({ msg: intl.todo('Hey those commits don\'t exist in the set!') @@ -2406,7 +2402,7 @@ GitEngine.prototype.rebaseFinish = function( }.bind(this); // set up the promise chain - _.each(toRebase, function(commit) { + toRebase.forEach(function (commit) { chain = chain.then(function() { return chainStep(commit); }); @@ -2561,7 +2557,7 @@ GitEngine.prototype.describe = function(ref) { // ok we need to BFS from start upwards until we hit a tag. but // first we need to get a reverse mapping from tag to commit var tagMap = {}; - _.each(this.tagCollection.toJSON(), function(tag) { + this.tagCollection.toJSON().forEach(function (tag) { tagMap[tag.target.get('id')] = tag.id; }); @@ -2733,7 +2729,7 @@ GitEngine.prototype.status = function() { lines.push(intl.str('git-status-readytocommit')); var msg = ''; - _.each(lines, function(line) { + lines.forEach(function (line) { msg += '# ' + line + '\n'; }); @@ -2776,7 +2772,7 @@ GitEngine.prototype.log = function(ref, omitSet) { // now go through and collect logs var bigLogStr = ''; - _.each(toDump, function(c) { + toDump.forEach(function (c) { bigLogStr += c.getLogEntry(); }, this); @@ -2831,7 +2827,7 @@ GitEngine.prototype.getDownstreamSet = function(ancestor) { var here = queue.pop(); var children = here.get('children'); - _.each(children, addToExplored); + children.forEach(addToExplored); } return exploredSet; }; @@ -3009,7 +3005,7 @@ var Commit = Backbone.Model.extend({ }, removeFromParents: function() { - _.each(this.get('parents'), function(parent) { + this.get('parents').forEach(function (parent) { parent.removeChild(this); }, this); }, @@ -3052,11 +3048,11 @@ var Commit = Backbone.Model.extend({ removeChild: function(childToRemove) { var newChildren = []; - _.each(this.get('children'), function(child) { + this.get('children').forEach(function (child) { if (child !== childToRemove) { newChildren.push(child); } - }, this); + }); this.set('children', newChildren); }, @@ -3069,7 +3065,7 @@ var Commit = Backbone.Model.extend({ this.validateAtInit(); this.addNodeToVisuals(); - _.each(this.get('parents'), function(parent) { + (this.get('parents') || []).forEach(function (parent) { parent.get('children').push(this); this.addEdgeToVisuals(parent); }, this);