From: Junio C Hamano <gitster@pobox.com>
To: Kousik Sanagavarapu <five231003@gmail.com>
Cc: Bence Ferdinandy <bence@ferdinandy.com>, git@vger.kernel.org
Subject: Re: [PATCH] ref-filter: add "notes" atom
Date: Thu, 21 Nov 2024 08:51:47 +0900 [thread overview]
Message-ID: <xmqqserlh3ak.fsf@gitster.g> (raw)
In-Reply-To: <Zz4Wr1YY7HxRARoc@five231003> (Kousik Sanagavarapu's message of "Wed, 20 Nov 2024 22:34:47 +0530")
Kousik Sanagavarapu <five231003@gmail.com> writes:
> +static void grab_notes_values(struct atom_value *val, int deref,
> + struct object *obj)
> +{
> + for (int i = 0; i < used_atom_cnt; i++) {
> + struct used_atom *atom = &used_atom[i];
> + const char *name = atom->name;
> + struct atom_value *v = &val[i];
> +
> + struct child_process cmd = CHILD_PROCESS_INIT;
> + struct strbuf out = STRBUF_INIT;
> + struct strbuf err = STRBUF_INIT;
> +
> + if (atom->atom_type != ATOM_NOTES)
> + continue;
> +
> + if (!!deref != (*name == '*'))
> + continue;
> +
> + cmd.git_cmd = 1;
> + strvec_push(&cmd.args, "notes");
> + if (atom->u.notes_refname) {
> + strvec_push(&cmd.args, "--ref");
> + strvec_push(&cmd.args, atom->u.notes_refname);
> + }
> + strvec_push(&cmd.args, "show");
> + strvec_push(&cmd.args, oid_to_hex(&obj->oid));
> + if (pipe_command(&cmd, NULL, 0, &out, 0, &err, 0) < 0) {
> + error(_("failed to run 'notes'"));
> + v->s = xstrdup("");
> + continue;
> + }
> + strbuf_rtrim(&out);
> + v->s = strbuf_detach(&out, NULL);
> +
> + strbuf_release(&err);
> + }
> +}
I suspect that this was written to mimick what is done for describe.
The describe codepath has a (semi-)valid reason to fork out to a
subprocess, as computation of describe smudges the object flags of
in-core object database and it is not trivial to call into the
helper functions twice.
But showing notes for a single commit is merely an internal call to
get_note() away, so unless the note object is not a blob (which
should be absolutely rare), spawning a subprocess for each and every
ref tip feels a bit heavier than acceptable. We'd probably need to
maintain a table of notes_trees, one per <note-ref> used as
%(notes:<note-ref>) in the format string, and init_notes() on them
while parsing the atoms, and in this codepath it would be a look-up
of notes_tree from the table based on the u.notes_refname by calling
get_note() to learn the object name, plus reading the object
contents into the v->s member when the note object is a blob (and
fallback the above code when it is not a blob, which is a rare-case,
if we really want to handle them).
next prev parent reply other threads:[~2024-11-20 23:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 22:00 log --format existence of notes? Bence Ferdinandy
2024-11-16 0:06 ` Junio C Hamano
2024-11-16 15:11 ` Bence Ferdinandy
2024-11-20 17:04 ` [PATCH] ref-filter: add "notes" atom Kousik Sanagavarapu
2024-11-20 23:51 ` Junio C Hamano [this message]
2024-12-01 8:19 ` Kousik Sanagavarapu
2024-11-21 5:26 ` log --format existence of notes? Simon Richter
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=xmqqserlh3ak.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=bence@ferdinandy.com \
--cc=five231003@gmail.com \
--cc=git@vger.kernel.org \
/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).