at least it compiles

This commit is contained in:
Gerhard Hoffmann 2024-04-05 12:13:27 +02:00
parent 1d119cb63e
commit a3cbb20a53

View File

@ -378,52 +378,60 @@ static void parse_options(const char **repo_path, struct merge_options *opts) {
}
static void opts_add_refish(struct merge_options *opts, const char *refish) {
size_t sz;
size_t sz;
assert(opts != NULL);
assert(opts != NULL);
sz = ++opts->heads_count * sizeof(opts->heads[0]);
opts->heads = xrealloc((void *) opts->heads, sz);
opts->heads[opts->heads_count - 1] = refish;
sz = ++opts->heads_count * sizeof(opts->heads[0]);
if ((opts->heads = (const char **)realloc((void *) opts->heads, sz)) != 0) {
opts->heads[opts->heads_count - 1] = refish;
}
}
static int resolve_heads(git_repository *repo, struct merge_options *opts)
{
git_annotated_commit **annotated = calloc(opts->heads_count, sizeof(git_annotated_commit *));
size_t annotated_count = 0, i;
int err = 0;
git_annotated_commit **annotated = (git_annotated_commit **)calloc(opts->heads_count, sizeof(git_annotated_commit *));
size_t annotated_count = 0, i;
int err = 0;
for (i = 0; i < opts->heads_count; i++) {
err = resolve_refish(&annotated[annotated_count++], repo, opts->heads[i]);
if (err != 0) {
fprintf(stderr, "failed to resolve refish %s: %s\n", opts->heads[i], git_error_last()->message);
annotated_count--;
continue;
for (i = 0; i < opts->heads_count; i++) {
err = resolve_refish(&annotated[annotated_count++], repo, opts->heads[i]);
if (err != 0) {
fprintf(stderr, "failed to resolve refish %s: %s\n", opts->heads[i], git_error_last()->message);
annotated_count--;
continue;
}
}
}
if (annotated_count != opts->heads_count) {
fprintf(stderr, "unable to parse some refish\n");
free(annotated);
return -1;
}
if (annotated_count != opts->heads_count) {
fprintf(stderr, "unable to parse some refish\n");
free(annotated);
return -1;
}
opts->annotated = annotated;
opts->annotated_count = annotated_count;
return 0;
opts->annotated = annotated;
opts->annotated_count = annotated_count;
return 0;
}
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_reference *target_ref;
git_reference *new_target_ref;
git_object *target = NULL;
int err = 0;
// git_checkout_options ff_checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
git_checkout_options ff_checkout_options;
if (is_unborn) {
const char *symbolic_ref;
git_reference *head_ref;
// #define GIT_CHECKOUT_OPTIONS_INIT {GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE}
git_checkout_options_init(&ff_checkout_options, GIT_CHECKOUT_OPTIONS_VERSION);
ff_checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
git_reference *target_ref;
git_reference *new_target_ref;
git_object *target = NULL;
int err = 0;
if (is_unborn) {
const char *symbolic_ref;
git_reference *head_ref;
/* HEAD reference is unborn, lookup manually so we don't try to resolve it */
err = git_reference_lookup(&head_ref, repo, "HEAD");
@ -513,7 +521,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, struct me
git_reference *merge_ref = NULL;
git_annotated_commit *merge_commit;
git_reference *head_ref;
git_commit **parents = calloc(opts->annotated_count + 1, sizeof(git_commit *));
git_commit **parents = (git_commit **)calloc(opts->annotated_count + 1, sizeof(git_commit *));
const char *msg_target = NULL;
size_t msglen = 0;
char *msg;
@ -545,7 +553,7 @@ 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 = malloc(msglen);
msg = (char *)malloc(msglen);
err = snprintf(msg, msglen, MERGE_COMMIT_MSG, (merge_ref ? "branch" : "commit"), msg_target);
/* This is only to silence the compiler */
@ -568,7 +576,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, struct me
sign, sign,
NULL, msg,
tree,
opts->annotated_count + 1, parents);
opts->annotated_count + 1, (const git_commit **)parents);
check(err, "failed to create commit", NULL);
/* We're done merging, cleanup the repository state */
@ -591,7 +599,7 @@ static int merge(git_repository *repo) {
merge_options_init(&opts);
parse_options(&path, &opts);
state = git_repository_state(repo);
state = (git_repository_state_t)git_repository_state(repo);
if (state != GIT_REPOSITORY_STATE_NONE) {
fprintf(stderr, "repository is in unexpected state %d\n", state);
goto cleanup;
@ -626,8 +634,21 @@ static int merge(git_repository *repo) {
return perform_fastforward(repo, target_oid, (analysis & GIT_MERGE_ANALYSIS_UNBORN));
} else if (analysis & GIT_MERGE_ANALYSIS_NORMAL) {
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
//git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_merge_options merge_opts;
git_merge_options_init(&merge_opts, GIT_MERGE_OPTIONS_VERSION);
// TODO: check this...
// merge_opts.file_flags = GIT_MERGE_FIND_RENAMES;
// GIT_MERGE_OPTIONS_VERSION, GIT_MERGE_FIND_RENAMES }
//git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_checkout_options checkout_opts;
git_checkout_options_init(&checkout_opts, GIT_CHECKOUT_OPTIONS_VERSION);
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
merge_opts.flags = 0;
merge_opts.file_flags = GIT_MERGE_FILE_STYLE_DIFF3;