public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Phil Hord <phil.hord@gmail.com>
Cc: gitster@pobox.com, git@vger.kernel.org,
	Jacob Keller <jacob.e.keller@intel.com>
Subject: Re: [PATCH v4 3/3] clean up interface for refs_warn_dangling_symrefs
Date: Mon, 7 Jul 2025 21:35:34 -0400	[thread overview]
Message-ID: <20250708013534.GA549007@coredump.intra.peff.net> (raw)
In-Reply-To: <20250702011214.2835529-5-phil.hord@gmail.com>

On Tue, Jul 01, 2025 at 06:12:15PM -0700, Phil Hord wrote:

> The refs_warn_dangling_symrefs interface is a bit fragile as it passes
> in printf-formatting strings with expectations about the number of
> arguments. This patch series made it worse by adding a 2nd positional
> argument. But there are only two call sites, and they both use almost
> identical display options.
> 
> Make this safer by moving the format strings into the function that uses
> them to make it easier to see when the arguments don't match. Pass a
> prefix string and a dry_run flag so the decision logic can be handled
> where needed.

Thanks, I think the result is nicer. I have two comments, but I don't
think either will merit a re-roll.

> @@ -1384,9 +1384,6 @@ static int prune_refs(struct display_state *display_state,
>  	struct ref *ref, *stale_refs = get_stale_heads(rs, ref_map);
>  	struct strbuf err = STRBUF_INIT;
>  	struct string_list refnames = STRING_LIST_INIT_NODUP;
> -	const char *dangling_msg = dry_run
> -		? _("   %s will become dangling after %s is deleted")
> -		: _("   %s has become dangling after %s was deleted");
>  
>  	for (ref = stale_refs; ref; ref = ref->next)
>  		string_list_append(&refnames, ref->name);
> @@ -1417,7 +1414,7 @@ static int prune_refs(struct display_state *display_state,
>  		}
>  		string_list_sort(&refnames);
>  		refs_warn_dangling_symrefs(get_main_ref_store(the_repository),
> -					   stderr, dangling_msg, &refnames);
> +					   stderr, "   ", dry_run, &refnames);
>  	}

I had imagined passing in an "int indent", and not an arbitrary string.
But passing in the string is actually more flexible (it really could be
any prefix, not just an indentation). I think calling it "prefix" in the
actual function might be the more usual term here, but it's probably
just bike-shedding.

> -	fprintf(d->fp, d->msg_fmt, refname, resolves_to);
> -	fputc('\n', d->fp);
> +	msg = d->dry_run
> +		? _("%s%s will become dangling after %s is deleted\n")
> +		: _("%s%s has become dangling after %s was deleted\n");
> +	fprintf(d->fp, msg, d->indent, refname, resolves_to);

Translators might find the extra "%s" at the beginning confusing without
context. I think you can do something like:

  /* TRANSLATORS: The first %s is whitespace indentation. */

or similar. But maybe it would be more obvious as:

  fputs(d->indent, d->fp);
  fprintf(d->fp, msg, refname, resolves_to);
  fputc('\n', d->fp);

? I dunno. Maybe putting it all together gives translators more options
(e.g., in a RTL language). I don't know much about translation.

Likewise on including the newline in the translated string. I think we
usually don't, just because we're mostly passing in strings for error(),
etc. But I don't know how much it matters.

-Peff

  reply	other threads:[~2025-07-08  1:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02  1:12 [PATCH v4 0/3] fetch --prune performance problem Phil Hord
2025-07-02  1:12 ` [PATCH v4 1/3] fetch-prune: optimize dangling-ref reporting Phil Hord
2025-07-02  1:12 ` [PATCH v4 2/3] refs: remove old refs_warn_dangling_symref Phil Hord
2025-07-02  1:12 ` [PATCH v4 3/3] clean up interface for refs_warn_dangling_symrefs Phil Hord
2025-07-08  1:35   ` Jeff King [this message]
2025-07-07 22:43 ` [PATCH v4 0/3] fetch --prune performance problem Junio C Hamano
2025-07-08  1:00   ` Phil Hord
2025-07-08  1:36   ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250708013534.GA549007@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.e.keller@intel.com \
    --cc=phil.hord@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox