Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated diff-commits
  • Loading branch information
John Haley committed Nov 15, 2014
commit 6dd55dd476e1b470c58545e8beedf131c78cba05
45 changes: 21 additions & 24 deletions example/diff-commits.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
var git = require('../'),
path = require('path');
var git = require('../');
var path = require('path');

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

git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
if (error) throw error;
git.Repository.open(path.resolve(__dirname, '../.git'))
.then(function(repo) {
return repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5');
})
.then(function(commit) {
console.log('commit ' + commit.sha());
console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>');
console.log('Date:', commit.date());
console.log('\n ' + commit.message());

repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) {
if (error) throw error;

console.log('commit ' + commit.sha());
console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>');
console.log('Date:', commit.date());
console.log('\n ' + commit.message());

commit.getDiff(function(error, diffList) {
if (error) throw error;

diffList.forEach(function(diff) {
diff.patches().forEach(function(patch) {
console.log("diff", patch.oldFile().path(), patch.newFile().path());
patch.hunks().forEach(function(hunk) {
console.log(hunk.header().trim());
hunk.lines().forEach(function(line) {
console.log(String.fromCharCode(line.lineOrigin) + line.content.trim());
});
});
return commit.getDiff();
})
.done(function(diffList) {
diffList.forEach(function(diff) {
diff.patches().forEach(function(patch) {
console.log("diff", patch.oldFile().path(), patch.newFile().path());
patch.hunks().forEach(function(hunk) {
console.log(hunk.header().trim());
hunk.lines().forEach(function(line) {
console.log(String.fromCharCode(line.origin()) + line.content().trim());
});
});
});
Expand Down
10 changes: 9 additions & 1 deletion generate/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,15 @@
"isAsync": false
},
"git_patch_get_hunk": {
"ignore": true
"args": {
"out": {
"returnName": "hunk"
},
"lines_in_hunk": {
"isReturn": true
}
},
"isAsync": false
},
"git_patch_get_line_in_hunk": {
"isAsync": false
Expand Down
4 changes: 2 additions & 2 deletions generate/filters/returns_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function(fn, argReturnsOnly, isAsync) {
return_info.parsedName = isAsync ? "baton->" + return_info.name : return_info.name;
return_info.isCppClassIntType = ~['Uint32', 'Int32'].indexOf(return_info.cppClassName);
return_info.parsedClassName = (return_info.cppClassName || '').toLowerCase() + "_t";
return_info.jsNameOrName = return_info.jsName | return_info.name;
return_info.returnNameOrName = return_info.returnName || return_info.name;
return_info.jsOrCppClassName = return_info.jsClassName || return_info.cppClassName;

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

result.push(return_info);
Expand Down
26 changes: 26 additions & 0 deletions generate/libgit2-supplement.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@
"int new_lines",
"size_t header_len",
"char header[128]"
],
"fields": [
{
"name": "old_start",
"type": "int"
},
{
"name": "old_lines",
"type": "int"
},
{
"name": "new_start",
"type": "int"
},
{
"name": "new_lines",
"type": "int"
},
{
"name": "header_len",
"type": "size_t"
},
{
"name": "header",
"type": "char *"
}
]
},
"git_diff_line": {
Expand Down
2 changes: 1 addition & 1 deletion generate/partials/async_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
{%each .|returnsInfo 0 1 as _return %}
{%partial convertToV8 _return %}
{%if .|returnsCount > 1 %}
result->Set(NanNew<String>("{{ _return.jsNameOrName }}"), to);
result->Set(NanNew<String>("{{ _return.returnNameOrName }}"), to);
{%endif%}
{%endeach%}
{%if .|returnsCount == 1 %}
Expand Down
2 changes: 1 addition & 1 deletion generate/partials/sync_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ from_{{ arg.name }}
{%each .|returnsInfo as _return %}
{%partial convertToV8 _return %}
{%if .|returnsCount > 1 %}
toReturn->Set(NanNew<String>("{{ _return.jsNameOrName }}"), to);
toReturn->Set(NanNew<String>("{{ _return.returnNameOrName }}"), to);
{%endif%}
{%endeach%}
{%if .|returnsCount == 1 %}
Expand Down
2 changes: 1 addition & 1 deletion lib/convenient_hunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function ConvenientHunk(raw, i) {
* @return {String}
*/
ConvenientHunk.prototype.header = function() {
return this.raw.hunk(this.i).header;
return this.raw.getHunk(this.i).hunk.header();
};

/**
Expand Down