Skip to content

Commit a8fd045

Browse files
committed
make index.addAll use status to speed up
1 parent 8b3753f commit a8fd045

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

lib/index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var NodeGit = require("../");
22

33
var Index = NodeGit.Index;
4-
4+
var Status = NodeGit.Status;
5+
var Promise = require("nodegit-promise");
56
/**
67
* Return an array of the entries in this index.
78
* @return {Array<IndexEntry>} an array of IndexEntrys
@@ -19,7 +20,21 @@ Index.prototype.entries = function() {
1920

2021
var addAll = Index.prototype.addAll;
2122
Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
22-
return addAll.call(this, pathspec || "*", flags, matchedCallback, null);
23+
// This status path code is here to speedup addall, which currently is
24+
// excessively slow due to adding every single unignored file to the index
25+
// even if it has no changes. Remove this when it's fixed in libgit2
26+
// https://github.com/libgit2/libgit2/issues/2687
27+
var paths = [];
28+
var statusCB = function(path) {
29+
paths.push(path);
30+
};
31+
return Status.foreach(this.owner(), statusCB)
32+
.then(function() {
33+
return Promise.resolve(paths);
34+
})
35+
.then(function(paths) {
36+
return addAll.call(this, pathspec || "*", flags, matchedCallback, null);
37+
});
2338
};
2439

2540
var removeAll = Index.prototype.removeAll;

0 commit comments

Comments
 (0)