-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-utilities.js
85 lines (72 loc) 路 1.95 KB
/
git-utilities.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var async = require('async');
var _ = require('lodash');
exports.recurseTree = function (start, path, cb) {
var result = [];
async.series([
// Get an array of blobs wrapped with the path
function (cbSeries) {
if (!start.blobs) {
return cbSeries();
}
start.blobs(function (err, blobs) {
blobs.forEach(function (blob) {
result.push({
path: path + '/' + blob.name,
blob: blob
});
});
cbSeries();
});
},
// Recurse into each subtree and get its blobs too
function (cbSeries) {
if (!start.trees) {
return cbSeries();
}
start.trees(function (err, trees) {
async.forEachSeries(trees, function (tree, cbForEach) {
exports.recurseTree(tree, path + '/' + tree.name,
function (subResult) {
result = result.concat(subResult);
cbForEach();
});
}, function () {
cbSeries();
});
});
}
], function () {
cb(result);
});
};
exports.diffCommitStats = function (a, b) {
var diffs = [];
var paths = _.union(
a ? Object.keys(a.stats) : [],
b ? Object.keys(b.stats) : []
);
paths.forEach(function (path) {
var stats = {
path: path,
diff: {}
};
if (a && b && a.stats && b.stats && a.stats[path] && b.stats[path]) {
if (_.isEqual(a.stats[path], b.stats[path])) {
return;
}
Object.keys(a.stats[path]).forEach(function (key) {
stats.diff[key] = b.stats[path][key] - a.stats[path][key];
});
} else if (a && a.stats && a.stats[path]) {
Object.keys(a.stats[path]).forEach(function (key) {
stats.diff[key] = 0 - a.stats[path][key];
});
} else if (b && b.stats && b.stats[path]) {
Object.keys(b.stats[path]).forEach(function (key) {
stats.diff[key] = b.stats[path][key];
});
}
diffs.push(stats);
});
return diffs;
};