All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] Multiple worktrees vs. submodules fixes
@ 2014-12-09  4:44 Max Kirillov
  2014-12-09  4:44 ` [PATCH v3 1/3] submodule refactor: use git_path_submodule() in add_submodule_odb() Max Kirillov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Max Kirillov @ 2014-12-09  4:44 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, Jens Lehmann
  Cc: Junio C Hamano, git, Max Kirillov

After discussions I came to basically same as v1.

* Resubmitting the 2 patches which have not been taken to worktrees reroll -
  they fix visible issue. Mostly unchanged except small cleanup in test.
* Added GIT_COMMON_DIR to local_repo_env. While it is obviously a right
  thing, I wasn't able to observe any change in behavior.

Max Kirillov (3):
  submodule refactor: use git_path_submodule() in add_submodule_odb()
  path: implement common_dir handling in git_path_submodule()
  Add GIT_COMMON_DIR to local_repo_env

 cache.h                          |  1 +
 environment.c                    |  1 +
 path.c                           | 24 ++++++++++++++++++++----
 setup.c                          | 17 ++++++++++++-----
 submodule.c                      | 28 ++++++++++------------------
 t/t7410-submodule-checkout-to.sh | 10 ++++++++++
 6 files changed, 54 insertions(+), 27 deletions(-)

-- 
2.2.0.50.gb2b6831

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/3] submodule refactor: use git_path_submodule() in add_submodule_odb()
  2014-12-09  4:44 [PATCH v3 0/3] Multiple worktrees vs. submodules fixes Max Kirillov
@ 2014-12-09  4:44 ` Max Kirillov
  2014-12-09  4:44 ` [PATCH v3 2/3] path: implement common_dir handling in git_path_submodule() Max Kirillov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Max Kirillov @ 2014-12-09  4:44 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, Jens Lehmann
  Cc: Junio C Hamano, git, Max Kirillov

Signed-off-by: Max Kirillov <max@max630.net>
---
 submodule.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/submodule.c b/submodule.c
index 34094f5..4aad3d4 100644
--- a/submodule.c
+++ b/submodule.c
@@ -122,43 +122,35 @@ void stage_updated_gitmodules(void)
 
 static int add_submodule_odb(const char *path)
 {
-	struct strbuf objects_directory = STRBUF_INIT;
 	struct alternate_object_database *alt_odb;
+	const char* objects_directory;
 	int ret = 0;
-	const char *git_dir;
 
-	strbuf_addf(&objects_directory, "%s/.git", path);
-	git_dir = read_gitfile(objects_directory.buf);
-	if (git_dir) {
-		strbuf_reset(&objects_directory);
-		strbuf_addstr(&objects_directory, git_dir);
-	}
-	strbuf_addstr(&objects_directory, "/objects/");
-	if (!is_directory(objects_directory.buf)) {
+	objects_directory = git_path_submodule(path, "objects/");
+	if (!is_directory(objects_directory)) {
 		ret = -1;
 		goto done;
 	}
+
 	/* avoid adding it twice */
 	for (alt_odb = alt_odb_list; alt_odb; alt_odb = alt_odb->next)
-		if (alt_odb->name - alt_odb->base == objects_directory.len &&
-				!strncmp(alt_odb->base, objects_directory.buf,
-					objects_directory.len))
+		if (alt_odb->name - alt_odb->base == strlen(objects_directory) &&
+				!strcmp(alt_odb->base, objects_directory))
 			goto done;
 
-	alt_odb = xmalloc(objects_directory.len + 42 + sizeof(*alt_odb));
+	alt_odb = xmalloc(strlen(objects_directory) + 42 + sizeof(*alt_odb));
 	alt_odb->next = alt_odb_list;
-	strcpy(alt_odb->base, objects_directory.buf);
-	alt_odb->name = alt_odb->base + objects_directory.len;
+	strcpy(alt_odb->base, objects_directory);
+	alt_odb->name = alt_odb->base + strlen(objects_directory);
 	alt_odb->name[2] = '/';
 	alt_odb->name[40] = '\0';
 	alt_odb->name[41] = '\0';
 	alt_odb_list = alt_odb;
 
 	/* add possible alternates from the submodule */
-	read_info_alternates(objects_directory.buf, 0);
+	read_info_alternates(objects_directory, 0);
 	prepare_alt_odb();
 done:
-	strbuf_release(&objects_directory);
 	return ret;
 }
 
-- 
2.2.0.50.gb2b6831

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/3] path: implement common_dir handling in git_path_submodule()
  2014-12-09  4:44 [PATCH v3 0/3] Multiple worktrees vs. submodules fixes Max Kirillov
  2014-12-09  4:44 ` [PATCH v3 1/3] submodule refactor: use git_path_submodule() in add_submodule_odb() Max Kirillov
@ 2014-12-09  4:44 ` Max Kirillov
  2014-12-09  4:44 ` [PATCH v3 3/3] Add GIT_COMMON_DIR to local_repo_env Max Kirillov
  2014-12-09  5:04 ` [PATCH v3 0/3] Multiple worktrees vs. submodules fixes Max Kirillov
  3 siblings, 0 replies; 5+ messages in thread
From: Max Kirillov @ 2014-12-09  4:44 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, Jens Lehmann
  Cc: Junio C Hamano, git, Max Kirillov

This allows making submodules a linked workdirs.

Same as for .git, but ignores the GIT_COMMON_DIR environment variable,
because it would mean common directory for the parent repository and
does not make sense for submodule.

Also add test for functionality which uses this call.

Signed-off-by: Max Kirillov <max@max630.net>
---
 cache.h                          |  1 +
 path.c                           | 24 ++++++++++++++++++++----
 setup.c                          | 17 ++++++++++++-----
 t/t7410-submodule-checkout-to.sh | 10 ++++++++++
 4 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/cache.h b/cache.h
index 3f60a11..e8f465a 100644
--- a/cache.h
+++ b/cache.h
@@ -437,6 +437,7 @@ extern char *get_object_directory(void);
 extern char *get_index_file(void);
 extern char *get_graft_file(void);
 extern int set_git_dir(const char *path);
+extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
 extern int get_common_dir(struct strbuf *sb, const char *gitdir);
 extern const char *get_git_namespace(void);
 extern const char *strip_namespace(const char *namespaced_ref);
diff --git a/path.c b/path.c
index a5c51a3..78f718f 100644
--- a/path.c
+++ b/path.c
@@ -98,7 +98,7 @@ static const char *common_list[] = {
 	NULL
 };
 
-static void update_common_dir(struct strbuf *buf, int git_dir_len)
+static void update_common_dir(struct strbuf *buf, int git_dir_len, const char* common_dir)
 {
 	char *base = buf->buf + git_dir_len;
 	const char **p;
@@ -115,12 +115,17 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
 			path++;
 			is_dir = 1;
 		}
+
+		if (!common_dir) {
+			common_dir = get_git_common_dir();
+		}
+
 		if (is_dir && dir_prefix(base, path)) {
-			replace_dir(buf, git_dir_len, get_git_common_dir());
+			replace_dir(buf, git_dir_len, common_dir);
 			return;
 		}
 		if (!is_dir && !strcmp(base, path)) {
-			replace_dir(buf, git_dir_len, get_git_common_dir());
+			replace_dir(buf, git_dir_len, common_dir);
 			return;
 		}
 	}
@@ -160,7 +165,7 @@ static void adjust_git_path(struct strbuf *buf, int git_dir_len)
 	else if (git_db_env && dir_prefix(base, "objects"))
 		replace_dir(buf, git_dir_len + 7, get_object_directory());
 	else if (git_common_dir_env)
-		update_common_dir(buf, git_dir_len);
+		update_common_dir(buf, git_dir_len, NULL);
 }
 
 static void do_git_path(struct strbuf *buf, const char *fmt, va_list args)
@@ -256,6 +261,8 @@ const char *git_path_submodule(const char *path, const char *fmt, ...)
 {
 	struct strbuf *buf = get_pathname();
 	const char *git_dir;
+	struct strbuf git_submodule_common_dir = STRBUF_INIT;
+	struct strbuf git_submodule_dir = STRBUF_INIT;
 	va_list args;
 
 	strbuf_addstr(buf, path);
@@ -269,11 +276,20 @@ const char *git_path_submodule(const char *path, const char *fmt, ...)
 		strbuf_addstr(buf, git_dir);
 	}
 	strbuf_addch(buf, '/');
+	strbuf_addstr(&git_submodule_dir, buf->buf);
 
 	va_start(args, fmt);
 	strbuf_vaddf(buf, fmt, args);
 	va_end(args);
+
+	if (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf)) {
+		update_common_dir(buf, git_submodule_dir.len, git_submodule_common_dir.buf);
+	}
+
 	strbuf_cleanup_path(buf);
+
+	strbuf_release(&git_submodule_dir);
+	strbuf_release(&git_submodule_common_dir);
 	return buf->buf;
 }
 
diff --git a/setup.c b/setup.c
index 05a8955..45e90c4 100644
--- a/setup.c
+++ b/setup.c
@@ -226,14 +226,21 @@ void verify_non_filename(const char *prefix, const char *arg)
 
 int get_common_dir(struct strbuf *sb, const char *gitdir)
 {
+	const char *git_env_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
+	if (git_env_common_dir) {
+		strbuf_addstr(sb, git_env_common_dir);
+		return 1;
+	} else {
+		return get_common_dir_noenv(sb, gitdir);
+	}
+}
+
+int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)
+{
 	struct strbuf data = STRBUF_INIT;
 	struct strbuf path = STRBUF_INIT;
-	const char *git_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
 	int ret = 0;
-	if (git_common_dir) {
-		strbuf_addstr(sb, git_common_dir);
-		return 1;
-	}
+
 	strbuf_addf(&path, "%s/commondir", gitdir);
 	if (file_exists(path.buf)) {
 		if (strbuf_read_file(&data, path.buf, 0) <= 0)
diff --git a/t/t7410-submodule-checkout-to.sh b/t/t7410-submodule-checkout-to.sh
index 8f30aed..b43391a 100755
--- a/t/t7410-submodule-checkout-to.sh
+++ b/t/t7410-submodule-checkout-to.sh
@@ -47,4 +47,14 @@ test_expect_success 'checkout main and initialize independed clones' \
 test_expect_success 'can see submodule diffs after independed cloning' \
     '(cd fully_cloned_submodule/main && git diff --submodule master"^!" | grep "file1 updated")'
 
+test_expect_success 'checkout sub manually' \
+    'mkdir linked_submodule &&
+    (cd clone/main &&
+	git checkout --to "$base_path/linked_submodule/main" "$rev1_hash_main") &&
+    (cd clone/main/sub &&
+	git checkout --to "$base_path/linked_submodule/main/sub" "$rev1_hash_sub")'
+
+test_expect_success 'can see submodule diffs after manual checkout of linked submodule' \
+    '(cd linked_submodule/main && git diff --submodule master"^!" | grep "file1 updated")'
+
 test_done
-- 
2.2.0.50.gb2b6831

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/3] Add GIT_COMMON_DIR to local_repo_env
  2014-12-09  4:44 [PATCH v3 0/3] Multiple worktrees vs. submodules fixes Max Kirillov
  2014-12-09  4:44 ` [PATCH v3 1/3] submodule refactor: use git_path_submodule() in add_submodule_odb() Max Kirillov
  2014-12-09  4:44 ` [PATCH v3 2/3] path: implement common_dir handling in git_path_submodule() Max Kirillov
@ 2014-12-09  4:44 ` Max Kirillov
  2014-12-09  5:04 ` [PATCH v3 0/3] Multiple worktrees vs. submodules fixes Max Kirillov
  3 siblings, 0 replies; 5+ messages in thread
From: Max Kirillov @ 2014-12-09  4:44 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, Jens Lehmann
  Cc: Junio C Hamano, git, Max Kirillov

This is obviously right thing to do, because submodule repository does
not use common directory of super repository.

Suggested-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Max Kirillov <max@max630.net>
---
 environment.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/environment.c b/environment.c
index 8351007..85ce3c4 100644
--- a/environment.c
+++ b/environment.c
@@ -94,6 +94,7 @@ const char * const local_repo_env[] = {
 	CONFIG_DATA_ENVIRONMENT,
 	DB_ENVIRONMENT,
 	GIT_DIR_ENVIRONMENT,
+	GIT_COMMON_DIR_ENVIRONMENT,
 	GIT_WORK_TREE_ENVIRONMENT,
 	GIT_IMPLICIT_WORK_TREE_ENVIRONMENT,
 	GRAFT_ENVIRONMENT,
-- 
2.2.0.50.gb2b6831

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/3] Multiple worktrees vs. submodules fixes
  2014-12-09  4:44 [PATCH v3 0/3] Multiple worktrees vs. submodules fixes Max Kirillov
                   ` (2 preceding siblings ...)
  2014-12-09  4:44 ` [PATCH v3 3/3] Add GIT_COMMON_DIR to local_repo_env Max Kirillov
@ 2014-12-09  5:04 ` Max Kirillov
  3 siblings, 0 replies; 5+ messages in thread
From: Max Kirillov @ 2014-12-09  5:04 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy, Jens Lehmann; +Cc: Junio C Hamano, git

On Tue, Dec 09, 2014 at 06:44:40AM +0200, Max Kirillov wrote:
> After discussions I came to basically same as v1.
> 
> * Resubmitting the 2 patches which have not been taken to worktrees reroll -
>   they fix visible issue. Mostly unchanged except small cleanup in test.
> * Added GIT_COMMON_DIR to local_repo_env. While it is obviously a right
>   thing, I wasn't able to observe any change in behavior.
> 
> Max Kirillov (3):
>   submodule refactor: use git_path_submodule() in add_submodule_odb()
>   path: implement common_dir handling in git_path_submodule()
>   Add GIT_COMMON_DIR to local_repo_env
> 
>  cache.h                          |  1 +
>  environment.c                    |  1 +
>  path.c                           | 24 ++++++++++++++++++++----
>  setup.c                          | 17 ++++++++++++-----
>  submodule.c                      | 28 ++++++++++------------------
>  t/t7410-submodule-checkout-to.sh | 10 ++++++++++
>  6 files changed, 54 insertions(+), 27 deletions(-)
> 
> -- 
> 2.2.0.50.gb2b6831
>

Should be applied on top of
http://thread.gmane.org/gmane.comp.version-control.git/260387
with _all_ patches included, currently it's df56607dff

-- 
Max

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-12-09  5:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-09  4:44 [PATCH v3 0/3] Multiple worktrees vs. submodules fixes Max Kirillov
2014-12-09  4:44 ` [PATCH v3 1/3] submodule refactor: use git_path_submodule() in add_submodule_odb() Max Kirillov
2014-12-09  4:44 ` [PATCH v3 2/3] path: implement common_dir handling in git_path_submodule() Max Kirillov
2014-12-09  4:44 ` [PATCH v3 3/3] Add GIT_COMMON_DIR to local_repo_env Max Kirillov
2014-12-09  5:04 ` [PATCH v3 0/3] Multiple worktrees vs. submodules fixes Max Kirillov

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.