Skip to content

Commit 3ef32e2

Browse files
Fix commit_create_cb
The definition was wrong parents should be an array of Commits not Oids. Also we are copying the Oid in the callback so we are not returning the Oid so we must not set selfFreeing to false.
1 parent 1c304e5 commit 3ef32e2

4 files changed

Lines changed: 17 additions & 22 deletions

File tree

generate/input/callbacks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
},
169169
{
170170
"name": "parents",
171-
"cType": "const git_oid * []"
171+
"cType": "const git_commit * []"
172172
},
173173
{
174174
"name": "payload",

generate/input/descriptor.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,10 +3142,10 @@
31423142
},
31433143
{
31443144
"name": "parents",
3145-
"cType": "const git_oid **",
3145+
"cType": "const git_commit **",
31463146
"cppClassName": "Array",
31473147
"jsClassName": "Array",
3148-
"arrayElementCppClassName": "GitOid",
3148+
"arrayElementCppClassName": "GitCommit",
31493149
"arrayLengthArgumentName": "parent_count"
31503150
},
31513151
{

generate/templates/partials/configurable_callbacks.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@
145145
else if (!result->IsNull() && !result->IsUndefined()) {
146146
{% if _return.isOutParam %}
147147
{{ _return.cppClassName }}* wrapper = Nan::ObjectWrap::Unwrap<{{ _return.cppClassName }}>(Nan::To<v8::Object>(result).ToLocalChecked());
148-
wrapper->selfFreeing = false;
149148

150149
{% if _return.cppClassName == "GitOid" %}
151150
git_oid_cpy(baton->{{ _return.name }}, wrapper->GetValue());
152151
{% else %}
152+
wrapper->selfFreeing = false;
153153
*baton->{{ _return.name }} = wrapper->GetValue();
154154
{% endif %}
155155
baton->result = {{ field.return.success }};
@@ -185,11 +185,11 @@
185185
else if (!result->IsNull() && !result->IsUndefined()) {
186186
{% if _return.isOutParam %}
187187
{{ _return.cppClassName }}* wrapper = Nan::ObjectWrap::Unwrap<{{ _return.cppClassName }}>(Nan::To<v8::Object>(result).ToLocalChecked());
188-
wrapper->selfFreeing = false;
189188

190189
{% if _return.cppClassName == "GitOid" %}
191190
git_oid_cpy(baton->{{ _return.name }}, wrapper->GetValue());
192191
{% else %}
192+
wrapper->selfFreeing = false;
193193
*baton->{{ _return.name }} = wrapper->GetValue();
194194
{% endif %}
195195
baton->result = {{ field.return.success }};

lib/repository.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ Repository.prototype.createCommitBuffer = function(
623623
* @param {Signature} committer
624624
* @param {String} message
625625
* @param {Tree|Oid|String} Tree
626-
* @param {Array} parents
626+
* @param {Array of Commits} parents
627627
* @param {Function} onSignature Callback to be called with string to be signed
628628
* @return {Oid} The oid of the commit
629629
*/
@@ -638,29 +638,24 @@ Repository.prototype.createCommitWithSignature = function(
638638
) {
639639

640640
var repo = this;
641-
var promises = [];
642641
var commitContent;
643642
var skippedSigning;
644643

645-
parents = parents || [];
646-
647-
promises.push(repo.getTree(tree));
648-
649-
parents.forEach(function(parent) {
650-
promises.push(repo.getCommit(parent));
651-
});
644+
const directTreePromise = Promise.resolve(tree);
652645

653-
const createCommitPromise = Promise.all(promises).then(function(results) {
654-
tree = results[0];
646+
const getTreePromise = function() {
647+
return repo.getTree(tree);
648+
};
655649

656-
// Get the normalized values for our input into the function
657-
var parentsLength = parents.length;
658-
parents = [];
650+
var treePromise;
659651

660-
for (var i = 0; i < parentsLength; i++) {
661-
parents.push(results[i + 1]);
662-
}
652+
if (tree instanceof Tree) {
653+
treePromise = directTreePromise;
654+
} else {
655+
treePromise = getTreePromise();
656+
}
663657

658+
const createCommitPromise = treePromise.then(function(tree) {
664659
return Commit.createBuffer(
665660
repo,
666661
author,

0 commit comments

Comments
 (0)