summaryrefslogtreecommitdiff
path: root/builtin/cat-file.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-08-14 18:18:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-14 19:29:00 (GMT)
commit54d2f0d945abac2d8a8a1bcc258db937e597189e (patch)
tree8db9ac90885729339f488d429c3f7f6fed96ba09 /builtin/cat-file.c
parentced9fff75dad2578d7583ba3085970b03c66c57b (diff)
downloadgit-54d2f0d945abac2d8a8a1bcc258db937e597189e.zip
git-54d2f0d945abac2d8a8a1bcc258db937e597189e.tar.gz
git-54d2f0d945abac2d8a8a1bcc258db937e597189e.tar.bz2
cat-file: split batch "buf" into two variables
We use the "buf" strbuf for two things: to read incoming lines, and as a scratch space for test-expanding the user-provided format. Let's split this into two variables with descriptive names, which makes their purpose and lifetime more clear. It will also help in a future patch when we start using the "output" buffer for more expansions. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/cat-file.c')
-rw-r--r--builtin/cat-file.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 04b5cda..3ed1d0b 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -466,7 +466,8 @@ static int batch_unordered_packed(const struct object_id *oid,
static int batch_objects(struct batch_options *opt)
{
- struct strbuf buf = STRBUF_INIT;
+ struct strbuf input = STRBUF_INIT;
+ struct strbuf output = STRBUF_INIT;
struct expand_data data;
int save_warning;
int retval = 0;
@@ -481,8 +482,9 @@ static int batch_objects(struct batch_options *opt)
*/
memset(&data, 0, sizeof(data));
data.mark_query = 1;
- strbuf_expand(&buf, opt->format, expand_format, &data);
+ strbuf_expand(&output, opt->format, expand_format, &data);
data.mark_query = 0;
+ strbuf_release(&output);
if (opt->cmdmode)
data.split_on_whitespace = 1;
@@ -542,14 +544,14 @@ static int batch_objects(struct batch_options *opt)
save_warning = warn_on_object_refname_ambiguity;
warn_on_object_refname_ambiguity = 0;
- while (strbuf_getline(&buf, stdin) != EOF) {
+ while (strbuf_getline(&input, stdin) != EOF) {
if (data.split_on_whitespace) {
/*
* Split at first whitespace, tying off the beginning
* of the string and saving the remainder (or NULL) in
* data.rest.
*/
- char *p = strpbrk(buf.buf, " \t");
+ char *p = strpbrk(input.buf, " \t");
if (p) {
while (*p && strchr(" \t", *p))
*p++ = '\0';
@@ -557,10 +559,10 @@ static int batch_objects(struct batch_options *opt)
data.rest = p;
}
- batch_one_object(buf.buf, opt, &data);
+ batch_one_object(input.buf, opt, &data);
}
- strbuf_release(&buf);
+ strbuf_release(&input);
warn_on_object_refname_ambiguity = save_warning;
return retval;
}