Multiple worktrees vs. submodules fixes
v3 cover Multiple worktrees vs. submodules fixes
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(-)
Signature · 1 line
2.2.0.50.gb2b6831
PATCH v3 1/3 submodule refactor: use git_path_submodule() in add_submodule_odb()
--- submodule.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)
submodule.c +10 -18
@@ -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; }
Signature · 1 line
2.2.0.50.gb2b6831
PATCH v3 2/3 path: implement common_dir handling in git_path_submodule()
In reply to Max KirillovThis 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.
--- cache.h | 1 + path.c | 24 ++++++++++++++++++++---- setup.c | 17 ++++++++++++----- t/t7410-submodule-checkout-to.sh | 10 ++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-)
cache.h +1 -0
@@ -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);
path.c +20 -4
@@ -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; }
setup.c +12 -5
@@ -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 )
t/t7410-submodule-checkout-to.sh +10 -0
@@ -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
Signature · 1 line
2.2.0.50.gb2b6831
PATCH v3 3/3 Add GIT_COMMON_DIR to local_repo_env
In reply to Max KirillovThis is obviously right thing to do, because submodule repository does not use common directory of super repository.
--- environment.c | 1 + 1 file changed, 1 insertion(+)
environment.c +1 -0
@@ -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,
Signature · 1 line
2.2.0.50.gb2b6831
Quoted 12 lines · 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.
* AddedGIT_COMMON_DIRtolocal_repo_env. While it is obviously a right thing, I wasn't able to observe any change in behavior.Max Kirillov (3):
submodule refactor: usegit_path_submodule()inadd_submodule_odb()
path: implementcommon_dirhandling ingit_path_submodule()AddGIT_COMMON_DIRtolocal_repo_env
Quoted 11 lines
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(-)Signature · 1 line
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
Signature · 1 line
Max