* [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status
@ 2013-09-11 9:08 Matthieu Moy
2013-09-11 9:08 ` [PATCH 2/2] commit: disable status hints when writing to COMMIT_EDITMSG Matthieu Moy
2013-09-11 18:35 ` [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status Jeff King
0 siblings, 2 replies; 6+ messages in thread
From: Matthieu Moy @ 2013-09-11 9:08 UTC (permalink / raw)
To: git, gitster; +Cc: javierdo1, jrnieder, judge.packham, Matthieu Moy
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 <Matthieu.Moy@imag.fr>
---
builtin/commit.c | 10 ++++++++--
wt-status.c | 38 +++++++++++++++++++-------------------
wt-status.h | 1 +
3 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 60812b5..388acde 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -163,6 +163,12 @@ static void determine_whence(struct wt_status *s)
s->whence = whence;
}
+static void status_finalize(struct wt_status *s)
+{
+ determine_whence(s);
+ s->hints = advice_status_hints;
+}
+
static void rollback_index_files(void)
{
switch (commit_style) {
@@ -1249,7 +1255,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
wt_status_prepare(&s);
gitmodules_config();
git_config(git_status_config, &s);
- determine_whence(&s);
+ status_finalize(&s);
argc = parse_options(argc, argv, prefix,
builtin_status_options,
builtin_status_usage, 0);
@@ -1494,7 +1500,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
gitmodules_config();
git_config(git_commit_config, &s);
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
- determine_whence(&s);
+ status_finalize(&s);
s.colopts = 0;
if (get_sha1("HEAD", sha1))
diff --git a/wt-status.c b/wt-status.c
index cb24f1f..885ee66 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -160,7 +160,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
}
}
- if (!advice_status_hints)
+ if (!s->hints)
return;
if (s->whence != FROM_COMMIT)
;
@@ -187,7 +187,7 @@ static void wt_status_print_cached_header(struct wt_status *s)
const char *c = color(WT_STATUS_HEADER, s);
status_printf_ln(s, c, _("Changes to be committed:"));
- if (!advice_status_hints)
+ if (!s->hints)
return;
if (s->whence != FROM_COMMIT)
; /* NEEDSWORK: use "git reset --unresolve"??? */
@@ -205,7 +205,7 @@ static void wt_status_print_dirty_header(struct wt_status *s,
const char *c = color(WT_STATUS_HEADER, s);
status_printf_ln(s, c, _("Changes not staged for commit:"));
- if (!advice_status_hints)
+ if (!s->hints)
return;
if (!has_deleted)
status_printf_ln(s, c, _(" (use \"git add <file>...\" to update what will be committed)"));
@@ -223,7 +223,7 @@ static void wt_status_print_other_header(struct wt_status *s,
{
const char *c = color(WT_STATUS_HEADER, s);
status_printf_ln(s, c, "%s:", what);
- if (!advice_status_hints)
+ if (!s->hints)
return;
status_printf_ln(s, c, _(" (use \"git %s <file>...\" to include in what will be committed)"), how);
status_printf_ln(s, c, "");
@@ -801,13 +801,13 @@ static void show_merge_in_progress(struct wt_status *s,
{
if (has_unmerged(s)) {
status_printf_ln(s, color, _("You have unmerged paths."));
- if (advice_status_hints)
+ if (s->hints)
status_printf_ln(s, color,
_(" (fix conflicts and run \"git commit\")"));
} else {
status_printf_ln(s, color,
_("All conflicts fixed but you are still merging."));
- if (advice_status_hints)
+ if (s->hints)
status_printf_ln(s, color,
_(" (use \"git commit\" to conclude merge)"));
}
@@ -823,7 +823,7 @@ static void show_am_in_progress(struct wt_status *s,
if (state->am_empty_patch)
status_printf_ln(s, color,
_("The current patch is empty."));
- if (advice_status_hints) {
+ if (s->hints) {
if (!state->am_empty_patch)
status_printf_ln(s, color,
_(" (fix conflicts and then run \"git am --continue\")"));
@@ -896,7 +896,7 @@ static void show_rebase_in_progress(struct wt_status *s,
else
status_printf_ln(s, color,
_("You are currently rebasing."));
- if (advice_status_hints) {
+ if (s->hints) {
status_printf_ln(s, color,
_(" (fix conflicts and then run \"git rebase --continue\")"));
status_printf_ln(s, color,
@@ -913,7 +913,7 @@ static void show_rebase_in_progress(struct wt_status *s,
else
status_printf_ln(s, color,
_("You are currently rebasing."));
- if (advice_status_hints)
+ if (s->hints)
status_printf_ln(s, color,
_(" (all conflicts fixed: run \"git rebase --continue\")"));
} else if (split_commit_in_progress(s)) {
@@ -925,7 +925,7 @@ static void show_rebase_in_progress(struct wt_status *s,
else
status_printf_ln(s, color,
_("You are currently splitting a commit during a rebase."));
- if (advice_status_hints)
+ if (s->hints)
status_printf_ln(s, color,
_(" (Once your working directory is clean, run \"git rebase --continue\")"));
} else {
@@ -937,7 +937,7 @@ static void show_rebase_in_progress(struct wt_status *s,
else
status_printf_ln(s, color,
_("You are currently editing a commit during a rebase."));
- if (advice_status_hints && !s->amend) {
+ if (s->hints && !s->amend) {
status_printf_ln(s, color,
_(" (use \"git commit --amend\" to amend the current commit)"));
status_printf_ln(s, color,
@@ -952,7 +952,7 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
const char *color)
{
status_printf_ln(s, color, _("You are currently cherry-picking."));
- if (advice_status_hints) {
+ if (s->hints) {
if (has_unmerged(s))
status_printf_ln(s, color,
_(" (fix conflicts and run \"git cherry-pick --continue\")"));
@@ -971,7 +971,7 @@ static void show_revert_in_progress(struct wt_status *s,
{
status_printf_ln(s, color, _("You are currently reverting commit %s."),
find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));
- if (advice_status_hints) {
+ if (s->hints) {
if (has_unmerged(s))
status_printf_ln(s, color,
_(" (fix conflicts and run \"git revert --continue\")"));
@@ -995,7 +995,7 @@ static void show_bisect_in_progress(struct wt_status *s,
else
status_printf_ln(s, color,
_("You are currently bisecting."));
- if (advice_status_hints)
+ if (s->hints)
status_printf_ln(s, color,
_(" (use \"git bisect reset\" to get back to the original branch)"));
wt_status_print_trailer(s);
@@ -1233,7 +1233,7 @@ void wt_status_print(struct wt_status *s)
}
} else if (s->commitable)
status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"),
- advice_status_hints
+ s->hints
? _(" (use -u option to show untracked files)") : "");
if (s->verbose)
@@ -1244,25 +1244,25 @@ void wt_status_print(struct wt_status *s)
else if (s->nowarn)
; /* nothing */
else if (s->workdir_dirty) {
- if (advice_status_hints)
+ if (s->hints)
printf(_("no changes added to commit "
"(use \"git add\" and/or \"git commit -a\")\n"));
else
printf(_("no changes added to commit\n"));
} else if (s->untracked.nr) {
- if (advice_status_hints)
+ if (s->hints)
printf(_("nothing added to commit but untracked files "
"present (use \"git add\" to track)\n"));
else
printf(_("nothing added to commit but untracked files present\n"));
} else if (s->is_initial) {
- if (advice_status_hints)
+ if (s->hints)
printf(_("nothing to commit (create/copy files "
"and use \"git add\" to track)\n"));
else
printf(_("nothing to commit\n"));
} else if (!s->show_untracked_files) {
- if (advice_status_hints)
+ if (s->hints)
printf(_("nothing to commit (use -u to show untracked files)\n"));
else
printf(_("nothing to commit\n"));
diff --git a/wt-status.h b/wt-status.h
index fb7152e..b4c9cb4 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -59,6 +59,7 @@ struct wt_status {
unsigned colopts;
int null_termination;
int show_branch;
+ int hints;
/* These are computed during processing of the individual sections */
int commitable;
--
1.8.4.8.g834017f
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] commit: disable status hints when writing to COMMIT_EDITMSG
2013-09-11 9:08 [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status Matthieu Moy
@ 2013-09-11 9:08 ` Matthieu Moy
2013-09-11 9:13 ` Eric Sunshine
2013-09-11 18:35 ` [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status Jeff King
1 sibling, 1 reply; 6+ messages in thread
From: Matthieu Moy @ 2013-09-11 9:08 UTC (permalink / raw)
To: git, gitster; +Cc: javierdo1, jrnieder, judge.packham, Matthieu Moy
This turns the template COMMIT_EDITMSG from e.g
# [...]
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: builtin/commit.c
#
# Untracked files:
# (use "git add <file>..." 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 ran.
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 edition 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 <Matthieu.Moy@imag.fr>
---
Junio, you'll get a trivial merge conflict with my other status
series, as they both add a few lines of code at the same location.
There should be no semantic conflict so I didn't consider the branches
as dependant.
builtin/commit.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/builtin/commit.c b/builtin/commit.c
index 388acde..6251d29 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -702,6 +702,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);
--
1.8.4.8.g834017f
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] commit: disable status hints when writing to COMMIT_EDITMSG
2013-09-11 9:08 ` [PATCH 2/2] commit: disable status hints when writing to COMMIT_EDITMSG Matthieu Moy
@ 2013-09-11 9:13 ` Eric Sunshine
0 siblings, 0 replies; 6+ messages in thread
From: Eric Sunshine @ 2013-09-11 9:13 UTC (permalink / raw)
To: Matthieu Moy
Cc: Git List, Junio C Hamano, javierdo1, Jonathan Nieder,
judge.packham
On Wed, Sep 11, 2013 at 5:08 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> 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 ran.
s/ran/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 edition of COMMIT_EDITMSG, but would be applicable
s/edition/editing/
> 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 <Matthieu.Moy@imag.fr>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status
2013-09-11 9:08 [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status Matthieu Moy
2013-09-11 9:08 ` [PATCH 2/2] commit: disable status hints when writing to COMMIT_EDITMSG Matthieu Moy
@ 2013-09-11 18:35 ` Jeff King
2013-09-12 9:44 ` Matthieu Moy
1 sibling, 1 reply; 6+ messages in thread
From: Jeff King @ 2013-09-11 18:35 UTC (permalink / raw)
To: Matthieu Moy; +Cc: git, gitster, javierdo1, jrnieder, judge.packham
On Wed, Sep 11, 2013 at 11:08:58AM +0200, Matthieu Moy wrote:
> 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().
> [...]
> +static void status_finalize(struct wt_status *s)
> +{
> + determine_whence(s);
> + s->hints = advice_status_hints;
> +}
Is a "finalize" the right place to put the status hint tweak? I would
expect the order for callers to be:
wt_status_prepare(&s);
/* manual tweaks of fields in "s" */
wt_status_finalize(&s);
but the finalize would overwrite any tweak of the hints field. So it
would make more sense to me for it to go in prepare().
But the current callsites look like this:
> @@ -1249,7 +1255,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
> wt_status_prepare(&s);
> gitmodules_config();
> git_config(git_status_config, &s);
> - determine_whence(&s);
> + status_finalize(&s);
> argc = parse_options(argc, argv, prefix,
> builtin_status_options,
> builtin_status_usage, 0);
We do not actually read the config until after _prepare, because the
config is what is doing the tweaking of "s" in this case. But we cannot
trust advice_* until we have read the config.
The problem is that we are doing two things in that git_config call:
1. Loading basic git-wide core config.
2. Priming the wt_status struct with options specific to "git status"
So the "cleanest" thing would be something like:
/* load basic config */
git_config(git_diff_ui_config, NULL);
/* initialize the status-run struct; this would probably be better named as
* _init to match the rest of the code */
wt_status_prepare(&s);
/* now tweak the defaults using status-specific config, which does
* not need to chain to other config callbacks anymore */
git_config(git_status_config, &s);
/* and then tweak further with command line options */
argc = parse_options(...);
/* and now finally ask wt-status to finalize any setup we've put into
the struct (e.g., calling determine_whence, though I do not
actually see it depending on any of the fields we set. Should it
be part of _prepare? */
wt_status_finalize(&s);
That would follow our more usual object init-tweak-finalize-use
patterns. Hrm. To make matters more complicated, we have
finalize_deferred_config, too. I think that could be rolled into
wt_status_finalize.
Perhaps that is getting a bit complicated as a refactor. If you don't
want to do it, I understand, but I think you should probably avoid the
name "_finalize" here, as it is a bit mis-leading.
-Peff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status
2013-09-11 18:35 ` [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status Jeff King
@ 2013-09-12 9:44 ` Matthieu Moy
2013-09-12 9:52 ` Jeff King
0 siblings, 1 reply; 6+ messages in thread
From: Matthieu Moy @ 2013-09-12 9:44 UTC (permalink / raw)
To: Jeff King; +Cc: git, gitster, javierdo1, jrnieder, judge.packham
Jeff King <peff@peff.net> writes:
> On Wed, Sep 11, 2013 at 11:08:58AM +0200, Matthieu Moy wrote:
>
>> 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().
>> [...]
>> +static void status_finalize(struct wt_status *s)
>> +{
>> + determine_whence(s);
>> + s->hints = advice_status_hints;
>> +}
>
> Is a "finalize" the right place to put the status hint tweak? I would
> expect the order for callers to be:
>
> wt_status_prepare(&s);
> /* manual tweaks of fields in "s" */
> wt_status_finalize(&s);
>
> but the finalize would overwrite any tweak of the hints field. So it
> would make more sense to me for it to go in prepare().
"finalize" is indeed not the right name. I made a separate function to
avoid too much code duplication between status and commit, and looked
for a name comlementary to "prepare" for a function that is ran later to
fill-in some fields.
> The problem is that we are doing two things in that git_config call:
>
> 1. Loading basic git-wide core config.
(Yes. This includes the advice section, so I need it for
advice_status_hints)
> So the "cleanest" thing would be something like:
>
> git_config(git_diff_ui_config, NULL);
> wt_status_prepare(&s);
[...]
That is clean, but a bit long and it is essentially duplicated between
status and commit. I went another way: put all the similar code in a
common function status_init_config:
static void status_init_config(struct wt_status *s, config_fn_t fn)
{
wt_status_prepare(s);
gitmodules_config();
git_config(git_status_config, s);
determine_whence(s);
s->hints = advice_status_hints; /* must come after git_config() */
}
We could split the git_config call, but that would not bring much
benefit IMHO. In any case, it can be done very simply on top of my patch
if needed later, as there is now only one call site for git_config.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status
2013-09-12 9:44 ` Matthieu Moy
@ 2013-09-12 9:52 ` Jeff King
0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2013-09-12 9:52 UTC (permalink / raw)
To: Matthieu Moy; +Cc: git, gitster, javierdo1, jrnieder, judge.packham
On Thu, Sep 12, 2013 at 11:44:30AM +0200, Matthieu Moy wrote:
> That is clean, but a bit long and it is essentially duplicated between
> status and commit. I went another way: put all the similar code in a
> common function status_init_config:
>
> static void status_init_config(struct wt_status *s, config_fn_t fn)
> {
> wt_status_prepare(s);
> gitmodules_config();
> git_config(git_status_config, s);
> determine_whence(s);
> s->hints = advice_status_hints; /* must come after git_config() */
> }
s/git_status_config/fn/, I assume.
> We could split the git_config call, but that would not bring much
> benefit IMHO. In any case, it can be done very simply on top of my patch
> if needed later, as there is now only one call site for git_config.
Yeah, I think that is fine. The other cleanup may or may not be worth
it, but should not be a blocker to your patch. With what you suggest
above, you are certainly not making anything worse with respect to the
code organization.
Thanks.
-Peff
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-09-12 9:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-11 9:08 [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status Matthieu Moy
2013-09-11 9:08 ` [PATCH 2/2] commit: disable status hints when writing to COMMIT_EDITMSG Matthieu Moy
2013-09-11 9:13 ` Eric Sunshine
2013-09-11 18:35 ` [PATCH 1/2] wt-status: turn advice_status_hints into a field of wt_status Jeff King
2013-09-12 9:44 ` Matthieu Moy
2013-09-12 9:52 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).