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

[PATCH 00/21] nd/list-files updates

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 8, 2015, 09:01 UTC
Message-ID
<1423386099-19994-1-git-send-email-pclouds@gmail.com>
- 02/21: fix a bug that ignores config keys if $LS_COLORS is not defined
- 09/21: use listFiles instead of list-files in config keys
- 17/21: incorporate match_pathspec changes from Junio,
    use strbuf_swap in show_as_directory()
- 21/21: use test_decode_color and test_when_finished in t3080
Full diff of changes is
-- 8< --
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 74da715..2dc4788 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -940,7 +940,7 @@ color.status.<slot>::
 	to red). The values of these variables may be specified as in
 	color.branch.<slot>.
 
-color.list-files::
+color.listFiles::
 	A boolean to enable/disable color in the output of
 	linkgit:git-list-files[1]. May be set to `always`, `false` (or
 	`never`) or `auto` (or `true`), in which case colors are used
@@ -1018,7 +1018,7 @@ column.clean::
 	Specify the layout when list items in `git clean -i`, which always
 	shows files and directories in columns. See `column.ui` for details.
 
-column.list-files::
+column.listFiles::
 	Specify whether to output tag listing in `git list-files` in columns.
 	See `column.ui` for details.
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b04c712..b5e1a59 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -229,8 +229,8 @@ static int show_as_directory(const struct cache_entry *ce)
 		if (want_color(use_color)) {
 			struct strbuf sb3 = STRBUF_INIT;
 			color_filename(&sb3, ce->name, sb2.buf, S_IFDIR, 1);
-			strbuf_release(&sb2);
-			sb2 = sb3;
+			strbuf_swap(&sb2, &sb3);
+			strbuf_release(&sb3);
 		}
 		if (show_tag)
 			strbuf_insert(&sb2, 0, tag_cached, strlen(tag_cached));
@@ -258,33 +258,41 @@ static void write_ce_name(struct strbuf *sb, const struct cache_entry *ce)
 	strbuf_release(&quoted);
 }
 
+static int match_pathspec_with_depth(struct pathspec *ps,
+				     const char *name, int namelen,
+				     int prefix, char *seen, int is_dir,
+				     const int *custom_depth)
+{
+	int saved_depth = ps->max_depth;
+	int result;
+
+	if (custom_depth)
+		ps->max_depth = *custom_depth;
+	result = match_pathspec(ps, name, namelen, prefix, seen, is_dir);
+	if (custom_depth)
+		ps->max_depth = saved_depth;
+	return result;
+}
+
 static void show_ce_entry(const char *tag, const struct cache_entry *ce)
 {
 	static struct strbuf sb = STRBUF_INIT;
-	int len = max_prefix_len, saved_max_depth;
+	static const int infinite_depth = -1;
+	int len = max_prefix_len;
 
 	if (len >= ce_namelen(ce))
 		die("git ls-files: internal error - cache entry not superset of prefix");
 
-	if (show_dirs) {
-		/* ignore depth to catch dirs that contain matched entries */
-		saved_max_depth = pathspec.max_depth;
-		pathspec.max_depth = -1;
-	}
-
-	if (!match_pathspec(&pathspec, ce->name, ce_namelen(ce),
-			    len, ps_matched,
-			    S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)))
+	if (!match_pathspec_with_depth(&pathspec, ce->name, ce_namelen(ce),
+				       len, ps_matched,
+				       S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode),
+				       show_dirs ? &infinite_depth : NULL))
 		return;
 
-	if (show_dirs) {
-		pathspec.max_depth = saved_max_depth;
-		if (strchr(ce->name, '/') &&
-		    !match_pathspec(&pathspec, ce->name, ce_namelen(ce),
-				    prefix_len, NULL, 1) &&
-		    show_as_directory(ce))
-			return;
-	}
+	if (show_dirs &&strchr(ce->name, '/') &&
+	    !match_pathspec(&pathspec, ce->name, ce_namelen(ce), prefix_len, NULL, 1) &&
+	    show_as_directory(ce))
+		return;
 
 	if (tag && *tag && show_valid_bit &&
 	    (ce->ce_flags & CE_VALID)) {
@@ -697,8 +705,8 @@ static int option_parse_exclude_standard(const struct option *opt,
 static int git_ls_config(const char *var, const char *value, void *cb)
 {
 	if (starts_with(var, "column."))
-		return git_column_config(var, value, "list-files", &colopts);
-	if (!strcmp(var, "color.list-files")) {
+		return git_column_config(var, value, "listfiles", &colopts);
+	if (!strcmp(var, "color.listfiles")) {
 		use_color = git_config_colorbool(var, value);
 		return 0;
 	}
diff --git a/ls_colors.c b/ls_colors.c
index 9259ad3..011a8b9 100644
--- a/ls_colors.c
+++ b/ls_colors.c
@@ -326,8 +326,10 @@ void parse_ls_color(void)
 	char *start;
 	size_t len;
 
-	if ((p = getenv("LS_COLORS")) == NULL || *p == '\0')
+	if ((p = getenv("LS_COLORS")) == NULL || *p == '\0') {
+		git_config(ls_colors_config, NULL);
 		return;
+	}
 
 	ext = NULL;
 	strcpy(label, "??");
diff --git a/t/t3080-list-files.sh b/t/t3080-list-files.sh
index 6313dd9..01b9662 100755
--- a/t/t3080-list-files.sh
+++ b/t/t3080-list-files.sh
@@ -15,16 +15,26 @@ test_expect_success 'setup' '
 
 test_expect_success 'LS_COLORS env variable' '
 	LS_COLORS="rs=0:fi=31:di=32" \
-		git list-files --color=always | grep -v gitlink >actual &&
-	test_cmp "$TEST_DIRECTORY"/t3080/ls_colors actual
+		git list-files --color=always | test_decode_color | \
+		grep -v gitlink >actual &&
+	cat >expected <<-\EOF &&
+	<GREEN>dir<RESET>
+	<RED>file<RESET>
+	EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'color.ls.*' '
 	test_config color.ls.file red &&
 	test_config color.ls.directory green &&
 	test_config color.ls.submodule yellow &&
-	git list-files --color=always >actual &&
-	test_cmp "$TEST_DIRECTORY"/t3080/color_ls actual
+	git list-files --color=always | test_decode_color >actual &&
+	cat >expected <<-\EOF &&
+	<GREEN>dir<RESET>
+	<RED>file<RESET>
+	<YELLOW>gitlink<RESET>
+	EOF
+	test_cmp expected actual
 '
 
 test_expect_success 'column output' '
@@ -78,6 +88,7 @@ test_expect_success 'globbing' '
 '
 
 test_expect_success 'no dups' '
+	test_when_finished "git checkout file" &&
 	echo dirty >>file &&
 	git list-files -m file >actual &&
 	echo "file" >expected &&
@@ -100,6 +111,7 @@ test_expect_success '--classify' '
 '
 
 test_expect_success 'diff-cached' '
+	test_when_finished "git checkout file" &&
 	echo dirty >>file &&
 	git add file &&
 	git list-files -M >actual &&
diff --git a/t/t3080/color_ls b/t/t3080/color_ls
deleted file mode 100644
index 47f77ad..0000000
--- a/t/t3080/color_ls
+++ /dev/null
@@ -1,3 +0,0 @@
-dir
-file
-gitlink
diff --git a/t/t3080/ls_colors b/t/t3080/ls_colors
deleted file mode 100644
index 423c016..0000000
--- a/t/t3080/ls_colors
+++ /dev/null
@@ -1,2 +0,0 @@
-dir
-file
-- 8< --
-- 
2.3.0.rc1.137.g477eb31
Next: Nguyễn Thái Ngọc Duy
Message 1 of 23 in “nd/list-files updates”
  1. 00/21 nd/list-files updatesNguyễn Thái Ngọc Duy, Feb 8, 2015
  2. 01/21 ls_colors.c: add $LS_COLORS parsing codeNguyễn Thái Ngọc Duy, Feb 8, 2015
  3. 02/21 ls_colors.c: parse color.ls.* from config fileNguyễn Thái Ngọc Duy, Feb 8, 2015
  4. 03/21 ls_colors.c: add a function to color a file nameNguyễn Thái Ngọc Duy, Feb 8, 2015
  5. 04/21 ls_colors.c: highlight submodules like directoriesNguyễn Thái Ngọc Duy, Feb 8, 2015
  6. 05/21 ls-files: buffer full item in strbuf before printingNguyễn Thái Ngọc Duy, Feb 8, 2015
  7. 06/21 ls-files: add --color to highlight file namesNguyễn Thái Ngọc Duy, Feb 8, 2015
  8. 07/21 ls-files: add --columnNguyễn Thái Ngọc Duy, Feb 8, 2015
  9. 08/21 ls-files: support --max-depthNguyễn Thái Ngọc Duy, Feb 8, 2015
  10. 09/21 list-files: a user friendly version of ls-files and moreNguyễn Thái Ngọc Duy, Feb 8, 2015
  11. 10/21 list-files: make alias 'ls' default to 'list-files'Nguyễn Thái Ngọc Duy, Feb 8, 2015
  12. 11/21 list-files: -u does not imply showing stagesNguyễn Thái Ngọc Duy, Feb 8, 2015
  13. 12/21 list-files: add -R/--recursive short for --max-depth=-1Nguyễn Thái Ngọc Duy, Feb 8, 2015
  14. 13/21 list-files: add -1 short for --no-columnNguyễn Thái Ngọc Duy, Feb 8, 2015
  15. 14/21 list-files: add -t backNguyễn Thái Ngọc Duy, Feb 8, 2015
  16. 15/21 list-files: sort output and remove duplicatesNguyễn Thái Ngọc Duy, Feb 8, 2015
  17. 16/21 list-files: do not show duplicate cached entriesNguyễn Thái Ngọc Duy, Feb 8, 2015
  18. 17/21 list-files: show directories as well as filesNguyễn Thái Ngọc Duy, Feb 8, 2015
  19. Junio C HamanoFeb 9, 2015
  20. 18/21 list-files: add -F/--classifyNguyễn Thái Ngọc Duy, Feb 8, 2015
  21. 19/21 list-files -F: show submodules with the new indicator '&'Nguyễn Thái Ngọc Duy, Feb 8, 2015
  22. 20/21 list-files: -M aka diff-cachedNguyễn Thái Ngọc Duy, Feb 8, 2015
  23. 21/21 t3080: tests for git-list-filesNguyễn Thái Ngọc Duy, Feb 8, 2015

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.