git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] archive.c: use OPT_BOOL()

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 27, 2011, 23:59 UTC
Message-ID
<7vy5x9tu4a.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7v39fhv8se.fsf@alter.siamese.dyndns.org>

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>
---
 * This is an example of "the remaining clean-up tasks" I mentioned.
 archive.c               |    4 ++--
 t/t5001-archive-attr.sh |    9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/archive.c b/archive.c
index 3fd7f47..2ae740a 100644
--- a/archive.c
+++ b/archive.c
@@ -318,7 +318,7 @@ static int parse_archive_args(int argc, const char **argv,
 			"prepend prefix to each pathname in the archive"),
 		OPT_STRING('o', "output", &output, "file",
 			"write the archive to this file"),
-		OPT_BOOLEAN(0, "worktree-attributes", &worktree_attributes,
+		OPT_BOOL(0, "worktree-attributes", &worktree_attributes,
 			"read .gitattributes in working directory"),
 		OPT__VERBOSE(&verbose, "report archived files on stderr"),
 		OPT__COMPR('0', &compression_level, "store only", 0),
@@ -332,7 +332,7 @@ static int parse_archive_args(int argc, const char **argv,
 		OPT__COMPR_HIDDEN('8', &compression_level, 8),
 		OPT__COMPR('9', &compression_level, "compress better", 9),
 		OPT_GROUP(""),
-		OPT_BOOLEAN('l', "list", &list,
+		OPT_BOOL('l', "list", &list,
 			"list supported archive formats"),
 		OPT_GROUP(""),
 		OPT_STRING(0, "remote", &remote, "repo",
diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh
index 02d4d22..f47d871 100755
--- a/t/t5001-archive-attr.sh
+++ b/t/t5001-archive-attr.sh
@@ -57,6 +57,15 @@ test_expect_missing	worktree/ignored
 test_expect_exists	worktree/ignored-by-tree
 test_expect_missing	worktree/ignored-by-worktree
 
+test_expect_success 'git archive --worktree-attributes option' '
+	git archive --worktree-attributes --worktree-attributes HEAD >worktree.tar &&
+	(mkdir worktree2 && cd worktree2 && "$TAR" xf -) <worktree.tar
+'
+
+test_expect_missing	worktree2/ignored
+test_expect_exists	worktree2/ignored-by-tree
+test_expect_missing	worktree2/ignored-by-worktree
+
 test_expect_success 'git archive vs. bare' '
 	(cd bare && git archive HEAD) >bare-archive.tar &&
 	test_cmp archive.tar bare-archive.tar
Previous: Junio C HamanoNext: Jeff King
Message 2 of 9 in “parse-options: deprecate OPT_BOOLEAN”
  1. parse-options: deprecate OPT_BOOLEANJunio C Hamano, Sep 27, 2011
  2. archive.c: use OPT_BOOL()Junio C Hamano, Sep 27, 2011
  3. Jeff KingSep 28, 2011
  4. Junio C HamanoSep 28, 2011
  5. Miles BaderSep 28, 2011
  6. 1/3 parseopt: add OPT_NOOP_NOARGRené Scharfe, Sep 28, 2011
  7. 2/3 revert: use OPT_NOOP_NOARGRené Scharfe, Sep 28, 2011
  8. 3/3 apply: use OPT_NOOP_NOARGRené Scharfe, Sep 28, 2011
  9. Junio C HamanoSep 28, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.