From 5c25dfaa794c7bbfa1b4d234b10f94ee371b1db0 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Thu, 12 Sep 2013 12:50:04 +0200 Subject: commit: factor status configuration is a helper function cmd_commit and cmd_status use very similar code to initialize the wt_status structure. Factor this code into a function to ensure future changes will keep both versions consistent. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- builtin/commit.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'builtin') diff --git a/builtin/commit.c b/builtin/commit.c index 10acc53f8..94512c05b 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -163,6 +163,14 @@ static void determine_whence(struct wt_status *s) s->whence = whence; } +static void status_init_config(struct wt_status *s, config_fn_t fn) +{ + wt_status_prepare(s); + gitmodules_config(); + git_config(fn, s); + determine_whence(s); +} + static void rollback_index_files(void) { switch (commit_style) { @@ -1246,10 +1254,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(builtin_status_usage, builtin_status_options); - wt_status_prepare(&s); - gitmodules_config(); - git_config(git_status_config, &s); - determine_whence(&s); + status_init_config(&s, git_status_config); argc = parse_options(argc, argv, prefix, builtin_status_options, builtin_status_usage, 0); @@ -1492,11 +1497,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(builtin_commit_usage, builtin_commit_options); - wt_status_prepare(&s); - gitmodules_config(); - git_config(git_commit_config, &s); + status_init_config(&s, git_commit_config); status_format = STATUS_FORMAT_NONE; /* Ignore status.short */ - determine_whence(&s); s.colopts = 0; if (get_sha1("HEAD", sha1)) -- cgit v1.2.1 From 6a964f57e52bb25d9233ff6d38c82a16f21f60aa Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Thu, 12 Sep 2013 12:50:05 +0200 Subject: wt-status: turn advice_status_hints into a field of wt_status No behavior change in this patch, but this makes the display of status hints more flexible as they can be enabled or disabled for individual calls to commit.c:run_status(). Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- builtin/commit.c | 1 + 1 file changed, 1 insertion(+) (limited to 'builtin') diff --git a/builtin/commit.c b/builtin/commit.c index 94512c05b..28c6309d4 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -169,6 +169,7 @@ static void status_init_config(struct wt_status *s, config_fn_t fn) gitmodules_config(); git_config(fn, s); determine_whence(s); + s->hints = advice_status_hints; /* must come after git_config() */ } static void rollback_index_files(void) -- cgit v1.2.1 From ea9882bfc4d2850b65eac29ac5152e0d778a744b Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Thu, 12 Sep 2013 12:50:06 +0200 Subject: commit: disable status hints when writing to COMMIT_EDITMSG This turns the template COMMIT_EDITMSG from e.g # [...] # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: builtin/commit.c # # Untracked files: # (use "git add ..." to include in what will be committed) # # t/foo # to # [...] # Changes to be committed: # modified: builtin/commit.c # # Untracked files: # t/foo # Most status hints were written to be accurate when running "git status" before running a commit. Many of them are not applicable when the commit has already been started, and should not be shown in COMMIT_EDITMSG. The most obvious are hints advising to run "git commit", "git rebase/am/cherry-pick --continue", which do not make sense when the command has already been run. Other messages become slightly inaccurate (e.g. hint to use "git add" to add untracked files), as the suggested commands are not immediately applicable during the editing of COMMIT_EDITMSG, but would be applicable if the commit is aborted. These messages are both potentially helpful and slightly misleading. This patch chose to remove them too, to avoid introducing too much complexity in the status code. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- builtin/commit.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'builtin') diff --git a/builtin/commit.c b/builtin/commit.c index 28c6309d4..321462a43 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -705,6 +705,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (s->fp == NULL) die_errno(_("could not open '%s'"), git_path(commit_editmsg)); + /* + * Most hints are counter-productive when the commit has + * already started. + */ + s->hints = 0; + if (clean_message_contents) stripspace(&sb, 0); -- cgit v1.2.1