aboutsummaryrefslogtreecommitdiffstats
path: root/refs.c
diff options
context:
space:
mode:
authorPhil Hord <phil.hord@gmail.com>2025-07-01 18:12:15 -0700
committerJunio C Hamano <gitster@pobox.com>2025-07-01 18:42:25 -0700
commit87d8d8c5d09b1ee52cdf472b53b370020a7cb41c (patch)
tree7bc2254498aff64b2452cb8cbf55c467e495ad93 /refs.c
parentrefs: remove old refs_warn_dangling_symref (diff)
downloadgit-87d8d8c5d09b1ee52cdf472b53b370020a7cb41c.tar.gz
git-87d8d8c5d09b1ee52cdf472b53b370020a7cb41c.zip
clean up interface for refs_warn_dangling_symrefs
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. Signed-off-by: Phil Hord <phil.hord@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/refs.c b/refs.c
index b0e67077a6..8573310a06 100644
--- a/refs.c
+++ b/refs.c
@@ -439,7 +439,8 @@ struct warn_if_dangling_data {
struct ref_store *refs;
FILE *fp;
const struct string_list *refnames;
- const char *msg_fmt;
+ const char *indent;
+ int dry_run;
};
static int warn_if_dangling_symref(const char *refname, const char *referent UNUSED,
@@ -447,7 +448,7 @@ static int warn_if_dangling_symref(const char *refname, const char *referent UNU
int flags, void *cb_data)
{
struct warn_if_dangling_data *d = cb_data;
- const char *resolves_to;
+ const char *resolves_to, *msg;
if (!(flags & REF_ISSYMREF))
return 0;
@@ -458,19 +459,23 @@ static int warn_if_dangling_symref(const char *refname, const char *referent UNU
return 0;
}
- 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);
return 0;
}
void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp,
- const char *msg_fmt, const struct string_list *refnames)
+ const char *indent, int dry_run,
+ const struct string_list *refnames)
{
struct warn_if_dangling_data data = {
.refs = refs,
.fp = fp,
.refnames = refnames,
- .msg_fmt = msg_fmt,
+ .indent = indent,
+ .dry_run = dry_run,
};
refs_for_each_rawref(refs, warn_if_dangling_symref, &data);
}