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

[PATCH 07/15] unpack-trees.c: assume submodules are clean

From
Sskimo@liacs.nl <skimo@liacs.nl>
Date
May 20, 2007, 18:04 UTC
Message-ID
<11796842892303-git-send-email-skimo@liacs.nl>
In-Reply-To
<11796842882917-git-send-email-skimo@liacs.nl>
From: Sven Verdoolaege <skimo@kotnet.org>

If the submodules are not clean, then we will get an error when we actally do the checkout.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
---
 unpack-trees.c |   43 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 4497a46..f3fe2dd 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -5,6 +5,7 @@
 #include "cache-tree.h"
 #include "unpack-trees.h"
 #include "progress.h"
+#include "refs.h"
 
 #define DBRT_DEBUG 1
 
@@ -430,11 +431,24 @@ static void invalidate_ce_path(struct cache_entry *ce)
 		cache_tree_invalidate_path(active_cache_tree, ce->name);
 }
 
-static int verify_clean_subdirectory(const char *path, const char *action,
+/* Check that checking out ce->sha1 in subdir ce->name is not
+ * going to overwrite any working files.
+ *
+ * FIXME: implement this function, so we can detect problems
+ *        early, rather than waiting until we actually try to checkout
+ *        the submodules.
+ */
+static int verify_clean_submodule(struct cache_entry *ce, const char *action,
+				      struct unpack_trees_options *o)
+{
+	return 0;
+}
+
+static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
 				      struct unpack_trees_options *o)
 {
 	/*
-	 * we are about to extract "path"; we would not want to lose
+	 * we are about to extract "ce->name"; we would not want to lose
 	 * anything in the existing directory there.
 	 */
 	int namelen;
@@ -442,13 +456,24 @@ static int verify_clean_subdirectory(const char *path, const char *action,
 	struct dir_struct d;
 	char *pathbuf;
 	int cnt = 0;
+	unsigned char sha1[20];
+
+	if (S_ISDIRLNK(ntohl(ce->ce_mode)) &&
+	    resolve_gitlink_ref(ce->name, "HEAD", sha1) == 0) {
+		/* If we are not going to update the submodule, then
+		 * we don't care.
+		 */
+		if (!o->submodules || !hashcmp(sha1, ce->sha1))
+			return 0;
+		verify_clean_submodule(ce, action, o);
+	}
 
 	/*
 	 * First let's make sure we do not have a local modification
 	 * in that directory.
 	 */
-	namelen = strlen(path);
-	pos = cache_name_pos(path, namelen);
+	namelen = strlen(ce->name);
+	pos = cache_name_pos(ce->name, namelen);
 	if (0 <= pos)
 		return cnt; /* we have it as nondirectory */
 	pos = -pos - 1;
@@ -456,7 +481,7 @@ static int verify_clean_subdirectory(const char *path, const char *action,
 		struct cache_entry *ce = active_cache[i];
 		int len = ce_namelen(ce);
 		if (len < namelen ||
-		    strncmp(path, ce->name, namelen) ||
+		    strncmp(ce->name, ce->name, namelen) ||
 		    ce->name[namelen] != '/')
 			break;
 		/*
@@ -474,16 +499,16 @@ static int verify_clean_subdirectory(const char *path, const char *action,
 	 * present file that is not ignored.
 	 */
 	pathbuf = xmalloc(namelen + 2);
-	memcpy(pathbuf, path, namelen);
+	memcpy(pathbuf, ce->name, namelen);
 	strcpy(pathbuf+namelen, "/");
 
 	memset(&d, 0, sizeof(d));
 	if (o->dir)
 		d.exclude_per_dir = o->dir->exclude_per_dir;
-	i = read_directory(&d, path, pathbuf, namelen+1, NULL);
+	i = read_directory(&d, ce->name, pathbuf, namelen+1, NULL);
 	if (i)
 		die("Updating '%s' would lose untracked files in it",
-		    path);
+		    ce->name);
 	free(pathbuf);
 	return cnt;
 }
@@ -517,7 +542,7 @@ static void verify_absent(struct cache_entry *ce, const char *action,
 			 * files that are in "foo/" we would lose
 			 * it.
 			 */
-			cnt = verify_clean_subdirectory(ce->name, action, o);
+			cnt = verify_clean_subdirectory(ce, action, o);
 
 			/*
 			 * If this removed entries from the index,
-- 
1.5.2.rc3.815.g8fc2
Previous: Sven VerdoolaegeNext: skimo@liacs.nl
Message 13 of 53 in “[RFC] Third round of support for cloning submodules”
  1. skimo@liacs.nlMay 20, 2007
  2. 01/15 Add dump-configskimo@liacs.nl, May 20, 2007
  3. 02/15 git-config: add --remote option for reading config from remote reposkimo@liacs.nl, May 20, 2007
  4. Frank LichtenheldMay 20, 2007
  5. Sven VerdoolaegeMay 20, 2007
  6. Frank LichtenheldMay 20, 2007
  7. 03/15 http.h: make fill_active_slots a function pointerskimo@liacs.nl, May 20, 2007
  8. 04/15 git-config: read remote config files over HTTPskimo@liacs.nl, May 20, 2007
  9. 05/15 unpack-trees.c: pass cache_entry * to verify_absent rather than just the nameskimo@liacs.nl, May 20, 2007
  10. 06/15 git-read-tree: take --submodules optionskimo@liacs.nl, May 20, 2007
  11. Martin WaitzMay 20, 2007
  12. Sven VerdoolaegeMay 20, 2007
  13. 07/15 unpack-trees.c: assume submodules are cleanskimo@liacs.nl, May 20, 2007
  14. 08/15 Add run_command_v_opt_cd: chdir into a directory before execskimo@liacs.nl, May 20, 2007
  15. 09/15 entry.c: optionally checkout submodulesskimo@liacs.nl, May 20, 2007
  16. Martin WaitzMay 20, 2007
  17. Sven VerdoolaegeMay 20, 2007
  18. Sven VerdoolaegeMay 24, 2007
  19. 10/15 git-checkout: pass --submodules option to git-read-treeskimo@liacs.nl, May 20, 2007
  20. 11/15 git-read-tree: treat null commit as empty treeskimo@liacs.nl, May 20, 2007
  21. 12/15 git_config: add void * for callback dataskimo@liacs.nl, May 20, 2007
  22. 13/15 unpack-trees.c: optionally clone submodules for later checkoutskimo@liacs.nl, May 20, 2007
  23. 14/15 entry.c: optionall checkout newly cloned submodulesskimo@liacs.nl, May 20, 2007
  24. 15/15 git-clone: add --submodules for cloning submodulesskimo@liacs.nl, May 20, 2007
  25. Junio C HamanoMay 20, 2007
  26. Sven VerdoolaegeMay 20, 2007
  27. Alex RiesenMay 20, 2007
  28. Sven VerdoolaegeMay 20, 2007
  29. Alex RiesenMay 20, 2007
  30. Sven VerdoolaegeMay 20, 2007
  31. Alex RiesenMay 20, 2007
  32. Sven VerdoolaegeMay 21, 2007
  33. Josef WeidendorferMay 21, 2007
  34. Martin WaitzMay 21, 2007
  35. Martin WaitzMay 20, 2007
  36. Alex RiesenMay 20, 2007
  37. Martin WaitzMay 20, 2007
  38. Alex RiesenMay 20, 2007
  39. Martin WaitzMay 20, 2007
  40. Alex RiesenMay 22, 2007
  41. Martin WaitzMay 24, 2007
  42. Steven GrimmMay 21, 2007
  43. Sven VerdoolaegeMay 21, 2007
  44. Alex RiesenMay 22, 2007
  45. Martin WaitzMay 20, 2007
  46. Alex RiesenMay 20, 2007
  47. Martin WaitzMay 20, 2007
  48. Martin WaitzMay 20, 2007
  49. Sven VerdoolaegeMay 21, 2007
  50. Martin WaitzMay 21, 2007
  51. Sven VerdoolaegeMay 21, 2007
  52. Martin WaitzMay 21, 2007
  53. Sven VerdoolaegeMay 21, 2007

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.