forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (51 loc) · 1.66 KB
/
index.js
File metadata and controls
58 lines (51 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var NodeGit = require("../");
var Index = NodeGit.Index;
var Status = NodeGit.Status;
var Pathspec = NodeGit.Pathspec;
/**
* Return an array of the entries in this index.
* @return {Array<IndexEntry>} an array of IndexEntrys
*/
Index.prototype.entries = function() {
var size = this.entryCount();
var result = [];
for (var i = 0; i < size; i++) {
result.push(this.getByIndex(i));
}
return result;
};
var addAll = Index.prototype.addAll;
Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
// This status path code is here to speedup addall, which currently is
// excessively slow due to adding every single unignored file to the index
// even if it has no changes. Remove this when it's fixed in libgit2
// https://github.com/libgit2/libgit2/issues/2687
var paths = [];
var repo = this.owner();
var statusCB = function(path) {
paths.push(path);
};
var idx = this;
return Pathspec.create(pathspec || "*")
.then(function(ps) {
pathspec = ps;
return Status.foreach(repo, statusCB);
})
.then(function() {
return paths;
})
.then(function(paths) {
paths = paths.filter(function(path) {
return !!(pathspec.matchesPath(0, path));
});
return addAll.call(idx, paths, flags, matchedCallback, null);
});
};
var removeAll = Index.prototype.removeAll;
Index.prototype.removeAll = function(pathspec, matchedCallback) {
return removeAll.call(this, pathspec || "*", matchedCallback, null);
};
var updateAll = Index.prototype.updateAll;
Index.prototype.updateAll = function(pathspec, matchedCallback) {
return updateAll.call(this, pathspec || "*", matchedCallback, null);
};