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 <gitster@pobox.com>

Junio C Hamano committed Sep 27, 2011 at 16:59 UTC f858c646b5428519c4f847c5f15a9ead72a62b16
2 files changed +11 -2
archive.c
+2 -2
@@ -318,7 +318,7 @@ static int parse_archive_args(int argc, const char **argv,
318 "prepend prefix to each pathname in the archive"),
319 OPT_STRING('o', "output", &output, "file",
320 "write the archive to this file"),
321 - OPT_BOOLEAN(0, "worktree-attributes", &worktree_attributes,
321 + OPT_BOOL(0, "worktree-attributes", &worktree_attributes,
322 "read .gitattributes in working directory"),
323 OPT__VERBOSE(&verbose, "report archived files on stderr"),
324 OPT__COMPR('0', &compression_level, "store only", 0),
@@ -332,7 +332,7 @@ static int parse_archive_args(int argc, const char **argv,
332 OPT__COMPR_HIDDEN('8', &compression_level, 8),
333 OPT__COMPR('9', &compression_level, "compress better", 9),
334 OPT_GROUP(""),
335 - OPT_BOOLEAN('l', "list", &list,
335 + OPT_BOOL('l', "list", &list,
336 "list supported archive formats"),
337 OPT_GROUP(""),
338 OPT_STRING(0, "remote", &remote, "repo",
t/t5001-archive-attr.sh
+9
@@ -57,6 +57,15 @@ test_expect_missing worktree/ignored
57 test_expect_exists worktree/ignored-by-tree
58 test_expect_missing worktree/ignored-by-worktree
59
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 +
69 test_expect_success 'git archive vs. bare' '
70 (cd bare && git archive HEAD) >bare-archive.tar &&
71 test_cmp archive.tar bare-archive.tar