]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ref-filter: get rid of show_ref_array_item
authorZheNing Hu <adlternative@gmail.com>
Mon, 19 Apr 2021 11:28:44 +0000 (11:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Apr 2021 22:08:00 +0000 (15:08 -0700)
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>
builtin/for-each-ref.c
builtin/tag.c
ref-filter.c
ref-filter.h

index cb9c81a04606196ae3e23a6d59e3e0f27c1b3b5a..8520008604e377494532afe758518ecab8c7c062 100644 (file)
@@ -80,8 +80,18 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
 
        if (!maxcount || array.nr < maxcount)
                maxcount = array.nr;
-       for (i = 0; i < maxcount; i++)
-               show_ref_array_item(array.items[i], &format);
+       for (i = 0; i < maxcount; i++) {
+               struct strbuf output = STRBUF_INIT;
+               struct strbuf err = STRBUF_INIT;
+
+               if (format_ref_array_item(array.items[i], &format, &output, &err))
+                       die("%s", err.buf);
+               fwrite(output.buf, 1, output.len, stdout);
+               putchar('\n');
+
+               strbuf_release(&err);
+               strbuf_release(&output);
+       }
        ref_array_clear(&array);
        return 0;
 }
index d403417b562595832513cd6e88e4d58c4076336e..d92d8e110b4d62c262b56fecf77c6b7cfe2691ec 100644 (file)
@@ -63,8 +63,18 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
        filter_refs(&array, filter, FILTER_REFS_TAGS);
        ref_array_sort(sorting, &array);
 
-       for (i = 0; i < array.nr; i++)
-               show_ref_array_item(array.items[i], format);
+       for (i = 0; i < array.nr; i++) {
+               struct strbuf output = STRBUF_INIT;
+               struct strbuf err = STRBUF_INIT;
+
+               if (format_ref_array_item(array.items[i], format, &output, &err))
+                       die("%s", err.buf);
+               fwrite(output.buf, 1, output.len, stdout);
+               putchar('\n');
+
+               strbuf_release(&err);
+               strbuf_release(&output);
+       }
        ref_array_clear(&array);
        free(to_free);
 
index a0adb4551d870d99fe2c9a08412a9f57dee15117..e2eac50d9508ee6ea26d433e735774d48850aa83 100644 (file)
@@ -2435,27 +2435,22 @@ int format_ref_array_item(struct ref_array_item *info,
        return 0;
 }
 
-void show_ref_array_item(struct ref_array_item *info,
-                        const struct ref_format *format)
-{
-       struct strbuf final_buf = STRBUF_INIT;
-       struct strbuf error_buf = STRBUF_INIT;
-
-       if (format_ref_array_item(info, format, &final_buf, &error_buf))
-               die("%s", error_buf.buf);
-       fwrite(final_buf.buf, 1, final_buf.len, stdout);
-       strbuf_release(&error_buf);
-       strbuf_release(&final_buf);
-       putchar('\n');
-}
-
 void pretty_print_ref(const char *name, const struct object_id *oid,
                      const struct ref_format *format)
 {
        struct ref_array_item *ref_item;
+       struct strbuf output = STRBUF_INIT;
+       struct strbuf err = STRBUF_INIT;
+
        ref_item = new_ref_array_item(name, oid);
        ref_item->kind = ref_kind_from_refname(name);
-       show_ref_array_item(ref_item, format);
+       if (format_ref_array_item(ref_item, format, &output, &err))
+               die("%s", err.buf);
+       fwrite(output.buf, 1, output.len, stdout);
+       putchar('\n');
+
+       strbuf_release(&err);
+       strbuf_release(&output);
        free_array_item(ref_item);
 }
 
index 19ea4c413409373b809ba4822214a8a7c47b3e73..baf72a718965278fe75ef18fb6d5fb9610d86b32 100644 (file)
@@ -119,8 +119,6 @@ int format_ref_array_item(struct ref_array_item *info,
                          const struct ref_format *format,
                          struct strbuf *final_buf,
                          struct strbuf *error_buf);
-/*  Print the ref using the given format and quote_style */
-void show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
 /*  Parse a single sort specifier and add it to the list */
 void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
 /*  Callback function for parsing the sort option */