|
1 | 1 | var nodegit = require("../"), |
2 | | - path = require("path"); |
| 2 | + path = require("path"), |
| 3 | + historyFile = "generate/input/descriptor.json", |
| 4 | + walker, |
| 5 | + historyCommits = [], |
| 6 | + commit, |
| 7 | + repo; |
3 | 8 |
|
4 | 9 | // This code walks the history of the master branch and prints results |
5 | 10 | // that look very similar to calling `git log` from the command line |
6 | 11 |
|
| 12 | +function compileHistory(resultingArrayOfCommits) { |
| 13 | + var lastSha; |
| 14 | + if (historyCommits.length > 0) { |
| 15 | + lastSha = historyCommits[historyCommits.length - 1].commit.sha(); |
| 16 | + if ( |
| 17 | + resultingArrayOfCommits.length == 1 && |
| 18 | + resultingArrayOfCommits[0].commit.sha() == lastSha |
| 19 | + ) { |
| 20 | + return; |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + resultingArrayOfCommits.forEach(function(entry) { |
| 25 | + historyCommits.push(entry); |
| 26 | + }); |
| 27 | + |
| 28 | + lastSha = historyCommits[historyCommits.length - 1].commit.sha(); |
| 29 | + |
| 30 | + walker = repo.createRevWalk(); |
| 31 | + walker.push(lastSha); |
| 32 | + walker.sorting(nodegit.Revwalk.SORT.TIME); |
| 33 | + |
| 34 | + return walker.fileHistoryWalk(historyFile, 500) |
| 35 | + .then(compileHistory); |
| 36 | +} |
| 37 | + |
7 | 38 | nodegit.Repository.open(path.resolve(__dirname, "../.git")) |
8 | | - .then(function(repo) { |
| 39 | + .then(function(r) { |
| 40 | + repo = r; |
9 | 41 | return repo.getMasterCommit(); |
10 | 42 | }) |
11 | 43 | .then(function(firstCommitOnMaster){ |
12 | 44 | // History returns an event. |
13 | | - var history = firstCommitOnMaster.history(nodegit.Revwalk.SORT.Time); |
14 | | - var commits = []; |
15 | | - |
16 | | - // History emits "commit" event for each commit in the branch's history |
17 | | - history.on("commit", function(commit) { |
18 | | - return commit.getDiff() |
19 | | - .then(function(diffList) { |
20 | | - diffList.map(function(diff) { |
21 | | - diff.patches().then(function(patches) { |
22 | | - patches.map(function(patch) { |
23 | | - var result = |
24 | | - !!~patch.oldFile().path().indexOf("descriptor.json") || |
25 | | - !!~patch.newFile().path().indexOf("descriptor.json"); |
26 | | - |
27 | | - if(result && !~commits.indexOf(commit)) { |
28 | | - commits.push(commit); |
29 | | - } |
30 | | - }); |
31 | | - }); |
32 | | - }); |
33 | | - }); |
34 | | - }); |
| 45 | + walker = repo.createRevWalk(); |
| 46 | + walker.push(firstCommitOnMaster.sha()); |
| 47 | + walker.sorting(nodegit.Revwalk.SORT.Time); |
35 | 48 |
|
36 | | - history.on("end", function() { |
37 | | - commits.forEach(function(commit) { |
38 | | - console.log("commit " + commit.sha()); |
39 | | - console.log("Author:", commit.author().name() + |
40 | | - " <" + commit.author().email() + ">"); |
41 | | - console.log("Date:", commit.date()); |
42 | | - console.log("\n " + commit.message()); |
43 | | - }); |
| 49 | + return walker.fileHistoryWalk(historyFile, 500); |
| 50 | + }) |
| 51 | + .then(compileHistory) |
| 52 | + .then(function() { |
| 53 | + historyCommits.forEach(function(entry) { |
| 54 | + commit = entry.commit; |
| 55 | + console.log("commit " + commit.sha()); |
| 56 | + console.log("Author:", commit.author().name() + |
| 57 | + " <" + commit.author().email() + ">"); |
| 58 | + console.log("Date:", commit.date()); |
| 59 | + console.log("\n " + commit.message()); |
44 | 60 | }); |
45 | | - |
46 | | - // Don't forget to call `start()`! |
47 | | - history.start(); |
48 | 61 | }) |
49 | 62 | .done(); |
0 commit comments