Skip to content

Commit 8d159d8

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 8d159d8

File tree

4 files changed

+47
-52
lines changed

4 files changed

+47
-52
lines changed

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: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,11 @@ 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
*/
630-
Repository.prototype.createCommitWithSignature = function(
630+
Repository.prototype.createCommitWithSignature = async function(
631631
updateRef,
632632
author,
633633
committer,
@@ -636,32 +636,32 @@ Repository.prototype.createCommitWithSignature = function(
636636
parents,
637637
onSignature
638638
) {
639+
let repo = this;
640+
let newParents = [];
641+
let skippedSigning = false;
639642

640-
var repo = this;
641-
var promises = [];
642-
var commitContent;
643-
var skippedSigning;
644-
645-
parents = parents || [];
646-
647-
promises.push(repo.getTree(tree));
643+
if (!(tree instanceof Tree)) {
644+
tree = await repo.getTree(tree);
645+
}
648646

649-
parents.forEach(function(parent) {
650-
promises.push(repo.getCommit(parent));
647+
let showDeprecationWarning = false;
648+
parents.forEach(async (parent) => {
649+
if (!(parent instanceof Commit)) {
650+
newParents.push(await repo.getCommit(parent));
651+
showDeprecationWarning = true;
652+
} else {
653+
newParents.push(parent);
654+
}
651655
});
652656

653-
const createCommitPromise = Promise.all(promises).then(function(results) {
654-
tree = results[0];
655-
656-
// Get the normalized values for our input into the function
657-
var parentsLength = parents.length;
658-
parents = [];
657+
if (showDeprecationWarning) {
658+
console.warn('DeprecationWarning: Parents in Repository.createCommitWithSignature should be an array of Commits instead an array of Oid|Strings');
659+
}
659660

660-
for (var i = 0; i < parentsLength; i++) {
661-
parents.push(results[i + 1]);
662-
}
661+
parents = newParents;
663662

664-
return Commit.createBuffer(
663+
const createCommitPromise = async () => {
664+
let commitContent = await Commit.createBuffer(
665665
repo,
666666
author,
667667
committer,
@@ -671,13 +671,12 @@ Repository.prototype.createCommitWithSignature = function(
671671
parents.length,
672672
parents
673673
);
674-
}).then(function(commitContentResult) {
675-
commitContent = commitContentResult;
676674
if (!commitContent.endsWith("\n")) {
677675
commitContent += "\n";
678676
}
679-
return onSignature(commitContent);
680-
}).then(function({ code, field, signedData }) {
677+
678+
const { code, field, signedData } = await onSignature(commitContent);
679+
681680
switch (code) {
682681
case NodeGit.Error.CODE.OK:
683682
return Commit.createWithSignature(
@@ -708,32 +707,28 @@ Repository.prototype.createCommitWithSignature = function(
708707
throw error;
709708
}
710709
}
711-
});
710+
}
712711

713712
if (!updateRef) {
714-
return createCommitPromise;
713+
return createCommitPromise();
715714
}
716715

717-
return createCommitPromise
718-
.then(function(commitOid) {
719-
if (skippedSigning) {
720-
return commitOid;
721-
}
716+
const commitOid = await createCommitPromise();
717+
if (skippedSigning) {
718+
return commitOid;
719+
}
722720

723-
return repo.getCommit(commitOid)
724-
.then(function(commitResult) {
725-
return Reference.updateTerminal(
726-
repo,
727-
updateRef,
728-
commitOid,
729-
getReflogMessageForCommit(commitResult),
730-
committer
731-
);
732-
})
733-
.then(function() {
734-
return commitOid;
735-
});
736-
});
721+
const commitResult = await repo.getCommit(commitOid)
722+
723+
await Reference.updateTerminal(
724+
repo,
725+
updateRef,
726+
commitOid,
727+
getReflogMessageForCommit(commitResult),
728+
committer
729+
);
730+
731+
return commitOid;
737732
};
738733

739734
/**

0 commit comments

Comments
 (0)