Skip to content

Commit 54d2f0d

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ced9fff commit 54d2f0d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

builtin/cat-file.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ static int batch_unordered_packed(const struct object_id *oid,
466466

467467
static int batch_objects(struct batch_options *opt)
468468
{
469-
struct strbuf buf = STRBUF_INIT;
469+
struct strbuf input = STRBUF_INIT;
470+
struct strbuf output = STRBUF_INIT;
470471
struct expand_data data;
471472
int save_warning;
472473
int retval = 0;
@@ -481,8 +482,9 @@ static int batch_objects(struct batch_options *opt)
481482
*/
482483
memset(&data, 0, sizeof(data));
483484
data.mark_query = 1;
484-
strbuf_expand(&buf, opt->format, expand_format, &data);
485+
strbuf_expand(&output, opt->format, expand_format, &data);
485486
data.mark_query = 0;
487+
strbuf_release(&output);
486488
if (opt->cmdmode)
487489
data.split_on_whitespace = 1;
488490

@@ -542,25 +544,25 @@ static int batch_objects(struct batch_options *opt)
542544
save_warning = warn_on_object_refname_ambiguity;
543545
warn_on_object_refname_ambiguity = 0;
544546

545-
while (strbuf_getline(&buf, stdin) != EOF) {
547+
while (strbuf_getline(&input, stdin) != EOF) {
546548
if (data.split_on_whitespace) {
547549
/*
548550
* Split at first whitespace, tying off the beginning
549551
* of the string and saving the remainder (or NULL) in
550552
* data.rest.
551553
*/
552-
char *p = strpbrk(buf.buf, " \t");
554+
char *p = strpbrk(input.buf, " \t");
553555
if (p) {
554556
while (*p && strchr(" \t", *p))
555557
*p++ = '\0';
556558
}
557559
data.rest = p;
558560
}
559561

560-
batch_one_object(buf.buf, opt, &data);
562+
batch_one_object(input.buf, opt, &data);
561563
}
562564

563-
strbuf_release(&buf);
565+
strbuf_release(&input);
564566
warn_on_object_refname_ambiguity = save_warning;
565567
return retval;
566568
}

0 commit comments

Comments
 (0)