Skip to content

Commit 0a3ab68

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 0a3ab68

File tree

4 files changed

+48
-52
lines changed

4 files changed

+48
-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: 43 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,33 @@ 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(parent);
651+
} else {
652+
newParents.push(await repo.getCommit(parent));
653+
showDeprecationWarning = true;
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 " +
659+
"should be an array of Commits instead an array of Oid|String");
660+
}
659661

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

664-
return Commit.createBuffer(
664+
const createCommitPromise = async () => {
665+
let commitContent = await Commit.createBuffer(
665666
repo,
666667
author,
667668
committer,
@@ -671,13 +672,12 @@ Repository.prototype.createCommitWithSignature = function(
671672
parents.length,
672673
parents
673674
);
674-
}).then(function(commitContentResult) {
675-
commitContent = commitContentResult;
676675
if (!commitContent.endsWith("\n")) {
677676
commitContent += "\n";
678677
}
679-
return onSignature(commitContent);
680-
}).then(function({ code, field, signedData }) {
678+
679+
const { code, field, signedData } = await onSignature(commitContent);
680+
681681
switch (code) {
682682
case NodeGit.Error.CODE.OK:
683683
return Commit.createWithSignature(
@@ -708,32 +708,28 @@ Repository.prototype.createCommitWithSignature = function(
708708
throw error;
709709
}
710710
}
711-
});
711+
};
712712

713713
if (!updateRef) {
714-
return createCommitPromise;
714+
return createCommitPromise();
715715
}
716716

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

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-
});
722+
const commitResult = await repo.getCommit(commitOid);
723+
724+
await Reference.updateTerminal(
725+
repo,
726+
updateRef,
727+
commitOid,
728+
getReflogMessageForCommit(commitResult),
729+
committer
730+
);
731+
732+
return commitOid;
737733
};
738734

739735
/**

0 commit comments

Comments
 (0)