Skip to content

Commit f858c64

Browse files
committed
archive.c: use OPT_BOOL()
The list variable (which is OPT_BOOLEAN) is initialized to 0 and only checked against 0 in the code, so it is safe to use OPT_BOOL(). The worktree_attributes variable (which is OPT_BOOLEAN) is initialized to 0 and later assigned to a field with the same name in struct archive_args, which is a bitfield of width 1. It is safe and even more correct to use OPT_BOOL() here; the new test in 5001 demonstrates why using OPT_COUNTUP is wrong. Signed-off-by: Junio C Hamano <[email protected]>
1 parent b04ba2b commit f858c64

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

archive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static int parse_archive_args(int argc, const char **argv,
318318
"prepend prefix to each pathname in the archive"),
319319
OPT_STRING('o', "output", &output, "file",
320320
"write the archive to this file"),
321-
OPT_BOOLEAN(0, "worktree-attributes", &worktree_attributes,
321+
OPT_BOOL(0, "worktree-attributes", &worktree_attributes,
322322
"read .gitattributes in working directory"),
323323
OPT__VERBOSE(&verbose, "report archived files on stderr"),
324324
OPT__COMPR('0', &compression_level, "store only", 0),
@@ -332,7 +332,7 @@ static int parse_archive_args(int argc, const char **argv,
332332
OPT__COMPR_HIDDEN('8', &compression_level, 8),
333333
OPT__COMPR('9', &compression_level, "compress better", 9),
334334
OPT_GROUP(""),
335-
OPT_BOOLEAN('l', "list", &list,
335+
OPT_BOOL('l', "list", &list,
336336
"list supported archive formats"),
337337
OPT_GROUP(""),
338338
OPT_STRING(0, "remote", &remote, "repo",

t/t5001-archive-attr.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ test_expect_missing worktree/ignored
5757
test_expect_exists worktree/ignored-by-tree
5858
test_expect_missing worktree/ignored-by-worktree
5959

60+
test_expect_success 'git archive --worktree-attributes option' '
61+
git archive --worktree-attributes --worktree-attributes HEAD >worktree.tar &&
62+
(mkdir worktree2 && cd worktree2 && "$TAR" xf -) <worktree.tar
63+
'
64+
65+
test_expect_missing worktree2/ignored
66+
test_expect_exists worktree2/ignored-by-tree
67+
test_expect_missing worktree2/ignored-by-worktree
68+
6069
test_expect_success 'git archive vs. bare' '
6170
(cd bare && git archive HEAD) >bare-archive.tar &&
6271
test_cmp archive.tar bare-archive.tar

0 commit comments

Comments
 (0)