diff mbox series

[v2] git-merge: move primary point before parenthetical

Message ID pull.934.v2.git.1619047347605.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] git-merge: move primary point before parenthetical | expand

Commit Message

Josh Soref April 21, 2021, 11:22 p.m. UTC
From: Josh Soref <jsoref@gmail.com>

Usually, it is easier to read a message if it makes its primary
point first, before giving a parenthetical note.

Before:
` (nothing to squash)Already up to date.
`

After:
`Already up to date (nothing to squash).
`

Signed-off-by: Josh Soref <jsoref@gmail.com>
---
    git-merge: move space to between strings
    
    GitHub Actions show things like:
    
     * branch                  master     -> FETCH_HEAD
     (nothing to squash)Already up to date.
    
    
    Usually, it is easier to read a message if it makes its primary point
    first, before giving a parenthetical note.
    
    The expected results are:
    
     * branch                  master     -> FETCH_HEAD
    Already up to date (nothing to squash).
    
    
    This commit should change that. Other than breaking all the
    localizations, and anyone who actively parses the output, this shouldn't
    have much impact.
    
    Changes since v1:
    
     * finish_up_to_date now takes a message with a %s for the parenthetical
       and a trailing \n to address feedback from Junio C Hamano

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-934%2Fjsoref%2Fnothing-to-squash-already-up-to-date-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-934/jsoref/nothing-to-squash-already-up-to-date-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/934

Range-diff vs v1:

 1:  1b9d685d611f ! 1:  4f60e08195ea git-merge: move space to between strings
     @@ Metadata
      Author: Josh Soref <jsoref@gmail.com>
      
       ## Commit message ##
     -    git-merge: move space to between strings
     +    git-merge: move primary point before parenthetical
     +
     +    Usually, it is easier to read a message if it makes its primary
     +    point first, before giving a parenthetical note.
     +
     +    Before:
     +    ` (nothing to squash)Already up to date.
     +    `
     +
     +    After:
     +    `Already up to date (nothing to squash).
     +    `
      
          Signed-off-by: Josh Soref <jsoref@gmail.com>
      
     @@ builtin/merge.c: static void restore_state(const struct object_id *head,
       {
       	if (verbosity >= 0)
      -		printf("%s%s\n", squash ? _(" (nothing to squash)") : "", msg);
     -+		printf("%s%s\n", squash ? _("(nothing to squash) ") : "", msg);
     ++		printf(msg, squash ? _(" (nothing to squash)") : "");
       	remove_merge_branch_state(the_repository);
       }
       
     +@@ builtin/merge.c: int cmd_merge(int argc, const char **argv, const char *prefix)
     + 		 * If head can reach all the merge then we are up to date.
     + 		 * but first the most common case of merging one remote.
     + 		 */
     +-		finish_up_to_date(_("Already up to date."));
     ++		finish_up_to_date(_("Already up to date%s.\n"));
     + 		goto done;
     + 	} else if (fast_forward != FF_NO && !remoteheads->next &&
     + 			!common->next &&
     +@@ builtin/merge.c: int cmd_merge(int argc, const char **argv, const char *prefix)
     + 			}
     + 		}
     + 		if (up_to_date) {
     +-			finish_up_to_date(_("Already up to date. Yeeah!"));
     ++			finish_up_to_date(_("Already up to date%s. Yeeah!\n"));
     + 			goto done;
     + 		}
     + 	}


 builtin/merge.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


base-commit: 7a6a90c6ec48fc78c83d7090d6c1b95d8f3739c0

Comments

Eric Sunshine April 21, 2021, 11:46 p.m. UTC | #1
On Wed, Apr 21, 2021 at 7:22 PM Josh Soref via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> Usually, it is easier to read a message if it makes its primary
> point first, before giving a parenthetical note.
>
> Before:
> ` (nothing to squash)Already up to date.
> `
>
> After:
> `Already up to date (nothing to squash).
> `

Thanks. This makes perfect sense and fixes what clearly seems to be a
case of swapped arguments to printf(). While the intent of the patch
is quite desirable, I do have some concerns about the actual
changes...

> Signed-off-by: Josh Soref <jsoref@gmail.com>
> ---
> diff --git a/builtin/merge.c b/builtin/merge.c
> @@ -383,7 +383,7 @@ static void restore_state(const struct object_id *head,
>  static void finish_up_to_date(const char *msg)
>  {
>         if (verbosity >= 0)
> -               printf("%s%s\n", squash ? _(" (nothing to squash)") : "", msg);
> +               printf(msg, squash ? _(" (nothing to squash)") : "");
>         remove_merge_branch_state(the_repository);
>  }
> @@ -1482,7 +1482,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
> -               finish_up_to_date(_("Already up to date."));
> +               finish_up_to_date(_("Already up to date%s.\n"));
> @@ -1566,7 +1566,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
> -                       finish_up_to_date(_("Already up to date. Yeeah!"));
> +                       finish_up_to_date(_("Already up to date%s. Yeeah!\n"));

I see why you changed the calling convention, making it the
responsibility of the caller to supply the "%s" so that the "(nothing
to squash)" annotation gets inserted before the period at the end of
"Already up to date". However, this makes things confusing for people
translating the text to other languages since they won't have enough
context to understand what gets interpolated in place of "%s".

In fact (not a fault of your patch), this sort of "sentence Lego" was
already a bit difficult on translators because they couldn't see the
entire context of "Already up to date" and "(nothing to squash)"
together, thus could only translate them individually which may have
led to inferior translations in some languages.

Ideally, for the sake of translators, we want to give them as much
context as possible, such as the entire "Already up to date (nothing
to squash)". So, keeping translators and context in mind, and asking
if we really need to that rather odd "Yeeah!", an alternative way to
resolve this problem would be like this:

    static void finish_up_to_date()
    {
        if (verbosity >= 0) {
            if (squash)
                puts(_("Already up to date (nothing to squash)."));
            else
                puts(_("Already up to date."));
        }
        remove_merge_branch_state(the_repository);
    }

And then the callers reduce simply to:

    finish_up_to_date();
diff mbox series

Patch

diff --git a/builtin/merge.c b/builtin/merge.c
index 062e91144125..aad180010670 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -383,7 +383,7 @@  static void restore_state(const struct object_id *head,
 static void finish_up_to_date(const char *msg)
 {
 	if (verbosity >= 0)
-		printf("%s%s\n", squash ? _(" (nothing to squash)") : "", msg);
+		printf(msg, squash ? _(" (nothing to squash)") : "");
 	remove_merge_branch_state(the_repository);
 }
 
@@ -1482,7 +1482,7 @@  int cmd_merge(int argc, const char **argv, const char *prefix)
 		 * If head can reach all the merge then we are up to date.
 		 * but first the most common case of merging one remote.
 		 */
-		finish_up_to_date(_("Already up to date."));
+		finish_up_to_date(_("Already up to date%s.\n"));
 		goto done;
 	} else if (fast_forward != FF_NO && !remoteheads->next &&
 			!common->next &&
@@ -1566,7 +1566,7 @@  int cmd_merge(int argc, const char **argv, const char *prefix)
 			}
 		}
 		if (up_to_date) {
-			finish_up_to_date(_("Already up to date. Yeeah!"));
+			finish_up_to_date(_("Already up to date%s. Yeeah!\n"));
 			goto done;
 		}
 	}