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

Re: tracking submodules out of main directory.

From
HGhenri GEIST <henri.geist@flying-robots.com>
Date
Jul 27, 2011, 18:49 UTC
Message-ID
<1311792580.2413.82.camel@Naugrim.eriador.com>
In-Reply-To
<4E0A08AE.8090407@web.de>
	Hello,

sorry for the delay but here is a patch to include the feature. I work with it and it full fill my needs.

In hope that some one else will find it useful.
	Henri GEIST
>From 09b7cda863c4443d11808f5b3f1a46ce05aa1e0d Mon Sep 17 00:00:00 2001
From: Henri GEIST <henri@flying-robots.com>
Date: Wed, 27 Jul 2011 20:16:13 +0200
Subject: [PATCH] Enabeling (sub)modules linking out of repository.

Depending on there workflow somme people needs to link there repository to depend on external modules. Just like library could be shared by different programme and other libraries. It's a mean to track dependency between source code projects.

In the current code it was not possible to add a gitlink to a repository outside of the main repository.

This pach :
  - Enable adding an external git directory.
  - Still forbid to add anything else.
  - Take care of prohibitting git to overright any data outside of the
    current directory.
  - Incrase some tests to validate the new feature.
This way you can have :
  - Project depending of multiple subprojects themselves depending on
    one third rank common suproject without clash at compilation
    linking.
  - Confidance that all suproject use the same version of the third rank
    subroject (git status will tell you.)
  - All subproject and subsubproject could be esealy worked on there one
    and synchronized after in the big project.
Signed-off-by: Henri GEIST <henri@flying-robots.com>
---
 builtin/clean.c       |    6 ++++--
 path.c                |   20 +++++++++++++++++---
 read-cache.c          |   14 ++++++++++++++
 setup.c               |   10 ++++++++--
 t/t0060-path-utils.sh |   16 ++++++++--------
 test-path-utils.c     |    6 ++++--
 6 files changed, 55 insertions(+), 17 deletions(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index 75697f7..e234e5d 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -149,8 +149,10 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 		if (S_ISDIR(st.st_mode)) {
 			strbuf_addstr(&directory, ent->name);
 			qname = quote_path_relative(directory.buf, directory.len, &buf, prefix);
-			if (show_only && (remove_directories ||
-			    (matches == MATCHED_EXACTLY))) {
+			if (!strncmp ("../", qname, 3)) {
+				die("'%s' is outside repository", qname);
+			} else if (show_only && (remove_directories ||
+				   (matches == MATCHED_EXACTLY))) {
 				printf(_("Would remove %s\n"), qname);
 			} else if (remove_directories ||
 				   (matches == MATCHED_EXACTLY)) {
diff --git a/path.c b/path.c
index 4d73cc9..daf1573 100644
--- a/path.c
+++ b/path.c
@@ -444,7 +444,8 @@ const char *relative_path(const char *abs, const char *base)
  * - Removes "." components.
  * - Removes ".." components, and the components the precede them.
  * Returns failure (non-zero) if a ".." component appears as first path
- * component anytime during the normalization. Otherwise, returns success (0).
+ * component but finish the normalization before.
+ * Otherwise, returns success (0).
  *
  * Note that this function is purely textual.  It does not follow symlinks,
  * verify the existence of the path, or make any system calls.
@@ -519,13 +520,26 @@ int normalize_path_copy(char *dst, const char *src)
 		 * go up one level.
 		 */
 		dst--;	/* go to trailing '/' */
-		if (dst <= dst0)
-			return -1;
+		if (dst <= dst0
+		    || (dst0 + 2 <= dst
+			&& dst[-1] == '.' && dst[-2] == '.'
+			&& (dst0 + 2 == dst || dst[-3] == '/'))) {
+			dst++;
+			*dst++ = '.';
+			*dst++ = '.';
+			*dst++ = '/';
+			continue;
+		}
 		/* Windows: dst[-1] cannot be backslash anymore */
 		while (dst0 < dst && dst[-1] != '/')
 			dst--;
 	}
 	*dst = '\0';
+	if (*dst0 == '/')
+		dst0++;
+	if (2 <= strlen (dst0)
+	    && dst0[0] == '.' && dst0[1] == '.' && dst0[2] == '/')
+		return -1;
 	return 0;
 }
 
diff --git a/read-cache.c b/read-cache.c
index 46a9e60..7fb695a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -753,6 +753,20 @@ static int verify_dotfile(const char *rest)
 int verify_path(const char *path)
 {
 	char c;
+	struct stat buf;
+
+	lstat (path, &buf);
+	if (buf.st_mode & S_IFDIR) {
+		for (;;) {
+			if (path[0] != '.')
+				break;
+			if (path[1] != '.')
+				break;
+			if (path[2] != '/')
+				break;
+			path += 3;
+		}
+	}
 
 	if (has_dos_drive_prefix(path))
 		return 0;
diff --git a/setup.c b/setup.c
index 5ea5502..ce7993e 100644
--- a/setup.c
+++ b/setup.c
@@ -8,6 +8,8 @@ char *prefix_path(const char *prefix, int len, const char *path)
 {
 	const char *orig = path;
 	char *sanitized;
+	struct stat buf;
+
 	if (is_absolute_path(orig)) {
 		const char *temp = real_path(path);
 		sanitized = xmalloc(len + strlen(temp) + 1);
@@ -18,8 +20,12 @@ char *prefix_path(const char *prefix, int len, const char *path)
 			memcpy(sanitized, prefix, len);
 		strcpy(sanitized + len, path);
 	}
-	if (normalize_path_copy(sanitized, sanitized))
-		goto error_out;
+	if (normalize_path_copy(sanitized, sanitized)) {
+		if (0 != lstat(sanitized, &buf))
+			goto error_out;
+		if (!(buf.st_mode & S_IFDIR))
+			goto error_out;
+	}
 	if (is_absolute_path(orig)) {
 		size_t root_len, len, total;
 		const char *work_tree = get_git_work_tree();
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 53cf1f8..b4b9b1f 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -48,12 +48,12 @@ norm_path "" ""
 norm_path . ""
 norm_path ./ ""
 norm_path ./. ""
-norm_path ./.. ++failed++
-norm_path ../. ++failed++
-norm_path ./../.// ++failed++
+norm_path ./.. "../ ++failed++"
+norm_path ../. "../ ++failed++"
+norm_path ./../.// "../ ++failed++"
 norm_path dir/.. ""
 norm_path dir/sub/../.. ""
-norm_path dir/sub/../../.. ++failed++
+norm_path dir/sub/../../.. "../ ++failed++"
 norm_path dir dir
 norm_path dir// dir/
 norm_path ./dir dir
@@ -73,12 +73,12 @@ norm_path // / POSIX
 norm_path /// / POSIX
 norm_path /. / POSIX
 norm_path /./ / POSIX
-norm_path /./.. ++failed++ POSIX
-norm_path /../. ++failed++ POSIX
-norm_path /./../.// ++failed++ POSIX
+norm_path /./.. "/../ ++failed++" POSIX
+norm_path /../. "/../ ++failed++" POSIX
+norm_path /./../.// "/../ ++failed++" POSIX
 norm_path /dir/.. / POSIX
 norm_path /dir/sub/../.. / POSIX
-norm_path /dir/sub/../../.. ++failed++ POSIX
+norm_path /dir/sub/../../.. "/../ ++failed++" POSIX
 norm_path /dir /dir POSIX
 norm_path /dir// /dir/ POSIX
 norm_path /./dir /dir POSIX
diff --git a/test-path-utils.c b/test-path-utils.c
index e767159..ba6c8ac 100644
--- a/test-path-utils.c
+++ b/test-path-utils.c
@@ -5,8 +5,10 @@ int main(int argc, char **argv)
 	if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
 		char *buf = xmalloc(PATH_MAX + 1);
 		int rv = normalize_path_copy(buf, argv[2]);
-		if (rv)
-			buf = "++failed++";
+		if (rv) {
+			fputs(buf, stdout);
+			buf = " ++failed++";
+		}
 		puts(buf);
 		return 0;
 	}
-- 
1.7.2.5
Previous: Jens LehmannNext: henri GEIST
Message 18 of 47 in “tracking submodules out of main directory.”
  1. henri GEISTJun 27, 2011
  2. Junio C HamanoJun 27, 2011
  3. Jens LehmannJun 27, 2011
  4. henri GEISTJun 27, 2011
  5. Jens LehmannJun 27, 2011
  6. henri GEISTJun 27, 2011
  7. Junio C HamanoJun 27, 2011
  8. Jens LehmannJun 27, 2011
  9. henri GEISTJun 27, 2011
  10. Jens LehmannJun 28, 2011
  11. henri GEISTJun 28, 2011
  12. henri GEISTJun 27, 2011
  13. Jens LehmannJun 28, 2011
  14. Jens LehmannJun 28, 2011
  15. henri GEISTJun 28, 2011
  16. Alexei SholikJun 28, 2011
  17. Jens LehmannJun 28, 2011
  18. henri GEISTJul 27, 2011
  19. henri GEISTJul 28, 2011
  20. Jens LehmannJul 28, 2011
  21. henri GEISTJul 29, 2011
  22. Jens LehmannJul 30, 2011
  23. henri GEISTJul 30, 2011
  24. Jens LehmannAug 1, 2011
  25. henri GEISTAug 2, 2011
  26. Jens LehmannAug 2, 2011
  27. Heiko VoigtAug 3, 2011
  28. henri GEISTAug 3, 2011
  29. Junio C HamanoAug 3, 2011
  30. Jens LehmannAug 3, 2011
  31. Junio C HamanoAug 3, 2011
  32. Jens LehmannAug 3, 2011
  33. henri GEISTAug 3, 2011
  34. Jens LehmannAug 4, 2011
  35. henri GEISTAug 5, 2011
  36. Heiko VoigtAug 4, 2011
  37. henri GEISTAug 5, 2011
  38. Heiko VoigtAug 3, 2011
  39. henri GEISTAug 3, 2011
  40. henri GEISTAug 3, 2011
  41. henri GEISTAug 3, 2011
  42. Heiko VoigtAug 1, 2011
  43. henri GEISTAug 2, 2011
  44. henri GEISTJun 27, 2011
  45. Jens LehmannJun 27, 2011
  46. henri GEISTJun 27, 2011
  47. henri GEISTAug 3, 2011

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.