git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: ZheNing Hu <adlternative@gmail.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: ZheNing Hu via GitGitGadget <gitgitgadget@gmail.com>,
	Git List <git@vger.kernel.org>, Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>,
	Christian Couder <chriscool@tuxfamily.org>,
	Hariom Verma <hariom18599@gmail.com>
Subject: Re: [PATCH] [GSOC] ref-filter: add %(notes) format atom
Date: Sun, 2 May 2021 14:12:09 +0800	[thread overview]
Message-ID: <CAOLTT8TGaVxxHJRF_-Dq0Gnd50_H-80C6zPhjQAQruiO59qw2A@mail.gmail.com> (raw)
In-Reply-To: <38083c1b-f92b-7624-67b7-3a5dcf213d79@web.de>

René Scharfe <l.s.r@web.de> 于2021年5月2日周日 上午3:21写道:
>
> Am 29.04.21 um 12:24 schrieb ZheNing Hu via GitGitGadget:
> > From: ZheNing Hu <adlternative@gmail.com>
> >
> > Note that `--pretty="%N"` can view notes related
> > to the commit. So add `%(notes)` to ref-filter
> > seem is a good choice. This atom `%(notes)` view
> > the notes associated with the ref, and support
> > dereference.
>
> I can't judge the usefulness of this feature because I don't use notes.
>
> > Signed-off-by: ZheNing Hu <adlternative@gmail.com>
> > ---
> >     [GSOC] ref-filter: add %(notes) format atom
> >
> >     An important step in the GSOC project Use ref-filter formats in git
> >     cat-file is to integrate different format atoms into the ref-filter.
> >     Olga and Hariom have also made a lot of efforts in this area.
>
> This is done to replace the custom format parser in git cat-file with
> ref-filter in order to reduce code duplication, right?
>
> >     Currently, I noticed that there may be some format atoms in "pretty.c"
> >     that have not been migrated to ref-filter, such as --pretty="%N",
> >     --pretty="%(describe)".
>
> git cat-file doesn't support pretty format atoms, so I'm not sure I see
> the connection here.
>

At present, `git cat-file --batch`, `git log --pretty`, and `git
for-each-ref --format`
lack consistency.

The ambition of this project is to unify these different formats
"%aN","%(authorname)"
through an interface, maybe it's `ref-filter` or maybe a new one.

It is estimated that many places in need to be replaced and rebuilt,
and it not just to
reduce code duplication.

Note that `cat-file --batch` should be a superset of `ref-filter` and
`--pretty`, because
it supports all objects, while `ref-filter` only supports "commit" and
"tag" two kinds
of objects, and `--pretty` only supports "commit" one kind of object.

So it may be reasonable to provide `%(notes)` to "commit","tag"
objects in `cat-file --batch`
in the future, now integrate them into ref-filter firstly.

> >     So in this patch, I tried to migrate --pretty=%N to --format=%(notes).
> >
> >     Hope this will be hopeful !!!
> >
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-944%2Fadlternative%2Fformat-notes-atom-v1
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-944/adlternative/format-notes-atom-v1
> > Pull-Request: https://github.com/gitgitgadget/git/pull/944
> >
> >  Documentation/git-for-each-ref.txt |  4 ++++
> >  ref-filter.c                       | 31 ++++++++++++++++++++++++++++--
> >  t/t6300-for-each-ref.sh            | 10 ++++++++++
> >  3 files changed, 43 insertions(+), 2 deletions(-)
> >
> > diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
> > index 2ae2478de706..07f037a16e13 100644
> > --- a/Documentation/git-for-each-ref.txt
> > +++ b/Documentation/git-for-each-ref.txt
> > @@ -139,6 +139,9 @@ deltabase::
> >       given object, if it is stored as a delta.  Otherwise it
> >       expands to the null object name (all zeroes).
> >
> > +notes::
> > +     The notes associated with the ref.
> > +
> >  upstream::
> >       The name of a local ref which can be considered ``upstream''
> >       from the displayed ref. Respects `:short`, `:lstrip` and
> > @@ -302,6 +305,7 @@ git for-each-ref --count=3 --sort='-*authordate' \
> >  Subject: %(*subject)
> >  Date: %(*authordate)
> >  Ref: %(*refname)
> > +Notes: %(*notes)
> >
> >  %(*body)
> >  ' 'refs/tags'
> > diff --git a/ref-filter.c b/ref-filter.c
> > index a0adb4551d87..42a5608a3056 100644
> > --- a/ref-filter.c
> > +++ b/ref-filter.c
> > @@ -23,6 +23,7 @@
> >  #include "worktree.h"
> >  #include "hashmap.h"
> >  #include "strvec.h"
> > +#include "run-command.h"
> >
> >  static struct ref_msg {
> >       const char *gone;
> > @@ -506,6 +507,7 @@ static struct {
> >       { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser },
> >       { "objectname", SOURCE_OTHER, FIELD_STR, oid_atom_parser },
> >       { "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser },
> > +     { "notes", SOURCE_OTHER, FIELD_STR },
> >       { "tree", SOURCE_OBJ, FIELD_STR, oid_atom_parser },
> >       { "parent", SOURCE_OBJ, FIELD_STR, oid_atom_parser },
> >       { "numparent", SOURCE_OBJ, FIELD_ULONG },
> > @@ -953,6 +955,24 @@ static int grab_oid(const char *name, const char *field, const struct object_id
> >       return 0;
> >  }
> >
> > +static int grab_notes(const struct object_id *oid, struct atom_value *v)
> > +{
> > +     struct child_process cmd = CHILD_PROCESS_INIT;
> > +     struct strbuf out = STRBUF_INIT;
> > +     struct strbuf err = STRBUF_INIT;
> > +     const char *args[] = { "notes", "show", NULL };
> > +     int ret;
> > +
> > +     cmd.git_cmd = 1;
> > +     strvec_pushv(&cmd.args, args);
> > +     strvec_push(&cmd.args, oid_to_hex(oid));
> > +     ret = pipe_command(&cmd, NULL, 0, &out, 0, &err, 0);
>
> Nice prototype.  Is it possible to avoid the overhead of calling git
> notes as an external process by calling load_display_notes() once at
> parse time and format_display_notes() for each item?  Would it cause
> conflicts for code that uses ref-filter and handles notes already?
>

This sounds feasible, I will try if it can work.

Thanks!
--
ZheNing Hu

  reply	other threads:[~2021-05-02  6:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29 10:24 [PATCH] [GSOC] ref-filter: add %(notes) format atom ZheNing Hu via GitGitGadget
2021-05-01 19:21 ` René Scharfe
2021-05-02  6:12   ` ZheNing Hu [this message]
2021-05-03  2:56     ` Junio C Hamano
2021-05-03 13:25       ` ZheNing Hu

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=CAOLTT8TGaVxxHJRF_-Dq0Gnd50_H-80C6zPhjQAQruiO59qw2A@mail.gmail.com \
    --to=adlternative@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=hariom18599@gmail.com \
    --cc=l.s.r@web.de \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).