Skip to content

Commit 5d96bcb

Browse files
committed
Merge branch 'zh/cat-file-batch-fix'
"git cat-file --batch-all-objects"" misbehaved when "--batch" is in use and did not ask for certain object traits. * zh/cat-file-batch-fix: cat-file: merge two block into one cat-file: handle trivial --batch format with --batch-all-objects
2 parents d486ca6 + ee02ac6 commit 5d96bcb

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

builtin/cat-file.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,6 @@ static int batch_objects(struct batch_options *opt)
512512
if (opt->cmdmode)
513513
data.split_on_whitespace = 1;
514514

515-
if (opt->all_objects) {
516-
struct object_info empty = OBJECT_INFO_INIT;
517-
if (!memcmp(&data.info, &empty, sizeof(empty)))
518-
data.skip_object_info = 1;
519-
}
520-
521515
/*
522516
* If we are printing out the object, then always fill in the type,
523517
* since we will want to decide whether or not to stream.
@@ -527,6 +521,10 @@ static int batch_objects(struct batch_options *opt)
527521

528522
if (opt->all_objects) {
529523
struct object_cb_data cb;
524+
struct object_info empty = OBJECT_INFO_INIT;
525+
526+
if (!memcmp(&data.info, &empty, sizeof(empty)))
527+
data.skip_object_info = 1;
530528

531529
if (has_promisor_remote())
532530
warning("This repository uses promisor remotes. Some objects may not be loaded.");

t/t1006-cat-file.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,4 +586,26 @@ test_expect_success 'cat-file --unordered works' '
586586
test_cmp expect actual
587587
'
588588

589+
test_expect_success 'set up object list for --batch-all-objects tests' '
590+
git -C all-two cat-file --batch-all-objects --batch-check="%(objectname)" >objects
591+
'
592+
593+
test_expect_success 'cat-file --batch="%(objectname)" with --batch-all-objects will work' '
594+
git -C all-two cat-file --batch="%(objectname)" <objects >expect &&
595+
git -C all-two cat-file --batch-all-objects --batch="%(objectname)" >actual &&
596+
cmp expect actual
597+
'
598+
599+
test_expect_success 'cat-file --batch="%(rest)" with --batch-all-objects will work' '
600+
git -C all-two cat-file --batch="%(rest)" <objects >expect &&
601+
git -C all-two cat-file --batch-all-objects --batch="%(rest)" >actual &&
602+
cmp expect actual
603+
'
604+
605+
test_expect_success 'cat-file --batch="batman" with --batch-all-objects will work' '
606+
git -C all-two cat-file --batch="batman" <objects >expect &&
607+
git -C all-two cat-file --batch-all-objects --batch="batman" >actual &&
608+
cmp expect actual
609+
'
610+
589611
test_done

0 commit comments

Comments
 (0)