{"thread":{"id":"34917","subject":"[PATCH v2 2/3] wt-status: turn advice_status_hints into a field of wt_status","startedAt":"2013-09-12T10:50:04Z","lastAt":"2013-09-12T10:50:06Z","messageCount":3,"participants":["Matthieu Moy"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"227529","messageId":"1378983006-3980-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"34917","inReplyTo":null,"subject":"[PATCH v2 1/3] commit: factor status configuration is a helper function","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2013-09-12T10:50:04Z","receivedAt":"2013-09-12T10:50:04Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"cmd_commit and cmd_status use very similar code to initialize the\nwt_status structure. Factor this code into a function to ensure future\nchanges will keep both versions consistent.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\nNew patch, as discussed with Peff.\n\n builtin/commit.c | 18 ++++++++++--------\n 1 file changed, 10 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 60812b5..dc957a9 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -163,6 +163,14 @@ static void determine_whence(struct wt_status *s)\n \t\ts->whence = whence;\n }\n \n+static void status_init_config(struct wt_status *s, config_fn_t fn)\n+{\n+\twt_status_prepare(s);\n+\tgitmodules_config();\n+\tgit_config(fn, s);\n+\tdetermine_whence(s);\n+}\n+\n static void rollback_index_files(void)\n {\n \tswitch (commit_style) {\n@@ -1246,10 +1254,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage_with_options(builtin_status_usage, builtin_status_options);\n \n-\twt_status_prepare(&s);\n-\tgitmodules_config();\n-\tgit_config(git_status_config, &s);\n-\tdetermine_whence(&s);\n+\tstatus_init_config(&s, git_status_config);\n \targc = parse_options(argc, argv, prefix,\n \t\t\t     builtin_status_options,\n \t\t\t     builtin_status_usage, 0);\n@@ -1490,11 +1495,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage_with_options(builtin_commit_usage, builtin_commit_options);\n \n-\twt_status_prepare(&s);\n-\tgitmodules_config();\n-\tgit_config(git_commit_config, &s);\n+\tstatus_init_config(&s, git_commit_config);\n \tstatus_format = STATUS_FORMAT_NONE; /* Ignore status.short */\n-\tdetermine_whence(&s);\n \ts.colopts = 0;\n \n \tif (get_sha1(\"HEAD\", sha1))\n-- \n1.8.4.8.g834017f\n"},{"id":"227527","messageId":"1378983006-3980-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"34917","inReplyTo":"1378983006-3980-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH v2 2/3] wt-status: turn advice_status_hints into a field of wt_status","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2013-09-12T10:50:05Z","receivedAt":"2013-09-12T10:50:05Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"No behavior change in this patch, but this makes the display of status\nhints more flexible as they can be enabled or disabled for individual\ncalls to commit.c:run_status().\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\nNo real change since v1, just a slight adaptation after the PATCH 1.\n\n builtin/commit.c |  1 +\n wt-status.c      | 38 +++++++++++++++++++-------------------\n wt-status.h      |  1 +\n 3 files changed, 21 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex dc957a9..7bfce94 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -169,6 +169,7 @@ static void status_init_config(struct wt_status *s, config_fn_t fn)\n \tgitmodules_config();\n \tgit_config(fn, s);\n \tdetermine_whence(s);\n+\ts->hints = advice_status_hints; /* must come after git_config() */\n }\n \n static void rollback_index_files(void)\ndiff --git a/wt-status.c b/wt-status.c\nindex cb24f1f..885ee66 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -160,7 +160,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s)\n \t\t}\n \t}\n \n-\tif (!advice_status_hints)\n+\tif (!s->hints)\n \t\treturn;\n \tif (s->whence != FROM_COMMIT)\n \t\t;\n@@ -187,7 +187,7 @@ static void wt_status_print_cached_header(struct wt_status *s)\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n \tstatus_printf_ln(s, c, _(\"Changes to be committed:\"));\n-\tif (!advice_status_hints)\n+\tif (!s->hints)\n \t\treturn;\n \tif (s->whence != FROM_COMMIT)\n \t\t; /* NEEDSWORK: use \"git reset --unresolve\"??? */\n@@ -205,7 +205,7 @@ static void wt_status_print_dirty_header(struct wt_status *s,\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n \tstatus_printf_ln(s, c, _(\"Changes not staged for commit:\"));\n-\tif (!advice_status_hints)\n+\tif (!s->hints)\n \t\treturn;\n \tif (!has_deleted)\n \t\tstatus_printf_ln(s, c, _(\"  (use \\\"git add <file>...\\\" to update what will be committed)\"));\n@@ -223,7 +223,7 @@ static void wt_status_print_other_header(struct wt_status *s,\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \tstatus_printf_ln(s, c, \"%s:\", what);\n-\tif (!advice_status_hints)\n+\tif (!s->hints)\n \t\treturn;\n \tstatus_printf_ln(s, c, _(\"  (use \\\"git %s <file>...\\\" to include in what will be committed)\"), how);\n \tstatus_printf_ln(s, c, \"\");\n@@ -801,13 +801,13 @@ static void show_merge_in_progress(struct wt_status *s,\n {\n \tif (has_unmerged(s)) {\n \t\tstatus_printf_ln(s, color, _(\"You have unmerged paths.\"));\n-\t\tif (advice_status_hints)\n+\t\tif (s->hints)\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (fix conflicts and run \\\"git commit\\\")\"));\n \t} else {\n \t\tstatus_printf_ln(s, color,\n \t\t\t_(\"All conflicts fixed but you are still merging.\"));\n-\t\tif (advice_status_hints)\n+\t\tif (s->hints)\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (use \\\"git commit\\\" to conclude merge)\"));\n \t}\n@@ -823,7 +823,7 @@ static void show_am_in_progress(struct wt_status *s,\n \tif (state->am_empty_patch)\n \t\tstatus_printf_ln(s, color,\n \t\t\t_(\"The current patch is empty.\"));\n-\tif (advice_status_hints) {\n+\tif (s->hints) {\n \t\tif (!state->am_empty_patch)\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (fix conflicts and then run \\\"git am --continue\\\")\"));\n@@ -896,7 +896,7 @@ static void show_rebase_in_progress(struct wt_status *s,\n \t\telse\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t\t _(\"You are currently rebasing.\"));\n-\t\tif (advice_status_hints) {\n+\t\tif (s->hints) {\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (fix conflicts and then run \\\"git rebase --continue\\\")\"));\n \t\t\tstatus_printf_ln(s, color,\n@@ -913,7 +913,7 @@ static void show_rebase_in_progress(struct wt_status *s,\n \t\telse\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t\t _(\"You are currently rebasing.\"));\n-\t\tif (advice_status_hints)\n+\t\tif (s->hints)\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (all conflicts fixed: run \\\"git rebase --continue\\\")\"));\n \t} else if (split_commit_in_progress(s)) {\n@@ -925,7 +925,7 @@ static void show_rebase_in_progress(struct wt_status *s,\n \t\telse\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t\t _(\"You are currently splitting a commit during a rebase.\"));\n-\t\tif (advice_status_hints)\n+\t\tif (s->hints)\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (Once your working directory is clean, run \\\"git rebase --continue\\\")\"));\n \t} else {\n@@ -937,7 +937,7 @@ static void show_rebase_in_progress(struct wt_status *s,\n \t\telse\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t\t _(\"You are currently editing a commit during a rebase.\"));\n-\t\tif (advice_status_hints && !s->amend) {\n+\t\tif (s->hints && !s->amend) {\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (use \\\"git commit --amend\\\" to amend the current commit)\"));\n \t\t\tstatus_printf_ln(s, color,\n@@ -952,7 +952,7 @@ static void show_cherry_pick_in_progress(struct wt_status *s,\n \t\t\t\t\tconst char *color)\n {\n \tstatus_printf_ln(s, color, _(\"You are currently cherry-picking.\"));\n-\tif (advice_status_hints) {\n+\tif (s->hints) {\n \t\tif (has_unmerged(s))\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (fix conflicts and run \\\"git cherry-pick --continue\\\")\"));\n@@ -971,7 +971,7 @@ static void show_revert_in_progress(struct wt_status *s,\n {\n \tstatus_printf_ln(s, color, _(\"You are currently reverting commit %s.\"),\n \t\t\t find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));\n-\tif (advice_status_hints) {\n+\tif (s->hints) {\n \t\tif (has_unmerged(s))\n \t\t\tstatus_printf_ln(s, color,\n \t\t\t\t_(\"  (fix conflicts and run \\\"git revert --continue\\\")\"));\n@@ -995,7 +995,7 @@ static void show_bisect_in_progress(struct wt_status *s,\n \telse\n \t\tstatus_printf_ln(s, color,\n \t\t\t\t _(\"You are currently bisecting.\"));\n-\tif (advice_status_hints)\n+\tif (s->hints)\n \t\tstatus_printf_ln(s, color,\n \t\t\t_(\"  (use \\\"git bisect reset\\\" to get back to the original branch)\"));\n \twt_status_print_trailer(s);\n@@ -1233,7 +1233,7 @@ void wt_status_print(struct wt_status *s)\n \t\t}\n \t} else if (s->commitable)\n \t\tstatus_printf_ln(s, GIT_COLOR_NORMAL, _(\"Untracked files not listed%s\"),\n-\t\t\tadvice_status_hints\n+\t\t\ts->hints\n \t\t\t? _(\" (use -u option to show untracked files)\") : \"\");\n \n \tif (s->verbose)\n@@ -1244,25 +1244,25 @@ void wt_status_print(struct wt_status *s)\n \t\telse if (s->nowarn)\n \t\t\t; /* nothing */\n \t\telse if (s->workdir_dirty) {\n-\t\t\tif (advice_status_hints)\n+\t\t\tif (s->hints)\n \t\t\t\tprintf(_(\"no changes added to commit \"\n \t\t\t\t\t \"(use \\\"git add\\\" and/or \\\"git commit -a\\\")\\n\"));\n \t\t\telse\n \t\t\t\tprintf(_(\"no changes added to commit\\n\"));\n \t\t} else if (s->untracked.nr) {\n-\t\t\tif (advice_status_hints)\n+\t\t\tif (s->hints)\n \t\t\t\tprintf(_(\"nothing added to commit but untracked files \"\n \t\t\t\t\t \"present (use \\\"git add\\\" to track)\\n\"));\n \t\t\telse\n \t\t\t\tprintf(_(\"nothing added to commit but untracked files present\\n\"));\n \t\t} else if (s->is_initial) {\n-\t\t\tif (advice_status_hints)\n+\t\t\tif (s->hints)\n \t\t\t\tprintf(_(\"nothing to commit (create/copy files \"\n \t\t\t\t\t \"and use \\\"git add\\\" to track)\\n\"));\n \t\t\telse\n \t\t\t\tprintf(_(\"nothing to commit\\n\"));\n \t\t} else if (!s->show_untracked_files) {\n-\t\t\tif (advice_status_hints)\n+\t\t\tif (s->hints)\n \t\t\t\tprintf(_(\"nothing to commit (use -u to show untracked files)\\n\"));\n \t\t\telse\n \t\t\t\tprintf(_(\"nothing to commit\\n\"));\ndiff --git a/wt-status.h b/wt-status.h\nindex fb7152e..b4c9cb4 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -59,6 +59,7 @@ struct wt_status {\n \tunsigned colopts;\n \tint null_termination;\n \tint show_branch;\n+\tint hints;\n \n \t/* These are computed during processing of the individual sections */\n \tint commitable;\n-- \n1.8.4.8.g834017f\n"},{"id":"227528","messageId":"1378983006-3980-3-git-send-email-Matthieu.Moy@imag.fr","threadId":"34917","inReplyTo":"1378983006-3980-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH v2 3/3] commit: disable status hints when writing to COMMIT_EDITMSG","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2013-09-12T10:50:06Z","receivedAt":"2013-09-12T10:50:06Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"This turns the template COMMIT_EDITMSG from e.g\n\n  # [...]\n  # Changes to be committed:\n  #   (use \"git reset HEAD <file>...\" to unstage)\n  #\n  #\tmodified:   builtin/commit.c\n  #\n  # Untracked files:\n  #   (use \"git add <file>...\" to include in what will be committed)\n  #\n  #\tt/foo\n  #\n\nto\n\n  # [...]\n  # Changes to be committed:\n  #\tmodified:   builtin/commit.c\n  #\n  # Untracked files:\n  #\tt/foo\n  #\n\nMost status hints were written to be accurate when running \"git status\"\nbefore running a commit. Many of them are not applicable when the commit\nhas already been started, and should not be shown in COMMIT_EDITMSG. The\nmost obvious are hints advising to run \"git commit\",\n\"git rebase/am/cherry-pick --continue\", which do not make sense when the\ncommand has already been run.\n\nOther messages become slightly inaccurate (e.g. hint to use \"git add\" to\nadd untracked files), as the suggested commands are not immediately\napplicable during the editing of COMMIT_EDITMSG, but would be applicable\nif the commit is aborted. These messages are both potentially helpful and\nslightly misleading. This patch chose to remove them too, to avoid\nintroducing too much complexity in the status code.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\nUnchanged since v1.\n\n builtin/commit.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 7bfce94..e32246a 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -705,6 +705,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \tif (s->fp == NULL)\n \t\tdie_errno(_(\"could not open '%s'\"), git_path(commit_editmsg));\n \n+\t/*\n+\t * Most hints are counter-productive when the commit has\n+\t * already started.\n+\t */\n+\ts->hints = 0;\n+\n \tif (clean_message_contents)\n \t\tstripspace(&sb, 0);\n \n-- \n1.8.4.8.g834017f\n"}]}