All of lore.kernel.org
 help / color / mirror / Atom feed
From: henri GEIST <henri.geist@flying-robots.com>
To: Jens Lehmann <Jens.Lehmann@web.de>
Cc: Alexei Sholik <alcosholik@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org, Sverre Rabbelier <srabbelier@gmail.com>
Subject: Re: tracking submodules out of main directory.
Date: Thu, 28 Jul 2011 10:57:45 +0200	[thread overview]
Message-ID: <1311843465.3734.40.camel@Naugrim.eriador.com> (raw)
In-Reply-To: <1311792580.2413.82.camel@Naugrim.eriador.com>

	Hello,

The same with some orthographique corrections by
Sverre Rabbelier <srabbelier@gmail.com> (unofficial)


>From 9a4e10fbb884583638c1651cc6cb98e0ce59cb9b Mon Sep 17 00:00:00 2001
From: Henri GEIST <henri@flying-robots.com>
Date: Thu, 28 Jul 2011 10:15:55 +0200
Subject: [PATCH] Enabeling (sub)modules linking out of repository.

Depending on there workflow some people needs to link there repository
to depend on external modules.
Just like library could be shared by different program and other libraries.
It's a means 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 :
  - Enables adding an external git directory.
  - Still forbids to add anything else.
  - Takes care of prohibitting git to overwrite any data outside of the
    current directory.
  - Increase 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 clashing at compilation
    linking.
  - Confidence that all suproject use the same version of the third rank
    subproject (git status will tell you.)
  - All subproject and subsubproject could be easily 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

  reply	other threads:[~2011-07-28  8:54 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-27 13:07 tracking submodules out of main directory henri GEIST
2011-06-27 16:51 ` Junio C Hamano
2011-06-27 18:14   ` Jens Lehmann
2011-06-27 18:52     ` henri GEIST
2011-06-27 18:56       ` Jens Lehmann
2011-06-27 21:18         ` henri GEIST
2011-06-27 19:05     ` Junio C Hamano
2011-06-27 19:40       ` Jens Lehmann
2011-06-27 21:57         ` henri GEIST
2011-06-28  7:25           ` Jens Lehmann
2011-06-28 11:55             ` henri GEIST
2011-06-27 21:51       ` henri GEIST
2011-06-28  7:20         ` Jens Lehmann
2011-06-28  7:37           ` Jens Lehmann
2011-06-28 11:52           ` henri GEIST
2011-06-28 10:05       ` Alexei Sholik
2011-06-28 17:00         ` Jens Lehmann
2011-07-27 18:49           ` henri GEIST
2011-07-28  8:57             ` henri GEIST [this message]
2011-07-28 16:48               ` Jens Lehmann
2011-07-29  9:39                 ` henri GEIST
2011-07-30 14:16                   ` Jens Lehmann
2011-07-30 21:55                     ` henri GEIST
2011-08-01 19:39                       ` Jens Lehmann
2011-08-02 12:19                         ` henri GEIST
2011-08-02 18:42                           ` Jens Lehmann
2011-08-03  6:25                             ` Heiko Voigt
2011-08-03 12:26                               ` henri GEIST
2011-08-03 17:11                                 ` Junio C Hamano
2011-08-03 19:07                                   ` Jens Lehmann
2011-08-03 19:41                                     ` Junio C Hamano
2011-08-03 21:30                                       ` Jens Lehmann
2011-08-03 22:29                                         ` henri GEIST
2011-08-04 17:45                                           ` Jens Lehmann
2011-08-05  0:29                                             ` henri GEIST
2011-08-04 20:05                                           ` Heiko Voigt
2011-08-05  2:19                                             ` henri GEIST
2011-08-03 21:45                                     ` Heiko Voigt
2011-08-03 22:41                                       ` henri GEIST
2011-08-03 21:49                                     ` henri GEIST
2011-08-03 21:04                                   ` henri GEIST
2011-08-01 22:12                   ` Heiko Voigt
2011-08-02 12:58                     ` henri GEIST
     [not found]                       ` <CAJsNXT=93FHjbi42JKA3Pg7PGXs0kEONJ5AC5SSPpa5RSVqB=A@mail.gmail.com>
2011-08-03  9:07                         ` henri GEIST
2011-06-27 18:40   ` henri GEIST
2011-06-27 19:02     ` Jens Lehmann
2011-06-27 21:45       ` henri GEIST

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311843465.3734.40.camel@Naugrim.eriador.com \
    --to=henri.geist@flying-robots.com \
    --cc=Jens.Lehmann@web.de \
    --cc=alcosholik@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=srabbelier@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.