port tag.c to use ref-filter APIs
v11 cover port tag.c to use ref-filter APIs
Karthik Nayak (13):
ref-filter: move struct atom_value to ref-filter.c
ref-filter: print output to strbuf for formatting
ref-filter: introduce ref_formatting_state
utf8: add function to align a string into given strbuf
ref-filter: implement an align atom
ref-filter: add option to filter out tags, branches and remotes
ref-filter: support printing N lines from tag annotation
ref-filter: add support to sort by version
ref-filter: add option to match literal pattern tag.c: use 'ref-filter' data structures
tag.c: use 'ref-filter' APIs
tag.c: implement '--format' option
tag.c: implement '--merged' and '--no-merged' options
Changes since v10:
* Improve documentation.
* Change the syntax used for the align atom and make left alignment default whenever the position is not mentioned.
* Instead of checking for modifier atoms, we have handler functions for each atom and each state can have a attend function which is called when the state is popped.
* Nested alignment is now possible.
* Change the way filter_refs() works and now we assign each ref its kind so further filtering if needed can be done.
* Rename some functions to have more meaningful names.
* strbuf_utf8_align() now works with empty strings and also been refactored to reduced the no of calls to strlen().
Documentation/git-for-each-ref.txt | 11 ++ Documentation/git-tag.txt | 34 +++- builtin/for-each-ref.c | 3 +- builtin/tag.c | 367 +++++++------------------------------ ref-filter.c | 309 +++++++++++++++++++++++++++---- ref-filter.h | 33 +++- refs.c | 7 + refs.h | 1 + t/t6302-for-each-ref-filter.sh | 84 +++++++++ t/t7004-tag.sh | 51 +++++- utf8.c | 21 +++ utf8.h | 15 ++ 12 files changed, 573 insertions(+), 363 deletions(-)
InterDiff :
Documentation/git-for-each-ref.txt +3 -4
@@ -128,13 +128,12 @@ color:: are described in `color.branch.*`. align:: - Implement an `align` atom which left-, middle-, or - right-aligns the content between %(align:..) and - %(end). Followed by `:<position>,<width>`, where the + left-, middle-, or right-align the content between %(align:..) + and %(end). Followed by `:<position>,<width>`, where the `<position>` is either left, right or middle and `<width>` is the total length of the content with alignment. If the contents length is more than the width then no alignment is - performed. Currently nested alignment is not supported. + performed. In addition to the above, for commit and tag objects, the header field names (`tree`, `parent`, `object`, `type`, and `tag`) can
builtin/tag.c +1 -1
@@ -41,7 +41,7 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, con filter->lines =0 ;if (filter->lines) - format ="%(align:left,16)%(refname:short)%(end)" ; + format ="%(align:16,left)%(refname:short)%(end)" ;else if (!format) format ="%(refname:short)" ;
ref-filter.c +147 -89
353 lines not on this page · raw message
ref-filter.h +11 -4
@@ -14,9 +14,14 @@#define QUOTE_PYTHON 4#define QUOTE_TCL 8 -#define FILTER_REFS_INCLUDE_BROKEN 0x1 -#define FILTER_REFS_ALL 0x2 -#define FILTER_REFS_TAGS 0x4 +#define FILTER_REFS_INCLUDE_BROKEN 0x0001 +#define FILTER_REFS_TAGS 0x0002 +#define FILTER_REFS_BRANCHES 0x0004 +#define FILTER_REFS_REMOTES 0x0008 +#define FILTER_REFS_OTHERS 0x0010 +#define FILTER_REFS_ALL (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \ + FILTER_REFS_REMOTES | FILTER_REFS_OTHERS) +#define FILTER_REFS_DETACHED_HEAD 0x0020struct atom_value ;
@@ -30,6 +35,7 @@ struct ref_sorting {struct ref_array_item {unsigned char objectname[20 ];int flag; +unsigned int kind;const char *symref;struct commit *commit;struct atom_value *value;
@@ -55,7 +61,8 @@ struct ref_filter { unsigned int with_commit_tag_algo : 1, match_as_path : 1; -unsigned int lines; +unsigned int kind, + lines; };struct ref_filter_cbdata {
refs.c +7 -5
@@ -2114,11 +2114,6 @@ int for_each_tag_ref(each_ref_fn fn, void *cb_data)return for_each_ref_in ("refs/tags/" , fn, cb_data); } -int for_each_tag_ref_fullpath (each_ref_fn fn,void *cb_data) -{ -return do_for_each_ref (&ref_cache,"refs/tags/" , fn,0 ,0 , cb_data); -} -int for_each_tag_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data) {return for_each_ref_in_submodule (submodule,"refs/tags/" , fn, cb_data);
@@ -2150,6 +2145,13 @@ int for_each_replace_ref(each_ref_fn fn, void *cb_data) strlen(git_replace_ref_base), 0, cb_data); } +int for_each_reftype_fullpath (each_ref_fn fn,char *type,unsigned int broken,void *cb_data) +{ +if (broken) + broken =DO_FOR_EACH_INCLUDE_BROKEN ; +return do_for_each_ref (&ref_cache, type, fn,0 , broken, cb_data); +} +int head_ref_namespaced (each_ref_fn fn,void *cb_data) {struct strbuf buf =STRBUF_INIT ;
refs.h +1 -1
@@ -174,12 +174,12 @@ extern int head_ref(each_ref_fn fn, void *cb_data);extern int for_each_ref (each_ref_fn fn,void *cb_data);extern int for_each_ref_in (const char *prefix,each_ref_fn fn,void *cb_data);extern int for_each_tag_ref (each_ref_fn fn,void *cb_data); -extern int for_each_tag_ref_fullpath (each_ref_fn fn,void *cb_data);extern int for_each_branch_ref (each_ref_fn fn,void *cb_data);extern int for_each_remote_ref (each_ref_fn fn,void *cb_data);extern int for_each_replace_ref (each_ref_fn fn,void *cb_data);extern int for_each_glob_ref (each_ref_fn fn,const char *pattern,void *cb_data);extern int for_each_glob_ref_in (each_ref_fn fn,const char *pattern,const char *prefix,void *cb_data); +extern int for_each_reftype_fullpath (each_ref_fn fn,char *type,unsigned int broken,void *cb_data);extern int head_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data);extern int for_each_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data);
t/t6302-for-each-ref-filter.sh +3 -3
@@ -93,7 +93,7 @@ test_expect_success 'left alignment' ' refname is refs/tags/three |refs/tags/three refname is refs/tags/two |refs/tags/two EOF - git for-each-ref --format="%(align:left,30)refname is %(refname)%(end)|%(refname)" >actual && + git for-each-ref --format="%(align:30,left)refname is %(refname)%(end)|%(refname)" >actual && test_cmp expect actual '
@@ -109,7 +109,7 @@ test_expect_success 'middle alignment' ' | refname is refs/tags/three |refs/tags/three | refname is refs/tags/two |refs/tags/two EOF - git for-each-ref --format="|%(align:middle,30)refname is %(refname)%(end)|%(refname)" >actual && + git for-each-ref --format="|%(align:30,middle)refname is %(refname)%(end)|%(refname)" >actual && test_cmp expect actual '
@@ -125,7 +125,7 @@ test_expect_success 'right alignment' ' | refname is refs/tags/three|refs/tags/three | refname is refs/tags/two|refs/tags/two EOF - git for-each-ref --format="|%(align:right,30)refname is %(refname)%(end)|%(refname)" >actual && + git for-each-ref --format="|%(align:30,right)refname is %(refname)%(end)|%(refname)" >actual && test_cmp expect actual '
utf8.c +6 -7
@@ -648,21 +648,20 @@ int skip_utf8_bom(char **text, size_t len)void strbuf_utf8_align (struct strbuf *buf,align_type position,unsigned int width,const char *s) { -int display_len =utf8_strnwidth (s,strlen (s),0 ); -int utf8_compenstation =strlen (s) - display_len; +int slen =strlen (s); +int display_len =utf8_strnwidth (s, slen,0 ); +int utf8_compensation = slen - display_len; -if (!strlen (s)) -return ;if (display_len >= width) {strbuf_addstr (buf, s);return ; }if (position ==ALIGN_LEFT ) -strbuf_addf (buf,"%-*s" , width + utf8_compenstation, s); +strbuf_addf (buf,"%-*s" , width + utf8_compensation, s);else if (position ==ALIGN_MIDDLE ) {int left = (width - display_len)/2 ; -strbuf_addf (buf,"%*s%-*s" , left,"" , width - left + utf8_compenstation, s); +strbuf_addf (buf,"%*s%-*s" , left,"" , width - left + utf8_compensation, s); }else if (position ==ALIGN_RIGHT ) -strbuf_addf (buf,"%*s" , width + utf8_compenstation, s); +strbuf_addf (buf,"%*s" , width + utf8_compensation, s); }
utf8.h +4 -2
@@ -62,8 +62,10 @@ typedef enum { } align_type;/* -* Align the string given and store it into a strbuf as per the type -* and width. +* Align the string given and store it into a strbuf as per the +* 'position' and 'width'. If the given string length is larger than +* 'width' than then the input string is not truncated and no +* alignment is done. */ void strbuf_utf8_align (struct strbuf *buf,align_type position,unsigned int width,const char *s);
Signature · 1 line
2.5.0
Documentation/git-for-each-ref.txt color:: · line 132
Quoted 7 lines · Karthik Nayak
align::
Documentation/git-for-each-ref.txt +2
-3- Implement an `align` atom which left-, middle-, or - right-aligns the content between %(align:..) and - %(end). Followed by `:<position>,<width>`, where the + left-, middle-, or right-align the content between %(align:..) + and %(end). Followed by `:<position>,<width>`, where the
Everywhere else in the code seems to now put position second now, but the documentation here doesn't say this is allowed or required.
Regards,
Jake
Quoted 6 lines
<position>is either left, right or middle and<width>is the total length of the content with alignment. If the contents length is more than the width then no alignment isDocumentation/git-for-each-ref.txt +1
-1- performed. Currently nested alignment is not supported. + performed.
Quoted 11 lines · Jacob Keller
Documentation/git-for-each-ref.txt color:: · line 132
Quoted 7 lines · Karthik Nayak
align::
Documentation/git-for-each-ref.txt +2
-3- Implement an `align` atom which left-, middle-, or - right-aligns the content between %(align:..) and - %(end). Followed by `:<position>,<width>`, where the + left-, middle-, or right-align the content between %(align:..) + and %(end). Followed by `:<position>,<width>`, where the
Quoted 3 lines
Everywhere else in the code seems to now put position second now, but the documentation here doesn't say this is allowed or required.
Oops! you're right, that needs to be swapped.
Signature · 2 lines
Regards, Karthik Nayak