Skip to content

Commit ac4e58c

Browse files
john-caigitster
authored andcommitted
cat-file: introduce batch_mode enum to replace print_contents
A future patch introduces a new --batch-command flag. Including --batch and --batch-check, we will have a total of three batch modes. print_contents is the only boolean on the batch_options sturct used to distinguish between the different modes. This makes the code harder to read. To reduce potential confusion, replace print_contents with an enum to help readability and clarity. Helped-by: Junio C Hamano <[email protected]> Signed-off-by: John Cai <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2c7552 commit ac4e58c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

builtin/cat-file.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
#include "object-store.h"
1818
#include "promisor-remote.h"
1919

20+
enum batch_mode {
21+
BATCH_MODE_CONTENTS,
22+
BATCH_MODE_INFO,
23+
};
24+
2025
struct batch_options {
2126
int enabled;
2227
int follow_symlinks;
23-
int print_contents;
28+
enum batch_mode batch_mode;
2429
int buffer_output;
2530
int all_objects;
2631
int unordered;
@@ -386,7 +391,7 @@ static void batch_object_write(const char *obj_name,
386391
strbuf_addch(scratch, '\n');
387392
batch_write(opt, scratch->buf, scratch->len);
388393

389-
if (opt->print_contents) {
394+
if (opt->batch_mode == BATCH_MODE_CONTENTS) {
390395
print_object_or_die(opt, data);
391396
batch_write(opt, "\n", 1);
392397
}
@@ -536,7 +541,7 @@ static int batch_objects(struct batch_options *opt)
536541
* If we are printing out the object, then always fill in the type,
537542
* since we will want to decide whether or not to stream.
538543
*/
539-
if (opt->print_contents)
544+
if (opt->batch_mode == BATCH_MODE_CONTENTS)
540545
data.info.typep = &data.type;
541546

542547
if (opt->all_objects) {
@@ -635,7 +640,14 @@ static int batch_option_callback(const struct option *opt,
635640
}
636641

637642
bo->enabled = 1;
638-
bo->print_contents = !strcmp(opt->long_name, "batch");
643+
644+
if (!strcmp(opt->long_name, "batch"))
645+
bo->batch_mode = BATCH_MODE_CONTENTS;
646+
else if (!strcmp(opt->long_name, "batch-check"))
647+
bo->batch_mode = BATCH_MODE_INFO;
648+
else
649+
BUG("%s given to batch-option-callback", opt->long_name);
650+
639651
bo->format = arg;
640652

641653
return 0;

0 commit comments

Comments
 (0)