@@ -98,7 +98,7 @@ static const char *common_list[] = {
9898 NULL
9999};
100100
101- static void update_common_dir (struct strbuf * buf , int git_dir_len )
101+ static void update_common_dir (struct strbuf * buf , int git_dir_len , const char * common_dir )
102102{
103103 char * base = buf -> buf + git_dir_len ;
104104 const char * * p ;
@@ -115,12 +115,16 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
115115 path ++ ;
116116 is_dir = 1 ;
117117 }
118+
119+ if (!common_dir )
120+ common_dir = get_git_common_dir ();
121+
118122 if (is_dir && dir_prefix (base , path )) {
119- replace_dir (buf , git_dir_len , get_git_common_dir () );
123+ replace_dir (buf , git_dir_len , common_dir );
120124 return ;
121125 }
122126 if (!is_dir && !strcmp (base , path )) {
123- replace_dir (buf , git_dir_len , get_git_common_dir () );
127+ replace_dir (buf , git_dir_len , common_dir );
124128 return ;
125129 }
126130 }
@@ -160,7 +164,7 @@ static void adjust_git_path(struct strbuf *buf, int git_dir_len)
160164 else if (git_db_env && dir_prefix (base , "objects" ))
161165 replace_dir (buf , git_dir_len + 7 , get_object_directory ());
162166 else if (git_common_dir_env )
163- update_common_dir (buf , git_dir_len );
167+ update_common_dir (buf , git_dir_len , NULL );
164168}
165169
166170static void do_git_path (struct strbuf * buf , const char * fmt , va_list args )
@@ -228,6 +232,8 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
228232 const char * fmt , va_list args )
229233{
230234 const char * git_dir ;
235+ struct strbuf git_submodule_common_dir = STRBUF_INIT ;
236+ struct strbuf git_submodule_dir = STRBUF_INIT ;
231237
232238 strbuf_addstr (buf , path );
233239 if (buf -> len && buf -> buf [buf -> len - 1 ] != '/' )
@@ -240,9 +246,17 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
240246 strbuf_addstr (buf , git_dir );
241247 }
242248 strbuf_addch (buf , '/' );
249+ strbuf_addstr (& git_submodule_dir , buf -> buf );
243250
244251 strbuf_vaddf (buf , fmt , args );
252+
253+ if (get_common_dir_noenv (& git_submodule_common_dir , git_submodule_dir .buf ))
254+ update_common_dir (buf , git_submodule_dir .len , git_submodule_common_dir .buf );
255+
245256 strbuf_cleanup_path (buf );
257+
258+ strbuf_release (& git_submodule_dir );
259+ strbuf_release (& git_submodule_common_dir );
246260}
247261
248262char * git_pathdup_submodule (const char * path , const char * fmt , ...)
0 commit comments