From: Junio C Hamano Date: Tue, 8 Apr 2014 19:07:06 +0000 (-0700) Subject: Merge branch 'bp/commit-p-editor' into maint X-Git-Tag: v1.9.2~9 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/86b4c1639c4a44fa8c10a7c438c5af24ca87e2a9?ds=inline;hp=-c Merge branch 'bp/commit-p-editor' into maint * bp/commit-p-editor: run-command: mark run_hook_with_custom_index as deprecated merge hook tests: fix and update tests merge: fix GIT_EDITOR override for commit hook commit: fix patch hunk editing with "commit -p -m" test patch hunk editing with "commit -p -m" merge hook tests: use 'test_must_fail' instead of '!' merge hook tests: fix missing '&&' in test --- 86b4c1639c4a44fa8c10a7c438c5af24ca87e2a9 diff --combined builtin/checkout.c index ada51fa70f,624bfbad7c..1b86d9c868 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -53,10 -53,10 +53,10 @@@ struct checkout_opts static int post_checkout_hook(struct commit *old, struct commit *new, int changed) { - return run_hook(NULL, "post-checkout", - sha1_to_hex(old ? old->object.sha1 : null_sha1), - sha1_to_hex(new ? new->object.sha1 : null_sha1), - changed ? "1" : "0", NULL); + return run_hook_le(NULL, "post-checkout", + sha1_to_hex(old ? old->object.sha1 : null_sha1), + sha1_to_hex(new ? new->object.sha1 : null_sha1), + changed ? "1" : "0", NULL); /* "new" can be NULL when checking out from the index before a commit exists. */ @@@ -297,7 -297,8 +297,7 @@@ static int checkout_paths(const struct * match_pathspec() for _all_ entries when * opts->source_tree != NULL. */ - if (match_pathspec_depth(&opts->pathspec, ce->name, ce_namelen(ce), - 0, ps_matched)) + if (ce_path_match(ce, &opts->pathspec, ps_matched)) ce->ce_flags |= CE_MATCHED; } diff --combined builtin/commit.c index 26b2986abe,baf1fc0fff..6a60f668b2 --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -234,7 -234,7 +234,7 @@@ static int list_paths(struct string_lis if (ce->ce_flags & CE_UPDATE) continue; - if (!match_pathspec_depth(pattern, ce->name, ce_namelen(ce), 0, m)) + if (!ce_path_match(ce, pattern, m)) continue; item = string_list_insert(list, ce->name); if (ce_skip_worktree(ce)) @@@ -612,7 -612,7 +612,7 @@@ static int prepare_to_commit(const cha /* This checks and barfs if author is badly specified */ determine_author_info(author_ident); - if (!no_verify && run_hook(index_file, "pre-commit", NULL)) + if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL)) return 0; if (squash_message) { @@@ -866,8 -866,8 +866,8 @@@ return 0; } - if (run_hook(index_file, "prepare-commit-msg", - git_path(commit_editmsg), hook_arg1, hook_arg2, NULL)) + if (run_commit_hook(use_editor, index_file, "prepare-commit-msg", + git_path(commit_editmsg), hook_arg1, hook_arg2, NULL)) return 0; if (use_editor) { @@@ -883,7 -883,7 +883,7 @@@ } if (!no_verify && - run_hook(index_file, "commit-msg", git_path(commit_editmsg), NULL)) { + run_commit_hook(use_editor, index_file, "commit-msg", git_path(commit_editmsg), NULL)) { return 0; } @@@ -1067,8 -1067,6 +1067,6 @@@ static int parse_and_validate_options(i use_editor = 0; if (0 <= edit_flag) use_editor = edit_flag; - if (!use_editor) - setenv("GIT_EDITOR", ":", 1); /* Sanity check options */ if (amend && !current_head) @@@ -1445,6 -1443,29 +1443,29 @@@ static int run_rewrite_hook(const unsig return finish_command(&proc); } + int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...) + { + const char *hook_env[3] = { NULL }; + char index[PATH_MAX]; + va_list args; + int ret; + + snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); + hook_env[0] = index; + + /* + * Let the hook know that no editor will be launched. + */ + if (!editor_is_used) + hook_env[1] = "GIT_EDITOR=:"; + + va_start(args, name); + ret = run_hook_ve(hook_env, name, args); + va_end(args); + + return ret; + } + int cmd_commit(int argc, const char **argv, const char *prefix) { static struct wt_status s; @@@ -1669,7 -1690,7 +1690,7 @@@ "not exceeded, and then \"git reset HEAD\" to recover.")); rerere(0); - run_hook(get_index_file(), "post-commit", NULL); + run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); if (amend && !no_post_rewrite) { struct notes_rewrite_cfg *cfg; cfg = init_copy_notes_for_rewrite("amend"); diff --combined commit.h index 55631f191f,8d97a5caa3..a9f177ba48 --- a/commit.h +++ b/commit.h @@@ -209,7 -209,7 +209,7 @@@ extern int write_shallow_commits(struc extern void setup_alternate_shallow(struct lock_file *shallow_lock, const char **alternate_shallow_file, const struct sha1_array *extra); -extern char *setup_temporary_shallow(const struct sha1_array *extra); +extern const char *setup_temporary_shallow(const struct sha1_array *extra); extern void advertise_shallow_grafts(int); struct shallow_info { @@@ -304,4 -304,7 +304,7 @@@ extern void check_commit_signature(cons int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused); + LAST_ARG_MUST_BE_NULL + extern int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...); + #endif /* COMMIT_H */