From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Gregory David <gregory.david@p1sec.com>,
ptm-dev <ptm-dev@p1sec.com>
Subject: Re: [PATCH v3 1/2] show-branch: refactor in preparation for next commit
Date: Thu, 21 Apr 2022 11:13:31 -0700 [thread overview]
Message-ID: <xmqqr15qi9tg.fsf@gitster.g> (raw)
In-Reply-To: <patch-v3-1.2-879930b7a66-20220421T152704Z-avarab@gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Thu, 21 Apr 2022 17:33:47 +0200")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Move the code in cmd_show_branch() that formats a reflog message for
> us into a function,
Makes quite a lot of sense.
"factoring out the formatting of reflog message, given a single
reflog entry", is a very good unit of work that is independently
good and can be evaluated as such.
> and change the "flags" variable that we never
> change into a "const", in addition to moving it up a scope in
> preparation for the subsequent commit.
Perhaps doing that as part of the next step is better (or not doing
it if it can be helped)? Mixing it in contaminates a good isolation
done with an unrelated change. We somehow ended up seeing too many
"while at it" in the recent patches, and I think that needs to stop.
We should go back to better patch hygiene.
Other than that, looks sensible. Let's see what 2/2 does.
Thanks.
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> builtin/show-branch.c | 34 +++++++++++++++++++++-------------
> 1 file changed, 21 insertions(+), 13 deletions(-)
>
> diff --git a/builtin/show-branch.c b/builtin/show-branch.c
> index 330b0553b9d..499ef76a508 100644
> --- a/builtin/show-branch.c
> +++ b/builtin/show-branch.c
> @@ -618,6 +618,24 @@ static int parse_reflog_param(const struct option *opt, const char *arg,
> return 0;
> }
>
> +static char *fmt_reflog(char *const logmsg, const timestamp_t ts, const int tz,
> + const char *fmt)
> +{
> + char *const end = strchr(logmsg, '\n');
> + const char *msg;
> + char *ret;
> +
> + if (end)
> + *end = '\0';
> +
> + msg = *logmsg ? logmsg : "(none)";
> +
> + ret = xstrfmt(fmt, show_date(ts, tz, DATE_MODE(RELATIVE)), msg);
> + free(logmsg);
> +
> + return ret;
> +}
> +
> int cmd_show_branch(int ac, const char **av, const char *prefix)
> {
> struct commit *rev[MAX_REVS], *commit;
> @@ -640,6 +658,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
> int topics = 0;
> int dense = 1;
> const char *reflog_base = NULL;
> + const unsigned int flags = 0;
> struct option builtin_show_branch_options[] = {
> OPT_BOOL('a', "all", &all_heads,
> N_("show remote-tracking and local branches")),
> @@ -720,7 +739,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
> struct object_id oid;
> char *ref;
> int base = 0;
> - unsigned int flags = 0;
>
> if (ac == 0) {
> static const char *fake_av[2];
> @@ -761,8 +779,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
> for (i = 0; i < reflog; i++) {
> char *logmsg;
> char *nth_desc;
> - const char *msg;
> - char *end;
> timestamp_t timestamp;
> int tz;
>
> @@ -773,16 +789,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
> break;
> }
>
> - end = strchr(logmsg, '\n');
> - if (end)
> - *end = '\0';
> -
> - msg = (*logmsg == '\0') ? "(none)" : logmsg;
> - reflog_msg[i] = xstrfmt("(%s) %s",
> - show_date(timestamp, tz,
> - DATE_MODE(RELATIVE)),
> - msg);
> - free(logmsg);
> + reflog_msg[i] = fmt_reflog(logmsg, timestamp, tz,
> + "(%s) %s");
>
> nth_desc = xstrfmt("%s@{%d}", *av, base+i);
> append_ref(nth_desc, &oid, 1);
next prev parent reply other threads:[~2022-04-21 18:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 13:34 [PATCH] show-branch: fix SEGFAULT when `--current` and `--reflog` together Gregory David
2022-04-21 15:33 ` [PATCH v3 0/2] show-brach: segfault fix from Gregory David Ævar Arnfjörð Bjarmason
2022-04-21 15:33 ` [PATCH v3 1/2] show-branch: refactor in preparation for next commit Ævar Arnfjörð Bjarmason
2022-04-21 18:13 ` Junio C Hamano [this message]
2022-04-21 15:33 ` [PATCH v3 2/2] show-branch: fix SEGFAULT when `--current` and `--reflog` together Ævar Arnfjörð Bjarmason
2022-04-21 18:36 ` Junio C Hamano
2022-04-21 21:25 ` [PATCH] show-branch: -g and --current are incompatible Junio C Hamano
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=xmqqr15qi9tg.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gregory.david@p1sec.com \
--cc=ptm-dev@p1sec.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;
as well as URLs for NNTP newsgroup(s).