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>
Jeff King committed
Aug 14, 2018 at 14:18 UTC
54d2f0d945abac2d8a8a1bcc258db937e597189e
1 file changed
+8
-6
builtin/cat-file.c
+8
-6
@@ -466,7 +466,8 @@ static int batch_unordered_packed(const struct object_id *oid,
466
467
static int batch_objects(struct batch_options *opt)
468
{
469
- struct strbuf buf = STRBUF_INIT;
469
+ struct strbuf input = STRBUF_INIT;
470
+ struct strbuf output = STRBUF_INIT;
471
struct expand_data data;
472
int save_warning;
473
int retval = 0;
@@ -481,8 +482,9 @@ static int batch_objects(struct batch_options *opt)
482
*/
483
memset(&data, 0, sizeof(data));
484
data.mark_query = 1;
484
- strbuf_expand(&buf, opt->format, expand_format, &data);
485
+ strbuf_expand(&output, opt->format, expand_format, &data);
486
data.mark_query = 0;
487
+ strbuf_release(&output);
488
if (opt->cmdmode)
489
data.split_on_whitespace = 1;
490
@@ -542,14 +544,14 @@ static int batch_objects(struct batch_options *opt)
544
save_warning = warn_on_object_refname_ambiguity;
545
warn_on_object_refname_ambiguity = 0;
546
545
- while (strbuf_getline(&buf, stdin) != EOF) {
547
+ while (strbuf_getline(&input, stdin) != EOF) {
548
if (data.split_on_whitespace) {
549
/*
550
* Split at first whitespace, tying off the beginning
551
* of the string and saving the remainder (or NULL) in
552
* data.rest.
553
*/
552
- char *p = strpbrk(buf.buf, " \t");
554
+ char *p = strpbrk(input.buf, " \t");
555
if (p) {
556
while (*p && strchr(" \t", *p))
557
*p++ = '\0';
@@ -557,10 +559,10 @@ static int batch_objects(struct batch_options *opt)
559
data.rest = p;
560
}
561
560
- batch_one_object(buf.buf, opt, &data);
562
+ batch_one_object(input.buf, opt, &data);
563
}
564
563
- strbuf_release(&buf);
565
+ strbuf_release(&input);
566
warn_on_object_refname_ambiguity = save_warning;
567
return retval;
568
}