cat-file: split batch "buf" into two variables
authorJeff King <peff@peff.net>
Tue, 14 Aug 2018 18:18:06 +0000 (14:18 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Aug 2018 19:29:00 +0000 (12:29 -0700)
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>
builtin/cat-file.c
index 04b5cda191804ce9727a1a01901c88222fb69535..3ed1d0be806c488647e9c85579813b72b5e7016b 100644 (file)
@@ -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;
 }