Re: [PATCH v4 2/7] ref-filter: add function to print single ref_array_item
On Wed, Oct 19, 2016 at 01:07:34PM -0400, Santiago Torres wrote: > > I guess that may complicate things for the caller you add in this > > series, which may not have a fully-qualified refname (which is obviously > > how filter_ref_kind() figures it out). I'd argue that is a bug, though, > > as things like "%(refname)" are generally expected to print out the > > fully refname ("git tag --format=%(refname)" does so, and you can use > > "%(refname:short)" if you want the shorter part). > > Hmm, I hadn't actually noticed that. Do you have any suggestions in how to > address this? > > In general this feels like a consequence of disambiguating .git/tags/* > within builtin/tag.c rather than letting ref-filter figure it out. The partial solution would look like something below. It's not too bad because git-tag always knows that it's working a ref in the refs/tags namespace (and we don't even have to qualify it ourselves, for_each_tag_name already does it for us). But verify-tag feeds arbitrary sha1 expressions. See the notes in the second patch. [1/2]: ref-filter: split ref_kind_from_filter [2/2]: tag: send fully qualified refnames to verify_tag_and_format builtin/tag.c | 2 +- ref-filter.c | 21 + ref-filter.h | 6 +- tag.c | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) -Peff
Re: [PATCH v4 2/7] ref-filter: add function to print single ref_array_item
On Wed, Oct 19, 2016 at 05:16:42AM -0400, Jeff King wrote: > On Wed, Oct 19, 2016 at 04:55:43AM -0400, Jeff King wrote: > > > > diff --git a/ref-filter.h b/ref-filter.h > > > index 14d435e..3d23090 100644 > > > --- a/ref-filter.h > > > +++ b/ref-filter.h > > > @@ -107,4 +107,7 @@ struct ref_sorting *ref_default_sorting(void); > > > /* Function to parse --merged and --no-merged options */ > > > int parse_opt_merge_filter(const struct option *opt, const char *arg, > > > int unset); > > > > > > +void pretty_print_ref(const char *name, const unsigned char *sha1, > > > + const char *format, unsigned kind); > > > + > > > > What are the possible values for "kind"? I guess these should come from > > FILTER_REFS_TAGS, BRANCHES, etc. It's probably worth documenting that. > > Alternatively, is it possible to just determine this from the name? It > > looks like filter_ref_kind() is how it happens for a normal ref-filter. > > I guess that may complicate things for the caller you add in this > series, which may not have a fully-qualified refname (which is obviously > how filter_ref_kind() figures it out). I'd argue that is a bug, though, > as things like "%(refname)" are generally expected to print out the > fully refname ("git tag --format=%(refname)" does so, and you can use > "%(refname:short)" if you want the shorter part). Hmm, I hadn't actually noticed that. Do you have any suggestions in how to address this? In general this feels like a consequence of disambiguating .git/tags/* within builtin/tag.c rather than letting ref-filter figure it out. Thanks, -Santiago. signature.asc Description: PGP signature
Re: [PATCH v4 2/7] ref-filter: add function to print single ref_array_item
On Fri, Oct 07, 2016 at 05:07:16PM -0400, santi...@nyu.edu wrote: > From: Lukas Puehringer> > ref-filter functions are useful for printing git object information > using a format specifier. However, some other modules may not want to use > this functionality on a ref-array but only print a single item. > > Expose a pretty_print_ref function to create, pretty print and free > individual ref-items. Makes sense. > diff --git a/ref-filter.h b/ref-filter.h > index 14d435e..3d23090 100644 > --- a/ref-filter.h > +++ b/ref-filter.h > @@ -107,4 +107,7 @@ struct ref_sorting *ref_default_sorting(void); > /* Function to parse --merged and --no-merged options */ > int parse_opt_merge_filter(const struct option *opt, const char *arg, int > unset); > > +void pretty_print_ref(const char *name, const unsigned char *sha1, > + const char *format, unsigned kind); > + What are the possible values for "kind"? I guess these should come from FILTER_REFS_TAGS, BRANCHES, etc. It's probably worth documenting that. Alternatively, is it possible to just determine this from the name? It looks like filter_ref_kind() is how it happens for a normal ref-filter. -Peff
Re: [PATCH v4 2/7] ref-filter: add function to print single ref_array_item
On Wed, Oct 19, 2016 at 04:55:43AM -0400, Jeff King wrote: > > diff --git a/ref-filter.h b/ref-filter.h > > index 14d435e..3d23090 100644 > > --- a/ref-filter.h > > +++ b/ref-filter.h > > @@ -107,4 +107,7 @@ struct ref_sorting *ref_default_sorting(void); > > /* Function to parse --merged and --no-merged options */ > > int parse_opt_merge_filter(const struct option *opt, const char *arg, int > > unset); > > > > +void pretty_print_ref(const char *name, const unsigned char *sha1, > > + const char *format, unsigned kind); > > + > > What are the possible values for "kind"? I guess these should come from > FILTER_REFS_TAGS, BRANCHES, etc. It's probably worth documenting that. > Alternatively, is it possible to just determine this from the name? It > looks like filter_ref_kind() is how it happens for a normal ref-filter. I guess that may complicate things for the caller you add in this series, which may not have a fully-qualified refname (which is obviously how filter_ref_kind() figures it out). I'd argue that is a bug, though, as things like "%(refname)" are generally expected to print out the fully refname ("git tag --format=%(refname)" does so, and you can use "%(refname:short)" if you want the shorter part). -Peff
[PATCH v4 2/7] ref-filter: add function to print single ref_array_item
From: Lukas Puehringerref-filter functions are useful for printing git object information using a format specifier. However, some other modules may not want to use this functionality on a ref-array but only print a single item. Expose a pretty_print_ref function to create, pretty print and free individual ref-items. Signed-off-by: Lukas Puehringer --- ref-filter.c | 10 ++ ref-filter.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/ref-filter.c b/ref-filter.c index 9adbb8a..cfbcd73 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1637,6 +1637,16 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu putchar('\n'); } +void pretty_print_ref(const char *name, const unsigned char *sha1, + const char *format, unsigned kind) +{ + struct ref_array_item *ref_item; + ref_item = new_ref_array_item(name, sha1, 0); + ref_item->kind = kind; + show_ref_array_item(ref_item, format, 0); + free_array_item(ref_item); +} + /* If no sorting option is given, use refname to sort as default */ struct ref_sorting *ref_default_sorting(void) { diff --git a/ref-filter.h b/ref-filter.h index 14d435e..3d23090 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -107,4 +107,7 @@ struct ref_sorting *ref_default_sorting(void); /* Function to parse --merged and --no-merged options */ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset); +void pretty_print_ref(const char *name, const unsigned char *sha1, + const char *format, unsigned kind); + #endif /* REF_FILTER_H */ -- 2.10.0