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

[PATCH 16/16] ls-files: add --overlay option

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 14, 2008, 13:08 UTC
Message-ID
<1221397685-27715-17-git-send-email-pclouds@gmail.com>
In-Reply-To
<1221397685-27715-16-git-send-email-pclouds@gmail.com>

Narrow checkout mode introduces an interesting case: some files are not to be checked out (marked CE_NO_CHECKOUT in index) but still exist in working directory. Those files will be ignored by Git unless explicitly specified. In Clearcase, these files are called "eclipsed". I would call them "overlay" for now. Any better term is welcome.

The same situation happens for "assume unchanged" bit, but I would expect narrow checkout to be more user-friendly and should notify users these cases so users will not be confused. On this first step, users may check by themselves with "git ls-files --overlay", further steps may make the information visible from "git status".

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-ls-files.txt |    4 ++++
 builtin-ls-files.c             |   16 +++++++++++++---
 t/t2104-update-index-narrow.sh |    4 ++++
 3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index 4f5a37e..9e749ef 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -56,6 +56,9 @@ OPTIONS
 --stage::
 	Show staged contents' object name, mode bits and stage number in the output.
 
+--overlay::
+	Show files that are marked no-checkout but exist in working directory.
+
 --directory::
 	If a whole directory is classified as "other", show just its
 	name (with a trailing slash) and not its whole contents.
@@ -122,6 +125,7 @@ OPTIONS
 	R::	removed/deleted
 	C::	modified/changed
 	K::	to be killed
+	!::	overlay files
 	?::	other
 
 -v::
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index f48a157..6e55207 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -20,6 +20,7 @@ static int show_others;
 static int show_stage;
 static int show_unmerged;
 static int show_modified;
+static int show_overlay;
 static int show_killed;
 static int show_valid_bit;
 static int narrow_checkout;
@@ -39,6 +40,7 @@ static const char *tag_removed = "";
 static const char *tag_other = "";
 static const char *tag_killed = "";
 static const char *tag_modified = "";
+static const char *tag_overlay = "";
 
 
 /*
@@ -256,7 +258,7 @@ static void show_files(struct dir_struct *dir, const char *prefix)
 			show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce);
 		}
 	}
-	if (show_deleted | show_modified) {
+	if (show_deleted | show_modified | show_overlay) {
 		for (i = 0; i < active_nr; i++) {
 			struct cache_entry *ce = active_cache[i];
 			struct stat st;
@@ -265,6 +267,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
 			if (excluded(dir, ce->name, &dtype) != dir->show_ignored)
 				continue;
 			err = lstat(ce->name, &st);
+			if (show_overlay && ce_no_checkout(ce) && !err)
+				show_ce_entry(tag_overlay, ce);
 			if (show_deleted && err && ce_checkout(ce))
 				show_ce_entry(tag_removed, ce);
 			if (show_modified && ce_modified(ce, &st, 0))
@@ -431,7 +435,7 @@ int report_path_error(const char *ps_matched, const char **pathspec, int prefix_
 }
 
 static const char ls_files_usage[] =
-	"git ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
+	"git ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified|overlay])* "
 	"[ --narrow-checkout ] [--narrow-match=<narrow_spec>] "
 	"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
 	"[ --exclude-per-directory=<filename> ] [--exclude-standard] "
@@ -466,6 +470,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 			tag_modified = "C ";
 			tag_other = "? ";
 			tag_killed = "K ";
+			tag_overlay = "! ";
 			if (arg[1] == 'v')
 				show_valid_bit = 1;
 			continue;
@@ -491,6 +496,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 			require_work_tree = 1;
 			continue;
 		}
+		if (!strcmp(arg, "--overlay")) {
+			show_overlay = 1;
+			require_work_tree = 1;
+			continue;
+		}
 		if (!strcmp(arg, "-o") || !strcmp(arg, "--others")) {
 			show_others = 1;
 			require_work_tree = 1;
@@ -610,7 +620,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 
 	/* With no flags, we default to showing the cached files */
 	if (!(show_stage | show_deleted | show_others | show_unmerged |
-	      show_killed | show_modified))
+	      show_killed | show_modified | show_overlay))
 		show_cached = 1;
 
 	if (narrow_checkout && !show_cached && !show_stage)
diff --git a/t/t2104-update-index-narrow.sh b/t/t2104-update-index-narrow.sh
index 1a3acdd..79da418 100755
--- a/t/t2104-update-index-narrow.sh
+++ b/t/t2104-update-index-narrow.sh
@@ -31,6 +31,10 @@ test_expect_success 'ls-files --deleted ignores no-checkout entries' '
 	touch 1
 '
 
+test_expect_success 'there are overlay entries' '
+	test "$(git ls-files --overlay|grep 1|wc -l)" = 2
+'
+
 test_expect_success 'update-index --checkout' '
 	git update-index --checkout 1 sub/1 &&
 	test "$(git ls-files)" = "$(git ls-files --narrow-checkout)"'
-- 
1.6.0.96.g2fad1.dirty
Previous: Nguyễn Thái Ngọc DuyNext: Jakub Narebski
Message 17 of 35 in “Narrow/Partial/Sparse checkout”
  1. 00/16 Narrow/Partial/Sparse checkoutNguyễn Thái Ngọc Duy, Sep 14, 2008
  2. 01/16 Extend index to save more flagsNguyễn Thái Ngọc Duy, Sep 14, 2008
  3. 02/16 Introduce CE_NO_CHECKOUT bitNguyễn Thái Ngọc Duy, Sep 14, 2008
  4. 03/16 update-index: refactor mark_valid() in preparation for new optionsNguyễn Thái Ngọc Duy, Sep 14, 2008
  5. 04/16 update-index: add --checkout/--no-checkout to update CE_NO_CHECKOUT bitNguyễn Thái Ngọc Duy, Sep 14, 2008
  6. 05/16 ls-files: add --narrow-checkout option to "will checkout" entriesNguyễn Thái Ngọc Duy, Sep 14, 2008
  7. 06/16 Add tests for updating no-checkout entries in indexNguyễn Thái Ngọc Duy, Sep 14, 2008
  8. 07/16 Prevent diff machinery from examining worktree outside narrow checkoutNguyễn Thái Ngọc Duy, Sep 14, 2008
  9. 08/16 checkout_entry(): CE_NO_CHECKOUT on checked out entries.Nguyễn Thái Ngọc Duy, Sep 14, 2008
  10. 09/16 ls-files: apply --deleted on narrow area onlyNguyễn Thái Ngọc Duy, Sep 14, 2008
  11. 10/16 grep: skip files that have not been checked outNguyễn Thái Ngọc Duy, Sep 14, 2008
  12. 11/16 unpack_trees(): add support for narrow checkoutNguyễn Thái Ngọc Duy, Sep 14, 2008
  13. 12/16 narrow spec: put '+' before a spec will change semantic of '*'Nguyễn Thái Ngọc Duy, Sep 14, 2008
  14. 13/16 ls-files: add --narrow-match=spec option for testing narrow matchingNguyễn Thái Ngọc Duy, Sep 14, 2008
  15. 14/16 clone: support narrow checkout with --path optionNguyễn Thái Ngọc Duy, Sep 14, 2008
  16. 15/16 checkout: add new options to support narrow checkoutNguyễn Thái Ngọc Duy, Sep 14, 2008
  17. 16/16 ls-files: add --overlay optionNguyễn Thái Ngọc Duy, Sep 14, 2008
  18. Jakub NarebskiSep 14, 2008
  19. Junio C HamanoSep 15, 2008
  20. Nguyen Thai Ngoc DuySep 16, 2008
  21. Junio C HamanoSep 16, 2008
  22. Jakub NarebskiSep 14, 2008
  23. BazSep 16, 2008
  24. Johannes SixtSep 16, 2008
  25. Nguyen Thai Ngoc DuySep 16, 2008
  26. Jakub NarebskiSep 14, 2008
  27. Junio C HamanoSep 15, 2008
  28. Jakub NarebskiSep 14, 2008
  29. Junio C HamanoSep 15, 2008
  30. Nguyen Thai Ngoc DuySep 16, 2008
  31. Jakub NarebskiSep 14, 2008
  32. Junio C HamanoSep 15, 2008
  33. Jakub NarebskiSep 14, 2008
  34. Junio C HamanoSep 15, 2008
  35. Jakub NarebskiSep 14, 2008

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.