From 945b09d79f4b34a7e709287acbed660bdc33e802 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Wed, 2 Aug 2017 15:23:44 -0700 Subject: [PATCH 01/14] Convert git_status_file to an async method --- generate/input/descriptor.json | 1 + generate/templates/partials/async_function.cc | 11 ++++ lib/repository.js | 65 +++++++++++++------ 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 1e9aeaf8b..659a63403 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -2241,6 +2241,7 @@ "isAsync": false }, "git_status_file": { + "isAsync": true, "args": { "status_flags": { "isReturn": true diff --git a/generate/templates/partials/async_function.cc b/generate/templates/partials/async_function.cc index 20813136d..ca4bd8d47 100644 --- a/generate/templates/partials/async_function.cc +++ b/generate/templates/partials/async_function.cc @@ -10,6 +10,11 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) { baton->error_code = GIT_OK; baton->error = NULL; + {%if cppClassName == "GitStatus" %} + {%if cppFunctionName == "File" %} + baton->status_flags = (unsigned int *)malloc(sizeof(unsigned int)); + {%endif%} + {%endif%} {%each args|argsInfo as arg %} {%if arg.globalPayload %} @@ -260,6 +265,12 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() { {%endeach%} } + {%if cppClassName == "GitStatus" %} + {%if cppFunctionName == "File" %} + free((void *)baton->status_flags); + {%endif%} + {%endif%} + {%each args|argsInfo as arg %} {%if arg.isCppClassStringOrArray %} {%if arg.freeFunctionName %} diff --git a/lib/repository.js b/lib/repository.js index 90be1d91c..3c4dcbda4 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -150,15 +150,15 @@ function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) { }); }) .then(function(diff) { - if (!(NodeGit.Status.file(repo, filePath) & - NodeGit.Status.STATUS.WT_MODIFIED) && - !(NodeGit.Status.file(repo, filePath) & - NodeGit.Status.STATUS.INDEX_MODIFIED)) { - return Promise.reject - ("Selected staging is only available on modified files."); - } - - return diff.patches(); + return NodeGit.Status.file(repo, filePath) + .then(function(status) { + if (!(status & NodeGit.Status.STATUS.WT_MODIFIED) && + !(status & NodeGit.Status.STATUS.INDEX_MODIFIED)) { + return Promise.reject + ("Selected staging is only available on modified files."); + } + return diff.patches(); + }); }) .then(function(patches) { var pathPatch = patches.filter(function(patch) { @@ -1636,17 +1636,42 @@ Repository.prototype.stageFilemode = }) .then(function(diff) { var origLength = filePaths.length; - filePaths = filePaths.filter(function(p) { - return ( - (NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.WT_MODIFIED) || - (NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.INDEX_MODIFIED) - ); - }); - if (filePaths.length === 0 && origLength > 0) { - return Promise.reject - ("Selected staging is only available on modified files."); - } - return diff.patches(); + var fileFilterPromises = fp.map(function(p) { + return NodeGit.Status.file(repo, p) + .then(function(status) { + return { + path: p, + filter: ( + (status & NodeGit.Status.STATUS.WT_MODIFIED) || + (status & NodeGit.Status.STATUS.INDEX_MODIFIED) + ) + }; + }); + }, filePaths); + + return Promise.all(fileFilterPromises) + .then(function(results) { + filePaths = fp.flow([ + fp.filter(function(filterResult) { + return filterResult.filter; + }), + fp.map(function(filterResult) { + return filterResult.path; + }) + ])(results); + + if (filePaths.length === 0 && origLength > 0) { + return Promise.reject + ("Selected staging is only available on modified files."); + } + return diff.patches(); + }); +// filePaths = filePaths.filter(function(p) { +// return ( +// (NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.WT_MODIFIED) || +// (NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.INDEX_MODIFIED) +// ); +// }); }) .then(function(patches) { var pathPatches = patches.filter(function(patch) { From 54a278624740fdc4e049556d15010432080919d1 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Wed, 2 Aug 2017 15:29:03 -0700 Subject: [PATCH 02/14] removed comments --- lib/repository.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/repository.js b/lib/repository.js index 3c4dcbda4..a5a0012fa 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -1666,12 +1666,6 @@ Repository.prototype.stageFilemode = } return diff.patches(); }); -// filePaths = filePaths.filter(function(p) { -// return ( -// (NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.WT_MODIFIED) || -// (NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.INDEX_MODIFIED) -// ); -// }); }) .then(function(patches) { var pathPatches = patches.filter(function(patch) { From 89c34899db978b618ff49a3b286595bd993d4927 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Tue, 8 Aug 2017 08:19:28 -0700 Subject: [PATCH 03/14] BREAKING: Made Merge.merge async --- generate/input/descriptor.json | 22 ++++++++++++++++++++++ test/tests/merge.js | 4 +--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 659a63403..234b91e3c 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1268,13 +1268,35 @@ "merge": { "functions": { "git_merge": { + "isAsync": true, "args": { + "repo": { + "cppClassName": "GitRepository", + "cType": "git_repository *", + "jsClassName": "Repo" + }, "their_heads": { "cType": "const git_annotated_commit **", "cppClassName": "Array", "jsClassName": "Array", "arrayElementCppClassName": "GitAnnotatedCommit" + }, + "their_heads_len": { + "cType": "size_t", + "cppClassName": "Number", + "jsClassName": "Number" + }, + "merge_opts": { + "cType": "git_merge_options *", + "cppClassName": "GitMergeOptions" + }, + "checkout_opts": { + "cType": "git_checkout_options *", + "cppClassName": "GitCheckoutOptions" } + }, + "return": { + "isErrorCode": true } }, "git_merge_analysis": { diff --git a/test/tests/merge.js b/test/tests/merge.js index 66728bdb9..86531aa2c 100644 --- a/test/tests/merge.js +++ b/test/tests/merge.js @@ -1539,9 +1539,7 @@ describe("Merge", function() { .then(function(theirAnnotatedCommit) { return NodeGit.Merge(repository, theirAnnotatedCommit); }) - .then(function(result) { - assert.equal(result, 0); - + .then(function() { assert.equal(repository.state(), NodeGit.Repository.STATE.MERGE); // verify the convenience method From 9927174ba75cb48e55896126778f203b82c39488 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Tue, 8 Aug 2017 12:11:57 -0700 Subject: [PATCH 04/14] updated rebase.commit to be async --- generate/input/descriptor.json | 7 ++++++ lib/rebase.js | 14 ++++++++++++ lib/repository.js | 42 +++++++++++++++++++--------------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 234b91e3c..be711db91 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1681,8 +1681,12 @@ "rebase": { "functions": { "git_rebase_commit": { + "isAsync": true, "args": { "id": { + "cType": "git_oid *", + "cppClassName": "GitOid", + "jsClassName": "Oid", "isReturn": true, "shouldAlloc": true }, @@ -1695,6 +1699,9 @@ "message": { "isOptional": true } + }, + "return": { + "isErrorCode": true } }, "git_rebase_finish": { diff --git a/lib/rebase.js b/lib/rebase.js index 22ca72c7d..1c112f051 100644 --- a/lib/rebase.js +++ b/lib/rebase.js @@ -5,6 +5,7 @@ var shallowClone = NodeGit.Utils.shallowClone; var _init = Rebase.init; var _open = Rebase.open; +var _commit = Rebase.prototype.commit; /** * Initializes a rebase * @async @@ -83,3 +84,16 @@ Rebase.open = function(repository, options) { ); return _open(repository, options); }; + +Rebase.prototype.commit = + function(author, committer, encoding, message, callback) { + return _commit.call(this, author, committer, encoding, message) + .then(function(oid) { + if (typeof callback === "function") { + callback(null, oid); + } + + return oid; + }, callback); + }; + diff --git a/lib/repository.js b/lib/repository.js index a5a0012fa..b841097ae 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -217,23 +217,26 @@ function performRebase( function getPromise() { return rebase.next() .then(function() { - return repository.refreshIndex() - .then(function(index) { - if (index.hasConflicts()) { - throw index; - } + return repository.refreshIndex(); + }) + .then(function(index) { + if (index.hasConflicts()) { + throw index; + } - rebase.commit(null, signature); + return rebase.commit(null, signature); + }) + .then(function() { - return performRebase( - repository, - rebase, - signature, - beforeNextFn, - beforeFinishFn - ); - }); - }, function(error) { + return performRebase( + repository, + rebase, + signature, + beforeNextFn, + beforeFinishFn + ); + }) + .catch(function(error) { if (error && error.errno === NodeGit.Error.CODE.ITEROVER) { const calcRewritten = fp.flow([ fp.split("\n"), @@ -435,6 +438,7 @@ Repository.prototype.continueRebase = function( signature = signature || repo.defaultSignature(); + var rebase; return repo.refreshIndex() .then(function(index) { if (index.hasConflicts()) { @@ -443,9 +447,11 @@ Repository.prototype.continueRebase = function( return NodeGit.Rebase.open(repo); }) - .then(function(rebase) { - rebase.commit(null, signature); - + .then(function(_rebase) { + rebase = _rebase; + return rebase.commit(null, signature); + }) + .then(function(oid) { return performRebase( repo, rebase, From 0f389936116c033927f1099ef1923c063122b1f1 Mon Sep 17 00:00:00 2001 From: Mohseen Mukaddam Date: Wed, 9 Aug 2017 11:45:34 -0700 Subject: [PATCH 05/14] Converted rebase abort to async --- generate/input/descriptor.json | 16 ++++++++++++++++ lib/rebase.js | 11 +++++++++++ test/tests/rebase.js | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index be711db91..a1832cd1c 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1729,6 +1729,22 @@ "isOptional": true } } + }, + "git_rebase_abort": { + "isAsync": true, + "args": { + "rebase": { + "cType": "git_rebase *", + "cppClassName": "GitRebase", + "jsClassName": "Rebase", + "isOptional": false, + "isSelf": true, + "isReturn": false + } + }, + "return": { + "isErrorCode": true + } } } }, diff --git a/lib/rebase.js b/lib/rebase.js index 1c112f051..8250c8663 100644 --- a/lib/rebase.js +++ b/lib/rebase.js @@ -5,6 +5,7 @@ var shallowClone = NodeGit.Utils.shallowClone; var _init = Rebase.init; var _open = Rebase.open; +var _abort = Rebase.prototype.abort; var _commit = Rebase.prototype.commit; /** * Initializes a rebase @@ -97,3 +98,13 @@ Rebase.prototype.commit = }, callback); }; +Rebase.prototype.abort = + function(callback) { + return _abort.call(this) + .then(function() { + if (typeof callback === "function") { + callback(null); + } + }, callback); + }; + diff --git a/test/tests/rebase.js b/test/tests/rebase.js index 731884f82..d121a6c0f 100644 --- a/test/tests/rebase.js +++ b/test/tests/rebase.js @@ -658,7 +658,7 @@ describe("Rebase", function() { }); }) .then(function() { - return rebase.abort(ourSignature); + return rebase.abort(); }) .then(function() { return NodeGit.Rebase.open(repository) From 766d3dda0e5f1bc7dd72573c6afdabb2db005338 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Wed, 9 Aug 2017 16:21:01 -0700 Subject: [PATCH 06/14] Fixed error in continueRebase --- lib/repository.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/repository.js b/lib/repository.js index b841097ae..42093d3db 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -449,9 +449,13 @@ Repository.prototype.continueRebase = function( }) .then(function(_rebase) { rebase = _rebase; - return rebase.commit(null, signature); + return rebase.commit(null, signature) + .catch(function() { + // we are ignoring errors. This is to prevent issues caused by making this async + return 0; + }); }) - .then(function(oid) { + .then(function() { return performRebase( repo, rebase, From 7e65c095343156b557c58441db89d2b3f72acbb4 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Thu, 10 Aug 2017 08:03:22 -0700 Subject: [PATCH 07/14] fixed linter error --- lib/repository.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/repository.js b/lib/repository.js index 42093d3db..0637cec47 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -451,7 +451,10 @@ Repository.prototype.continueRebase = function( rebase = _rebase; return rebase.commit(null, signature) .catch(function() { - // we are ignoring errors. This is to prevent issues caused by making this async + // Ignore all errors to prevent + // this routine from choking now + // that we made rebase.commit + // asynchronous return 0; }); }) From 6ded1d23b278b8165896b7d103e4a9b335b9bc1d Mon Sep 17 00:00:00 2001 From: Mohseen Mukaddam Date: Thu, 10 Aug 2017 09:55:30 -0700 Subject: [PATCH 08/14] converted commit amend to async --- generate/input/descriptor.json | 1 + 1 file changed, 1 insertion(+) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index a1832cd1c..d6506d1d6 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -402,6 +402,7 @@ "selfFreeing": true, "functions": { "git_commit_amend": { + "isAsync": true, "args": { "author": { "isOptional": true From 63f4db04626503ae99ea3ae2b6b785eaea81897c Mon Sep 17 00:00:00 2001 From: Mohseen Mukaddam Date: Thu, 10 Aug 2017 16:50:02 -0700 Subject: [PATCH 09/14] Converting git_reflog_write to async --- generate/input/descriptor.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index d6506d1d6..563ae0eb0 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1844,6 +1844,17 @@ "needsForwardDeclaration": false, "ignore": true }, + "reflog": { + "functions": { + "git_reflog_write": { + "isAsync": true, + "isSelf": true, + "return": { + "isErrorCode": true + } + } + } + }, "reflog_entry": { "functions": { "git_reflog_entry_id_new": { From 080e8aafe7354010f08cce842256070c313160ee Mon Sep 17 00:00:00 2001 From: Mohseen Mukaddam Date: Fri, 11 Aug 2017 13:51:28 -0700 Subject: [PATCH 10/14] babel cli fix for travis --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5becdd1c1..686c8357d 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "host": "https://nodegit.s3.amazonaws.com/nodegit/nodegit/" }, "scripts": { - "babel": "babel --presets es2015 -d ./dist ./lib", + "babel": "babel --presets es2015 -d dist lib", "cov": "npm run cppcov && npm run filtercov && npm run mergecov", "coveralls": "cat ./test/coverage/merged.lcov | coveralls", "cppcov": "mkdir -p test/coverage/cpp && ./lcov-1.10/bin/lcov --gcov-tool /usr/bin/gcov-4.9 --capture --directory build/Release/obj.target/nodegit/src --output-file test/coverage/cpp/lcov_full.info", From 34a9e594ffcc3e4324325b3b4af7a340964c6fd2 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Mon, 14 Aug 2017 08:08:14 -0700 Subject: [PATCH 11/14] Reverted unnecessary babel changes. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 686c8357d..5becdd1c1 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "host": "https://nodegit.s3.amazonaws.com/nodegit/nodegit/" }, "scripts": { - "babel": "babel --presets es2015 -d dist lib", + "babel": "babel --presets es2015 -d ./dist ./lib", "cov": "npm run cppcov && npm run filtercov && npm run mergecov", "coveralls": "cat ./test/coverage/merged.lcov | coveralls", "cppcov": "mkdir -p test/coverage/cpp && ./lcov-1.10/bin/lcov --gcov-tool /usr/bin/gcov-4.9 --capture --directory build/Release/obj.target/nodegit/src --output-file test/coverage/cpp/lcov_full.info", From 2e32eeb14f0e6c0b5e9afdef5387bc05d2188e2f Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Tue, 15 Aug 2017 14:52:41 -0700 Subject: [PATCH 12/14] Fixed status_file special case --- generate/input/descriptor.json | 3 ++- generate/templates/partials/async_function.cc | 11 ----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 563ae0eb0..1290486d9 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -2301,7 +2301,8 @@ "isAsync": true, "args": { "status_flags": { - "isReturn": true + "isReturn": true, + "shouldAlloc": true }, "return": { "isErrorCode": true diff --git a/generate/templates/partials/async_function.cc b/generate/templates/partials/async_function.cc index ca4bd8d47..20813136d 100644 --- a/generate/templates/partials/async_function.cc +++ b/generate/templates/partials/async_function.cc @@ -10,11 +10,6 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) { baton->error_code = GIT_OK; baton->error = NULL; - {%if cppClassName == "GitStatus" %} - {%if cppFunctionName == "File" %} - baton->status_flags = (unsigned int *)malloc(sizeof(unsigned int)); - {%endif%} - {%endif%} {%each args|argsInfo as arg %} {%if arg.globalPayload %} @@ -265,12 +260,6 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() { {%endeach%} } - {%if cppClassName == "GitStatus" %} - {%if cppFunctionName == "File" %} - free((void *)baton->status_flags); - {%endif%} - {%endif%} - {%each args|argsInfo as arg %} {%if arg.isCppClassStringOrArray %} {%if arg.freeFunctionName %} From f39bf863c123ff77cf85f51edc766313bdfd07c8 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Tue, 15 Aug 2017 15:01:49 -0700 Subject: [PATCH 13/14] removed old callback style code --- lib/rebase.js | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/rebase.js b/lib/rebase.js index 8250c8663..eb0957081 100644 --- a/lib/rebase.js +++ b/lib/rebase.js @@ -87,24 +87,11 @@ Rebase.open = function(repository, options) { }; Rebase.prototype.commit = - function(author, committer, encoding, message, callback) { - return _commit.call(this, author, committer, encoding, message) - .then(function(oid) { - if (typeof callback === "function") { - callback(null, oid); - } - - return oid; - }, callback); + function(author, committer, encoding, message) { + return _commit.call(this, author, committer, encoding, message); }; -Rebase.prototype.abort = - function(callback) { - return _abort.call(this) - .then(function() { - if (typeof callback === "function") { - callback(null); - } - }, callback); +Rebase.prototype.abort = function() { + return _abort.call(this); }; From 3b548992f5cccd5c560d1460b8bf9253157408f0 Mon Sep 17 00:00:00 2001 From: Carson Howard Date: Tue, 15 Aug 2017 15:10:18 -0700 Subject: [PATCH 14/14] Formatting; removed unnecessary return of 0 --- lib/rebase.js | 11 +++++------ lib/repository.js | 1 - 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/rebase.js b/lib/rebase.js index eb0957081..28882ea6c 100644 --- a/lib/rebase.js +++ b/lib/rebase.js @@ -86,12 +86,11 @@ Rebase.open = function(repository, options) { return _open(repository, options); }; -Rebase.prototype.commit = - function(author, committer, encoding, message) { - return _commit.call(this, author, committer, encoding, message); - }; +Rebase.prototype.commit = function(author, committer, encoding, message) { + return _commit.call(this, author, committer, encoding, message); +}; Rebase.prototype.abort = function() { - return _abort.call(this); - }; + return _abort.call(this); +}; diff --git a/lib/repository.js b/lib/repository.js index 0637cec47..bcf8591c7 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -455,7 +455,6 @@ Repository.prototype.continueRebase = function( // this routine from choking now // that we made rebase.commit // asynchronous - return 0; }); }) .then(function() {