format code

This commit is contained in:
Gerhard Hoffmann 2024-04-05 12:44:34 +02:00
parent a3cbb20a53
commit fe46da5417

View File

@ -388,8 +388,7 @@ static void opts_add_refish(struct merge_options *opts, const char *refish) {
}
}
static int resolve_heads(git_repository *repo, struct merge_options *opts)
{
static int resolve_heads(git_repository *repo, struct merge_options *opts) {
git_annotated_commit **annotated = (git_annotated_commit **)calloc(opts->heads_count, sizeof(git_annotated_commit *));
size_t annotated_count = 0, i;
int err = 0;
@ -414,8 +413,7 @@ static int resolve_heads(git_repository *repo, struct merge_options *opts)
return 0;
}
static int perform_fastforward(git_repository *repo, const git_oid *target_oid, int is_unborn)
{
static int perform_fastforward(git_repository *repo, const git_oid *target_oid, int is_unborn) {
// git_checkout_options ff_checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
git_checkout_options ff_checkout_options;
@ -436,7 +434,7 @@ static int perform_fastforward(git_repository *repo, const git_oid *target_oid,
/* HEAD reference is unborn, lookup manually so we don't try to resolve it */
err = git_reference_lookup(&head_ref, repo, "HEAD");
if (err != 0) {
fprintf(stderr, "failed to lookup HEAD ref\n");
qCritical() << HEADER << "failed to lookup HEAD ref";
return -1;
}
@ -446,7 +444,7 @@ static int perform_fastforward(git_repository *repo, const git_oid *target_oid,
/* Create our master reference on the target OID */
err = git_reference_create(&target_ref, repo, symbolic_ref, target_oid, 0, NULL);
if (err != 0) {
fprintf(stderr, "failed to create master reference\n");
qCritical() << HEADER << "failed to create master reference";
return -1;
}
@ -455,7 +453,7 @@ static int perform_fastforward(git_repository *repo, const git_oid *target_oid,
/* HEAD exists, just lookup and resolve */
err = git_repository_head(&target_ref, repo);
if (err != 0) {
fprintf(stderr, "failed to get HEAD reference\n");
qCritical() << HEADER << "failed to get HEAD reference";
return -1;
}
}
@ -463,7 +461,7 @@ static int perform_fastforward(git_repository *repo, const git_oid *target_oid,
/* Lookup the target object */
err = git_object_lookup(&target, repo, target_oid, GIT_OBJECT_COMMIT);
if (err != 0) {
fprintf(stderr, "failed to lookup OID %s\n", git_oid_tostr_s(target_oid));
qCritical() << HEADER << QString("failed to lookup OID %s").arg(git_oid_tostr_s(target_oid));
return -1;
}
@ -471,14 +469,14 @@ static int perform_fastforward(git_repository *repo, const git_oid *target_oid,
ff_checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
err = git_checkout_tree(repo, target, &ff_checkout_options);
if (err != 0) {
fprintf(stderr, "failed to checkout HEAD reference\n");
qCritical() << HEADER << "failed to checkout HEAD reference";
return -1;
}
/* Move the target reference to the target OID */
err = git_reference_set_target(&new_target_ref, target_ref, target_oid, NULL);
if (err != 0) {
fprintf(stderr, "failed to move HEAD reference\n");
qCritical() << HEADER << "failed to move HEAD reference";
return -1;
}
@ -489,8 +487,7 @@ static int perform_fastforward(git_repository *repo, const git_oid *target_oid,
return 0;
}
static void output_conflicts(git_index *index)
{
static void output_conflicts(git_index *index) {
git_index_conflict_iterator *conflicts;
const git_index_entry *ancestor;
const git_index_entry *our;
@ -500,21 +497,21 @@ static void output_conflicts(git_index *index)
check(git_index_conflict_iterator_new(&conflicts, index), "failed to create conflict iterator", NULL);
while ((err = git_index_conflict_next(&ancestor, &our, &their, conflicts)) == 0) {
fprintf(stderr, "conflict: a:%s o:%s t:%s\n",
ancestor ? ancestor->path : "NULL",
our->path ? our->path : "NULL",
their->path ? their->path : "NULL");
qCritical() << HEADER
<< QString("conflict: a:%s o:%s t:%s")
.arg(ancestor ? ancestor->path : "NULL")
.arg(our->path ? our->path : "NULL")
.arg(their->path ? their->path : "NULL");
}
if (err != GIT_ITEROVER) {
fprintf(stderr, "error iterating conflicts\n");
qCritical() << HEADER << "error iterating conflicts";
}
git_index_conflict_iterator_free(conflicts);
}
static int create_merge_commit(git_repository *repo, git_index *index, struct merge_options *opts)
{
static int create_merge_commit(git_repository *repo, git_index *index, struct merge_options *opts) {
git_oid tree_oid, commit_oid;
git_tree *tree;
git_signature *sign;
@ -522,6 +519,12 @@ static int create_merge_commit(git_repository *repo, git_index *index, struct me
git_annotated_commit *merge_commit;
git_reference *head_ref;
git_commit **parents = (git_commit **)calloc(opts->annotated_count + 1, sizeof(git_commit *));
if (!parents) {
qCritical() << HEADER << 'calloc failed';
return -1;
}
const char *msg_target = NULL;
size_t msglen = 0;
char *msg;
@ -531,7 +534,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, struct me
/* Grab our needed references */
check(git_repository_head(&head_ref, repo), "failed to get repo HEAD", NULL);
if (resolve_refish(&merge_commit, repo, opts->heads[0])) {
fprintf(stderr, "failed to resolve refish %s", opts->heads[0]);
qCritical() << HEADER << QString("failed to resolve refish %s").args(opts->heads[0]);
free(parents);
return -1;
}
@ -552,12 +555,21 @@ static int create_merge_commit(git_repository *repo, git_index *index, struct me
}
msglen = snprintf(NULL, 0, MERGE_COMMIT_MSG, (merge_ref ? "branch" : "commit"), msg_target);
if (msglen > 0) msglen++;
msg = (char *)malloc(msglen);
if (msglen > 0) {
msglen++;
}
if ((msg = (char *)malloc(msglen)) == nullptr) {
qCritical() << HEADER << 'malloc failed';
goto cleanup;
}
err = snprintf(msg, msglen, MERGE_COMMIT_MSG, (merge_ref ? "branch" : "commit"), msg_target);
/* This is only to silence the compiler */
if (err < 0) goto cleanup;
if (err < 0) {
goto cleanup;
}
/* Setup our parent commits */
err = git_reference_peel((git_object **)&parents[0], head_ref, GIT_OBJECT_COMMIT);
@ -577,6 +589,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, struct me
NULL, msg,
tree,
opts->annotated_count + 1, (const git_commit **)parents);
check(err, "failed to create commit", NULL);
/* We're done merging, cleanup the repository state */