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

Re: [PATCH 2/2] ls-files: fix broken --no-empty-directory

From
Jeff King <peff@peff.net>
Date
Mar 10, 2009, 19:11 UTC
Message-ID
<20090310191111.GA27662@sigill.intra.peff.net>
In-Reply-To
<20090308211312.GE4371@genesis.frugalware.org>
On Sun, Mar 08, 2009 at 10:13:12PM +0100, Miklos Vajna wrote:
Show 9 quoted lines
> > +		OPT_BIT(0, "no-empty-directory", &dir.flags,
> > +			"don't show empty directories",
> >  			DIR_HIDE_EMPTY_DIRECTORIES),
> >  		OPT_BOOLEAN('u', "unmerged", &show_unmerged,
> >  			"show unmerged files in the output"),
> 
> Thanks for catching this. But then why not using PARSE_OPT_NONEG?
> 
> That would avoid --no-no-empty-directory.

I think either we don't care about negation, in which case it is not hurting anybody to support --no-no-empty-directory, or we do, in which case you actually want to do the negation properly. Which would be something like:

diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 437c366..2c5f7a5 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -427,6 +427,7 @@ static int option_parse_exclude_standard(const struct option *opt,
 int cmd_ls_files(int argc, const char **argv, const char *prefix)
 {
 	int require_work_tree = 0, show_tag = 0;
+	int show_empty_directories = 1;
 	struct dir_struct dir;
 	struct option builtin_ls_files_options[] = {
 		{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
@@ -454,9 +455,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "directory", &dir.flags,
 			"show 'other' directories' name only",
 			DIR_SHOW_OTHER_DIRECTORIES),
-		OPT_BIT(0, "no-empty-directory", &dir.flags,
-			"don't show empty directories",
-			DIR_HIDE_EMPTY_DIRECTORIES),
+		OPT_BOOLEAN(0, "empty-directory", &show_empty_directories,
+			"show empty directories (on by default)"),
 		OPT_BOOLEAN('u', "unmerged", &show_unmerged,
 			"show unmerged files in the output"),
 		{ OPTION_CALLBACK, 'x', "exclude", &dir.exclude_list[EXC_CMDL], "pattern",
@@ -506,6 +506,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 		show_stage = 1;
 	if (dir.exclude_per_dir)
 		exc_given = 1;
+	if (!show_empty_directories)
+		dir.flags |= DIR_HIDE_EMPTY_DIRECTORIES;
 
 	if (require_work_tree && !is_inside_work_tree())
 		setup_work_tree();


which is even still a little confusing, as you get "--empty-directory"
in the usage message. But you would almost never want to use that, as it
is already the default.

-Peff
Previous: Miklos VajnaNext: Miklos Vajna
Message 5 of 6 in “fix ls-files parseopt regression”
  1. 0/2 fix ls-files parseopt regressionJeff King, Mar 8, 2009
  2. 1/2 t3000: use test_cmp instead of diffJeff King, Mar 8, 2009
  3. 2/2 ls-files: fix broken --no-empty-directoryJeff King, Mar 8, 2009
  4. Miklos VajnaMar 8, 2009
  5. Jeff KingMar 10, 2009
  6. Miklos VajnaMar 10, 2009

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.