From: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>, "Junio C Hamano" <gitster@pobox.com>,
"Christian Couder" <chriscool@tuxfamily.org>,
"Hariom Verma" <hariom18599@gmail.com>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Derrick Stolee" <stolee@gmail.com>,
"René Scharfe" <l.s.r@web.de>,
"ZheNing Hu" <adlternative@gmail.com>,
"ZheNing Hu" <adlternative@gmail.com>
Subject: [PATCH v2 1/2] [GSOC] ref-filter: get rid of show_ref_array_item
Date: Tue, 20 Apr 2021 16:52:10 +0000 [thread overview]
Message-ID: <7e378eef4b3405777eef9c0e9fe4e9e4ec6a1df9.1618937532.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.935.v2.git.1618937532.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>
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>
---
builtin/for-each-ref.c | 14 ++++++++++++--
builtin/tag.c | 14 ++++++++++++--
ref-filter.c | 25 ++++++++++---------------
ref-filter.h | 2 --
4 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index cb9c81a04606..8520008604e3 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -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;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index d403417b5625..d92d8e110b4d 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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);
diff --git a/ref-filter.c b/ref-filter.c
index f0bd32f71416..df67047fd615 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -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);
}
diff --git a/ref-filter.h b/ref-filter.h
index 19ea4c413409..baf72a718965 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -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 */
--
gitgitgadget
next prev parent reply other threads:[~2021-04-20 16:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-19 11:28 [PATCH 0/2] [GSOC] ref-filter: reuse output buffer ZheNing Hu via GitGitGadget
2021-04-19 11:28 ` [PATCH 1/2] [GSOC] ref-filter: get rid of show_ref_array_item ZheNing Hu via GitGitGadget
2021-04-19 20:54 ` Junio C Hamano
2021-04-19 11:28 ` [PATCH 2/2] [GSOC] ref-filter: reuse output buffer ZheNing Hu via GitGitGadget
2021-04-19 21:04 ` Junio C Hamano
2021-04-20 6:05 ` ZheNing Hu
2021-04-20 16:52 ` [PATCH v2 0/2] " ZheNing Hu via GitGitGadget
2021-04-20 16:52 ` ZheNing Hu via GitGitGadget [this message]
2021-04-20 16:52 ` [PATCH v2 2/2] " ZheNing Hu via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7e378eef4b3405777eef9c0e9fe4e9e4ec6a1df9.1618937532.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=adlternative@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hariom18599@gmail.com \
--cc=l.s.r@web.de \
--cc=peff@peff.net \
--cc=stolee@gmail.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).