Skip to content

Commit 49d3c4b

Browse files
SyntevoAlexgitster
authored andcommitted
get_superproject_working_tree(): return strbuf
Together with the previous commits, this commit fully fixes the problem of using shared buffer for `real_path()` in `get_superproject_working_tree()`. Signed-off-by: Alexandr Miloslavskiy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4530a85 commit 49d3c4b

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

builtin/rev-parse.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
808808
continue;
809809
}
810810
if (!strcmp(arg, "--show-superproject-working-tree")) {
811-
const char *superproject = get_superproject_working_tree();
812-
if (superproject)
813-
puts(superproject);
811+
struct strbuf superproject = STRBUF_INIT;
812+
if (get_superproject_working_tree(&superproject))
813+
puts(superproject.buf);
814+
strbuf_release(&superproject);
814815
continue;
815816
}
816817
if (!strcmp(arg, "--show-prefix")) {

submodule.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,14 +2168,13 @@ void absorb_git_dir_into_superproject(const char *path,
21682168
}
21692169
}
21702170

2171-
const char *get_superproject_working_tree(void)
2171+
int get_superproject_working_tree(struct strbuf *buf)
21722172
{
2173-
static struct strbuf realpath = STRBUF_INIT;
21742173
struct child_process cp = CHILD_PROCESS_INIT;
21752174
struct strbuf sb = STRBUF_INIT;
21762175
struct strbuf one_up = STRBUF_INIT;
21772176
const char *cwd = xgetcwd();
2178-
const char *ret = NULL;
2177+
int ret = 0;
21792178
const char *subpath;
21802179
int code;
21812180
ssize_t len;
@@ -2186,10 +2185,10 @@ const char *get_superproject_working_tree(void)
21862185
* We might have a superproject, but it is harder
21872186
* to determine.
21882187
*/
2189-
return NULL;
2188+
return 0;
21902189

21912190
if (!strbuf_realpath(&one_up, "../", 0))
2192-
return NULL;
2191+
return 0;
21932192

21942193
subpath = relative_path(cwd, one_up.buf, &sb);
21952194
strbuf_release(&one_up);
@@ -2233,8 +2232,8 @@ const char *get_superproject_working_tree(void)
22332232
super_wt = xstrdup(cwd);
22342233
super_wt[cwd_len - super_sub_len] = '\0';
22352234

2236-
strbuf_realpath(&realpath, super_wt, 1);
2237-
ret = realpath.buf;
2235+
strbuf_realpath(buf, super_wt, 1);
2236+
ret = 1;
22382237
free(super_wt);
22392238
}
22402239
strbuf_release(&sb);
@@ -2243,10 +2242,10 @@ const char *get_superproject_working_tree(void)
22432242

22442243
if (code == 128)
22452244
/* '../' is not a git repository */
2246-
return NULL;
2245+
return 0;
22472246
if (code == 0 && len == 0)
22482247
/* There is an unrelated git repository at '../' */
2249-
return NULL;
2248+
return 0;
22502249
if (code)
22512250
die(_("ls-tree returned unexpected return code %d"), code);
22522251

submodule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ void absorb_git_dir_into_superproject(const char *path,
152152
/*
153153
* Return the absolute path of the working tree of the superproject, which this
154154
* project is a submodule of. If this repository is not a submodule of
155-
* another repository, return NULL.
155+
* another repository, return 0.
156156
*/
157-
const char *get_superproject_working_tree(void);
157+
int get_superproject_working_tree(struct strbuf *buf);
158158

159159
#endif

0 commit comments

Comments
 (0)