X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fgit.git;a=blobdiff_plain;f=sequencer.c;h=8952cfa89b996f27a503be28c636643b732d5886;hp=5670bd7e7ab9f6fd5b88b24bdc683b09577e9efe;hb=14b58c62bcd60b7b5bfbb895eb869f7d1d64a9b7;hpb=280bd445515acffb83231dfee79c21719ad3bc7b diff --git a/sequencer.c b/sequencer.c index 5670bd7e7a..8952cfa89b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1126,25 +1126,22 @@ static int run_prepare_commit_msg_hook(struct repository *r, struct strbuf *msg, const char *commit) { - struct argv_array hook_env = ARGV_ARRAY_INIT; - int ret; - const char *name; + int ret = 0; + const char *name, *arg1 = NULL, *arg2 = NULL; name = git_path_commit_editmsg(); if (write_message(msg->buf, msg->len, name, 0)) return -1; - argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", r->index_file); - argv_array_push(&hook_env, "GIT_EDITOR=:"); - if (commit) - ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name, - "commit", commit, NULL); - else - ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name, - "message", NULL); - if (ret) + if (commit) { + arg1 = "commit"; + arg2 = commit; + } else { + arg1 = "message"; + } + if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name, + arg1, arg2, NULL)) ret = error(_("'prepare-commit-msg' hook failed")); - argv_array_clear(&hook_env); return ret; } @@ -1403,6 +1400,7 @@ static int try_to_commit(struct repository *r, goto out; } + run_commit_hook(0, r->index_file, "post-commit", NULL); if (flags & AMEND_MSG) commit_post_rewrite(r, current_head, oid); @@ -4397,9 +4395,14 @@ struct labels_entry { char label[FLEX_ARRAY]; }; -static int labels_cmp(const void *fndata, const struct labels_entry *a, - const struct labels_entry *b, const void *key) +static int labels_cmp(const void *fndata, const struct hashmap_entry *eptr, + const struct hashmap_entry *entry_or_key, const void *key) { + const struct labels_entry *a, *b; + + a = container_of(eptr, const struct labels_entry, entry); + b = container_of(entry_or_key, const struct labels_entry, entry); + return key ? strcmp(a->label, key) : strcmp(a->label, b->label); } @@ -4495,8 +4498,8 @@ static const char *label_oid(struct object_id *oid, const char *label, } FLEX_ALLOC_STR(labels_entry, label, label); - hashmap_entry_init(labels_entry, strihash(label)); - hashmap_add(&state->labels, labels_entry); + hashmap_entry_init(&labels_entry->entry, strihash(label)); + hashmap_add(&state->labels, &labels_entry->entry); FLEX_ALLOC_STR(string_entry, string, label); oidcpy(&string_entry->entry.oid, oid); @@ -4531,7 +4534,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, oidmap_init(&commit2todo, 0); oidmap_init(&state.commit2label, 0); - hashmap_init(&state.labels, (hashmap_cmp_fn) labels_cmp, NULL, 0); + hashmap_init(&state.labels, labels_cmp, NULL, 0); strbuf_init(&state.buf, 32); if (revs->cmdline.nr && (revs->cmdline.rev[0].flags & BOTTOM)) { @@ -4726,7 +4729,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, oidmap_free(&commit2todo, 1); oidmap_free(&state.commit2label, 1); - hashmap_free(&state.labels, 1); + hashmap_free_entries(&state.labels, struct labels_entry, entry); strbuf_release(&state.buf); return 0; @@ -5097,9 +5100,15 @@ struct subject2item_entry { }; static int subject2item_cmp(const void *fndata, - const struct subject2item_entry *a, - const struct subject2item_entry *b, const void *key) + const struct hashmap_entry *eptr, + const struct hashmap_entry *entry_or_key, + const void *key) { + const struct subject2item_entry *a, *b; + + a = container_of(eptr, const struct subject2item_entry, entry); + b = container_of(entry_or_key, const struct subject2item_entry, entry); + return key ? strcmp(a->subject, key) : strcmp(a->subject, b->subject); } @@ -5132,8 +5141,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) * In that case, last[i] will indicate the index of the latest item to * be moved to appear after the i'th. */ - hashmap_init(&subject2item, (hashmap_cmp_fn) subject2item_cmp, - NULL, todo_list->nr); + hashmap_init(&subject2item, subject2item_cmp, NULL, todo_list->nr); ALLOC_ARRAY(next, todo_list->nr); ALLOC_ARRAY(tail, todo_list->nr); ALLOC_ARRAY(subjects, todo_list->nr); @@ -5176,8 +5184,11 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) break; } - if ((entry = hashmap_get_from_hash(&subject2item, - strhash(p), p))) + entry = hashmap_get_entry_from_hash(&subject2item, + strhash(p), p, + struct subject2item_entry, + entry); + if (entry) /* found by title */ i2 = entry->i; else if (!strchr(p, ' ') && @@ -5211,8 +5222,9 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) strhash(subject), subject)) { FLEX_ALLOC_MEM(entry, subject, subject, subject_len); entry->i = i; - hashmap_entry_init(entry, strhash(entry->subject)); - hashmap_put(&subject2item, entry); + hashmap_entry_init(&entry->entry, + strhash(entry->subject)); + hashmap_put(&subject2item, &entry->entry); } } @@ -5246,7 +5258,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) for (i = 0; i < todo_list->nr; i++) free(subjects[i]); free(subjects); - hashmap_free(&subject2item, 1); + hashmap_free_entries(&subject2item, struct subject2item_entry, entry); clear_commit_todo_item(&commit_todo);