Am 29.04.21 um 12:24 schrieb ZheNing Hu via GitGitGadget: > From: ZheNing Hu <adlternative@xxxxxxxxx> > > 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@xxxxxxxxx> > --- > [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. > 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? > + strbuf_trim_trailing_newline(&out); > + v->s = strbuf_detach(&out, NULL); > + strbuf_release(&err); > + return ret; > +} > + > /* See grab_values */ > static void grab_common_values(struct atom_value *val, int deref, struct expand_data *oi) > { > @@ -975,8 +995,12 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_ > v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size); > } else if (!strcmp(name, "deltabase")) > v->s = xstrdup(oid_to_hex(&oi->delta_base_oid)); > - else if (deref) > - grab_oid(name, "objectname", &oi->oid, v, &used_atom[i]); > + else if (deref) { > + if (!strcmp(name, "notes")) > + grab_notes(&oi->oid, v); > + else > + grab_oid(name, "objectname", &oi->oid, v, &used_atom[i]); > + } > } > } > > @@ -1767,6 +1791,9 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) > continue; > } else if (!deref && grab_oid(name, "objectname", &ref->objectname, v, atom)) { > continue; > + } else if (!deref && !strcmp(name, "notes")) { > + grab_notes(&ref->objectname, v); > + continue; > } else if (!strcmp(name, "HEAD")) { > if (atom->u.head && !strcmp(ref->refname, atom->u.head)) > v->s = xstrdup("*");