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

Re: [PATCH 1/3] Fix sparse checkout not removing files from index

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Jul 31, 2010, 03:48 UTC
Message-ID
<AANLkTi=HGqwg1HUMej-NeYgCf2454erOo1EYp7z-LT1D@mail.gmail.com>
In-Reply-To
<20100731033339.GB1607@burratino>
On Sat, Jul 31, 2010 at 1:33 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 6 quoted lines
> Nguyen Thai Ngoc Duy wrote:
>
>> maybe we should move the CE_UPDATE/CE_WT_REMOVE removal code into
>> apply_sparse_checkout().
>
> Not a bad idea regardless.

Yeah, something like this, perhaps. It's not tested. I'll repost the patch later, incorporating all your suggestions.

diff --git a/unpack-trees.c b/unpack-trees.c
index f2d148c..48654b3 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -153,6 +153,26 @@ static int apply_sparse_checkout(struct
cache_entry *ce, struct unpack_trees_opt
 		ce->ce_flags &= ~CE_SKIP_WORKTREE;

 	/*
+	 * Merge strategies may set CE_UPDATE|CE_REMOVE outside checkout
+	 * area as a result of ce_skip_worktree() shortcuts in
+	 * verify_absent() and verify_uptodate().
+	 * Make sure they don't modify worktree if they are already
+	 * outside checkout area
+	 */
+	if (was_skip_worktree && ce_skip_worktree(ce)) {
+		ce->ce_flags &= ~CE_UPDATE;
+
+		/*
+		 * By default, when CE_REMOVE is on, CE_WT_REMOVE is also
+		 * on to get that file removed from both index and worktree.
+		 * If that file is already outside worktree area, don't
+		 * bother remove it.
+		 */
+		if (ce->ce_flags & CE_REMOVE)
+			ce->ce_flags &= ~CE_WT_REMOVE;
+	}
+
+	/*
 	 * We only care about files getting into the checkout area
 	 * If merge strategies want to remove some, go ahead, this
 	 * flag will be removed eventually in unpack_trees() if it's
@@ -793,19 +813,7 @@ int unpack_trees(unsigned len, struct tree_desc
*t, struct unpack_trees_options
 				ret = -1;
 				goto done;
 			}
-			/*
-			 * Merge strategies may set CE_UPDATE|CE_REMOVE outside checkout
-			 * area as a result of ce_skip_worktree() shortcuts in
-			 * verify_absent() and verify_uptodate().
-			 * Make sure they don't modify worktree.
-			 */
-			if (ce_skip_worktree(ce)) {
-				ce->ce_flags &= ~CE_UPDATE;
-
-				if (ce->ce_flags & CE_REMOVE)
-					ce->ce_flags &= ~CE_WT_REMOVE;
-			}
-			else
+			if (!ce_skip_worktree(ce))
 				empty_worktree = 0;

 		}
-- 
Duy
Previous: Jonathan Nieder
Message 17 of 17 in “Fix sparse checkout not removing files from index”
  1. 1/3 Fix sparse checkout not removing files from indexNguyễn Thái Ngọc Duy, Jul 26, 2010
  2. 2/3 unpack-trees.c: Do not check ce_stage in will_have_skip_worktree()Nguyễn Thái Ngọc Duy, Jul 26, 2010
  3. Jonathan NiederJul 31, 2010
  4. Nguyen Thai Ngoc DuyJul 31, 2010
  5. 3/3 Mark new entries skip-worktree appropriatelyNguyễn Thái Ngọc Duy, Jul 26, 2010
  6. Jonathan NiederJul 31, 2010
  7. Nguyen Thai Ngoc DuyJul 31, 2010
  8. Jonathan NiederJul 31, 2010
  9. Jonathan NiederJul 30, 2010
  10. Nguyen Thai Ngoc DuyJul 30, 2010
  11. Jonathan NiederJul 30, 2010
  12. Jonathan NiederJul 31, 2010
  13. 1/2 t1011 (sparse checkout): style nitpicksJonathan Nieder, Jul 31, 2010
  14. 2/2 read-tree -m -u: always remove relevant files when narrowing checkoutJonathan Nieder, Jul 31, 2010
  15. Nguyen Thai Ngoc DuyJul 31, 2010
  16. Jonathan NiederJul 31, 2010
  17. Nguyen Thai Ngoc DuyJul 31, 2010

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.