Skip to content

Commit 22f69a8

Browse files
adlternativegitster
authored andcommitted
ref-filter: get rid of show_ref_array_item
Inlining the exported function `show_ref_array_item()`, which is not providing the right level of abstraction, simplifies the API and can unlock improvements at the former call sites. Helped-by: René Scharfe <l.s.r@web.de> Signed-off-by: ZheNing Hu <adlternative@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b0c09ab commit 22f69a8

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

builtin/for-each-ref.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,18 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
8080

8181
if (!maxcount || array.nr < maxcount)
8282
maxcount = array.nr;
83-
for (i = 0; i < maxcount; i++)
84-
show_ref_array_item(array.items[i], &format);
83+
for (i = 0; i < maxcount; i++) {
84+
struct strbuf output = STRBUF_INIT;
85+
struct strbuf err = STRBUF_INIT;
86+
87+
if (format_ref_array_item(array.items[i], &format, &output, &err))
88+
die("%s", err.buf);
89+
fwrite(output.buf, 1, output.len, stdout);
90+
putchar('\n');
91+
92+
strbuf_release(&err);
93+
strbuf_release(&output);
94+
}
8595
ref_array_clear(&array);
8696
return 0;
8797
}

builtin/tag.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,18 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
6363
filter_refs(&array, filter, FILTER_REFS_TAGS);
6464
ref_array_sort(sorting, &array);
6565

66-
for (i = 0; i < array.nr; i++)
67-
show_ref_array_item(array.items[i], format);
66+
for (i = 0; i < array.nr; i++) {
67+
struct strbuf output = STRBUF_INIT;
68+
struct strbuf err = STRBUF_INIT;
69+
70+
if (format_ref_array_item(array.items[i], format, &output, &err))
71+
die("%s", err.buf);
72+
fwrite(output.buf, 1, output.len, stdout);
73+
putchar('\n');
74+
75+
strbuf_release(&err);
76+
strbuf_release(&output);
77+
}
6878
ref_array_clear(&array);
6979
free(to_free);
7080

ref-filter.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,27 +2435,22 @@ int format_ref_array_item(struct ref_array_item *info,
24352435
return 0;
24362436
}
24372437

2438-
void show_ref_array_item(struct ref_array_item *info,
2439-
const struct ref_format *format)
2440-
{
2441-
struct strbuf final_buf = STRBUF_INIT;
2442-
struct strbuf error_buf = STRBUF_INIT;
2443-
2444-
if (format_ref_array_item(info, format, &final_buf, &error_buf))
2445-
die("%s", error_buf.buf);
2446-
fwrite(final_buf.buf, 1, final_buf.len, stdout);
2447-
strbuf_release(&error_buf);
2448-
strbuf_release(&final_buf);
2449-
putchar('\n');
2450-
}
2451-
24522438
void pretty_print_ref(const char *name, const struct object_id *oid,
24532439
const struct ref_format *format)
24542440
{
24552441
struct ref_array_item *ref_item;
2442+
struct strbuf output = STRBUF_INIT;
2443+
struct strbuf err = STRBUF_INIT;
2444+
24562445
ref_item = new_ref_array_item(name, oid);
24572446
ref_item->kind = ref_kind_from_refname(name);
2458-
show_ref_array_item(ref_item, format);
2447+
if (format_ref_array_item(ref_item, format, &output, &err))
2448+
die("%s", err.buf);
2449+
fwrite(output.buf, 1, output.len, stdout);
2450+
putchar('\n');
2451+
2452+
strbuf_release(&err);
2453+
strbuf_release(&output);
24592454
free_array_item(ref_item);
24602455
}
24612456

ref-filter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ int format_ref_array_item(struct ref_array_item *info,
119119
const struct ref_format *format,
120120
struct strbuf *final_buf,
121121
struct strbuf *error_buf);
122-
/* Print the ref using the given format and quote_style */
123-
void show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
124122
/* Parse a single sort specifier and add it to the list */
125123
void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
126124
/* Callback function for parsing the sort option */

0 commit comments

Comments
 (0)