diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 2e6b09e97..75b886330 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -173,7 +173,10 @@ } }, "git_branch_upstream": { - "isAsync": false + "isAsync": false, + "return" : { + "isErrorCode": true + } } } }, @@ -1092,7 +1095,11 @@ "shouldAlloc": true, "functions": { "git_oid_cpy": { - "ignore": true + "args": { + "out": { + "isReturn": true + } + } }, "git_oid_fmt": { "ignore": true @@ -1601,6 +1608,16 @@ "git_status_byindex": { "isAsync": false }, + "git_status_file": { + "args": { + "status_flags": { + "isReturn": true + }, + "return": { + "isErrorCode": true + } + } + }, "git_status_foreach": { "isAsync": true, "return": { diff --git a/generate/scripts/generateNativeCode.js b/generate/scripts/generateNativeCode.js index 3774d1d56..4e2884c1b 100644 --- a/generate/scripts/generateNativeCode.js +++ b/generate/scripts/generateNativeCode.js @@ -56,7 +56,7 @@ module.exports = function generateNativeCode() { defaultValue: require("../templates/filters/default_value"), fieldsInfo: require("../templates/filters/fields_info"), hasReturnType: require("../templates/filters/has_return_type"), - hasReturns: require("../templates/filters/has_returns"), + hasReturnValue: require("../templates/filters/has_return_value"), isDoublePointer: require("../templates/filters/is_double_pointer"), isFixedLengthString: require("../templates/filters/is_fixed_length_string"), isOid: require("../templates/filters/is_oid"), diff --git a/generate/templates/filters/has_return_value.js b/generate/templates/filters/has_return_value.js new file mode 100644 index 000000000..bbe371808 --- /dev/null +++ b/generate/templates/filters/has_return_value.js @@ -0,0 +1,9 @@ +module.exports = function(fn) { + if (fn.return + && !fn.return.isErrorCode + && fn.return.cType != "void") { + return true + } + + return false; +}; diff --git a/generate/templates/filters/has_returns.js b/generate/templates/filters/has_returns.js deleted file mode 100644 index 733bfe6a3..000000000 --- a/generate/templates/filters/has_returns.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = function(fn) { - var args = fn.args || []; - var result = args.some(function (arg) { - return arg.isReturn; - }); - - if (!result - && fn.return - && !fn.return.isErrorCode - && fn.return.cType != "void") { - result = true; - } - - return result || (fn.return && fn.return.isErrorCode); -}; diff --git a/generate/templates/partials/sync_function.cc b/generate/templates/partials/sync_function.cc index eaca6480f..cf9ab11f2 100644 --- a/generate/templates/partials/sync_function.cc +++ b/generate/templates/partials/sync_function.cc @@ -36,7 +36,7 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) { if (ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->GetValue() != NULL) { {% endif %} -{%if .|hasReturns %} +{%if .|hasReturnValue %} {{ return.cType }} result = {%endif%}{{ cFunctionName }}( {%each args|argsInfo as arg %} {%if arg.isReturn %} @@ -53,7 +53,7 @@ from_{{ arg.name }} {%endeach%} ); -{%if return.isErrorCode %} +{%if .|hasReturnValue |and return.isErrorCode %} if (result != GIT_OK) { {%each args|argsInfo as arg %} {%if arg.shouldAlloc %} diff --git a/lib/oid.js b/lib/oid.js index 42d4405af..c3a84ecfb 100644 --- a/lib/oid.js +++ b/lib/oid.js @@ -14,6 +14,10 @@ Object.defineProperties(Oid.prototype, { } }); +Oid.prototype.copy = function() { + return this.cpy(); // seriously??? +}; + Oid.prototype.inspect = function() { return "[Oid " + this.allocfmt() + "]"; }; diff --git a/lib/stash.js b/lib/stash.js index 63aa2c6ce..960d7b648 100644 --- a/lib/stash.js +++ b/lib/stash.js @@ -5,5 +5,12 @@ var Stash = NodeGit.Stash; // Override Stash.foreach to eliminate the need to pass null payload var foreach = Stash.foreach; Stash.foreach = function(repo, callback) { - return foreach(repo, callback, null); + function wrappedCallback(index, message, oid) { + // We need to copy the OID since libgit2 types are getting cleaned up + // incorrectly right now in callbacks + + return callback(index, message, oid.copy()); + } + + return foreach(repo, wrappedCallback, null); };