diff options
| author | Victoria Dye <vdye@github.com> | 2023-11-14 19:53:52 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-11-16 14:02:59 +0900 |
| commit | e7574b0c6b1e0cf2de9e000766a13d23fd9516e6 (patch) | |
| tree | eea6d4b3510f6f7d3d60215d67ddcba89a29aa14 /builtin/tag.c | |
| parent | ref-filter.h: move contains caches into filter (diff) | |
| download | git-e7574b0c6b1e0cf2de9e000766a13d23fd9516e6.tar.gz git-e7574b0c6b1e0cf2de9e000766a13d23fd9516e6.zip | |
ref-filter.h: add functions for filter/format & format-only
Add two new public methods to 'ref-filter.h':
* 'print_formatted_ref_array()' which, given a format specification & array
of ref items, formats and prints the items to stdout.
* 'filter_and_format_refs()' which combines 'filter_refs()',
'ref_array_sort()', and 'print_formatted_ref_array()' into a single
function.
This consolidates much of the code used to filter and format refs in
'builtin/for-each-ref.c', 'builtin/tag.c', and 'builtin/branch.c', reducing
duplication and simplifying the future changes needed to optimize the filter
& format process.
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/tag.c')
| -rw-r--r-- | builtin/tag.c | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/builtin/tag.c b/builtin/tag.c index 2d599245d4..2528d499dd 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -48,13 +48,7 @@ static int config_sign_tag = -1; /* unspecified */ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, struct ref_format *format) { - struct ref_array array; - struct strbuf output = STRBUF_INIT; - struct strbuf err = STRBUF_INIT; char *to_free = NULL; - int i; - - memset(&array, 0, sizeof(array)); if (filter->lines == -1) filter->lines = 0; @@ -72,23 +66,8 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, if (verify_ref_format(format)) die(_("unable to parse format string")); filter->with_commit_tag_algo = 1; - filter_refs(&array, filter, FILTER_REFS_TAGS); - filter_ahead_behind(the_repository, format, &array); - ref_array_sort(sorting, &array); - - for (i = 0; i < array.nr; i++) { - strbuf_reset(&output); - strbuf_reset(&err); - if (format_ref_array_item(array.items[i], format, &output, &err)) - die("%s", err.buf); - fwrite(output.buf, 1, output.len, stdout); - if (output.len || !format->array_opts.omit_empty) - putchar('\n'); - } + filter_and_format_refs(filter, FILTER_REFS_TAGS, sorting, format); - strbuf_release(&err); - strbuf_release(&output); - ref_array_clear(&array); free(to_free); return 0; |
