Skip to content

Commit 6dd55dd

Browse files
author
John Haley
committed
Updated diff-commits
1 parent 316f4ce commit 6dd55dd

7 files changed

Lines changed: 61 additions & 30 deletions

File tree

example/diff-commits.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
var git = require('../'),
2-
path = require('path');
1+
var git = require('../');
2+
var path = require('path');
33

44
// This code examines the diffs between a particular commit and all of its
55
// parents. Since this commit is not a merge, it only has one parent. This is
66
// similar to doing `git show`.
77

8-
git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
9-
if (error) throw error;
8+
git.Repository.open(path.resolve(__dirname, '../.git'))
9+
.then(function(repo) {
10+
return repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5');
11+
})
12+
.then(function(commit) {
13+
console.log('commit ' + commit.sha());
14+
console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>');
15+
console.log('Date:', commit.date());
16+
console.log('\n ' + commit.message());
1017

11-
repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) {
12-
if (error) throw error;
13-
14-
console.log('commit ' + commit.sha());
15-
console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>');
16-
console.log('Date:', commit.date());
17-
console.log('\n ' + commit.message());
18-
19-
commit.getDiff(function(error, diffList) {
20-
if (error) throw error;
21-
22-
diffList.forEach(function(diff) {
23-
diff.patches().forEach(function(patch) {
24-
console.log("diff", patch.oldFile().path(), patch.newFile().path());
25-
patch.hunks().forEach(function(hunk) {
26-
console.log(hunk.header().trim());
27-
hunk.lines().forEach(function(line) {
28-
console.log(String.fromCharCode(line.lineOrigin) + line.content.trim());
29-
});
30-
});
18+
return commit.getDiff();
19+
})
20+
.done(function(diffList) {
21+
diffList.forEach(function(diff) {
22+
diff.patches().forEach(function(patch) {
23+
console.log("diff", patch.oldFile().path(), patch.newFile().path());
24+
patch.hunks().forEach(function(hunk) {
25+
console.log(hunk.header().trim());
26+
hunk.lines().forEach(function(line) {
27+
console.log(String.fromCharCode(line.origin()) + line.content().trim());
3128
});
3229
});
3330
});

generate/descriptor.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,15 @@
786786
"isAsync": false
787787
},
788788
"git_patch_get_hunk": {
789-
"ignore": true
789+
"args": {
790+
"out": {
791+
"returnName": "hunk"
792+
},
793+
"lines_in_hunk": {
794+
"isReturn": true
795+
}
796+
},
797+
"isAsync": false
790798
},
791799
"git_patch_get_line_in_hunk": {
792800
"isAsync": false

generate/filters/returns_info.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function(fn, argReturnsOnly, isAsync) {
1212
return_info.parsedName = isAsync ? "baton->" + return_info.name : return_info.name;
1313
return_info.isCppClassIntType = ~['Uint32', 'Int32'].indexOf(return_info.cppClassName);
1414
return_info.parsedClassName = (return_info.cppClassName || '').toLowerCase() + "_t";
15-
return_info.jsNameOrName = return_info.jsName | return_info.name;
15+
return_info.returnNameOrName = return_info.returnName || return_info.name;
1616
return_info.jsOrCppClassName = return_info.jsClassName || return_info.cppClassName;
1717

1818
result.push(return_info);
@@ -29,7 +29,7 @@ module.exports = function(fn, argReturnsOnly, isAsync) {
2929
return_info.parsedName = return_info.name && isAsync ? "baton->" + return_info.name : "result";
3030
return_info.isCppClassIntType = ~['Uint32', 'Int32'].indexOf(return_info.cppClassName);
3131
return_info.parsedClassName = (return_info.cppClassName || '').toLowerCase() + "_t";
32-
return_info.jsNameOrName = return_info.jsName | return_info.name;
32+
return_info.returnNameOrName = return_info.returnName || return_info.name;
3333
return_info.jsOrCppClassName = return_info.jsClassName || return_info.cppClassName;
3434

3535
result.push(return_info);

generate/libgit2-supplement.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@
1111
"int new_lines",
1212
"size_t header_len",
1313
"char header[128]"
14+
],
15+
"fields": [
16+
{
17+
"name": "old_start",
18+
"type": "int"
19+
},
20+
{
21+
"name": "old_lines",
22+
"type": "int"
23+
},
24+
{
25+
"name": "new_start",
26+
"type": "int"
27+
},
28+
{
29+
"name": "new_lines",
30+
"type": "int"
31+
},
32+
{
33+
"name": "header_len",
34+
"type": "size_t"
35+
},
36+
{
37+
"name": "header",
38+
"type": "char *"
39+
}
1440
]
1541
},
1642
"git_diff_line": {

generate/partials/async_function.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
8686
{%each .|returnsInfo 0 1 as _return %}
8787
{%partial convertToV8 _return %}
8888
{%if .|returnsCount > 1 %}
89-
result->Set(NanNew<String>("{{ _return.jsNameOrName }}"), to);
89+
result->Set(NanNew<String>("{{ _return.returnNameOrName }}"), to);
9090
{%endif%}
9191
{%endeach%}
9292
{%if .|returnsCount == 1 %}

generate/partials/sync_function.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ from_{{ arg.name }}
6969
{%each .|returnsInfo as _return %}
7070
{%partial convertToV8 _return %}
7171
{%if .|returnsCount > 1 %}
72-
toReturn->Set(NanNew<String>("{{ _return.jsNameOrName }}"), to);
72+
toReturn->Set(NanNew<String>("{{ _return.returnNameOrName }}"), to);
7373
{%endif%}
7474
{%endeach%}
7575
{%if .|returnsCount == 1 %}

lib/convenient_hunk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function ConvenientHunk(raw, i) {
99
* @return {String}
1010
*/
1111
ConvenientHunk.prototype.header = function() {
12-
return this.raw.hunk(this.i).header;
12+
return this.raw.getHunk(this.i).hunk.header();
1313
};
1414

1515
/**

0 commit comments

Comments
 (0)