Skip to content

Commit 618b844

Browse files
chooglengitster
authored andcommitted
submodule--helper update: use display path helper
There are two locations in prepare_to_clone_next_submodule() that manually calculate the submodule display path, but should just use do_get_submodule_displaypath() for consistency. Do this replacement and reorder the code slightly to avoid computing the display path twice. Until the preceding commit this code had never been tested, with our newly added tests we can see that both these sites have been computing the display path incorrectly ever since they were introduced in 4830868 (git submodule update: have a dedicated helper for cloning, 2016-02-29) [1]: - The first hunk puts a "/" between recursive_prefix and ce->name, but recursive_prefix already ends with "/". - The second hunk calls relative_path() on recursive_prefix and ce->name, but relative_path() only makes sense when both paths share the same base directory. This is never the case here: - recursive_prefix is the path from the topmost superproject to the current submodule - ce->name is the path from the root of the current submodule to its submodule. so, e.g. recursive_prefix="super" and ce->name="submodule" produces displayname="../super" instead of "super/submodule". [1] I verified this by applying the tests to 4830868. Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8fc36c3 commit 618b844

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

builtin/submodule--helper.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,30 +1947,21 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
19471947
const char *update_string;
19481948
enum submodule_update_type update_type;
19491949
char *key;
1950-
struct strbuf displaypath_sb = STRBUF_INIT;
1950+
struct update_data *ud = suc->update_data;
1951+
char *displaypath = do_get_submodule_displaypath(ce->name, ud->prefix,
1952+
ud->recursive_prefix);
19511953
struct strbuf sb = STRBUF_INIT;
1952-
const char *displaypath = NULL;
19531954
int needs_cloning = 0;
19541955
int need_free_url = 0;
19551956

19561957
if (ce_stage(ce)) {
1957-
if (suc->update_data->recursive_prefix)
1958-
strbuf_addf(&sb, "%s/%s", suc->update_data->recursive_prefix, ce->name);
1959-
else
1960-
strbuf_addstr(&sb, ce->name);
1961-
strbuf_addf(out, _("Skipping unmerged submodule %s"), sb.buf);
1958+
strbuf_addf(out, _("Skipping unmerged submodule %s"), displaypath);
19621959
strbuf_addch(out, '\n');
19631960
goto cleanup;
19641961
}
19651962

19661963
sub = submodule_from_path(the_repository, null_oid(), ce->name);
19671964

1968-
if (suc->update_data->recursive_prefix)
1969-
displaypath = relative_path(suc->update_data->recursive_prefix,
1970-
ce->name, &displaypath_sb);
1971-
else
1972-
displaypath = ce->name;
1973-
19741965
if (!sub) {
19751966
next_submodule_warn_missing(suc, out, displaypath);
19761967
goto cleanup;
@@ -2060,7 +2051,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
20602051
"--no-single-branch");
20612052

20622053
cleanup:
2063-
strbuf_release(&displaypath_sb);
2054+
free(displaypath);
20642055
strbuf_release(&sb);
20652056
if (need_free_url)
20662057
free((void*)url);

t/t7406-submodule-update.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ test_expect_success 'submodule update should skip unmerged submodules' '
11601160
test_config -C top-cloned submodule.middle.update !true &&
11611161
git -C top-cloned submodule update --recursive 2>actual.err &&
11621162
cat >expect.err <<-\EOF &&
1163-
Skipping unmerged submodule middle//bottom
1163+
Skipping unmerged submodule middle/bottom
11641164
EOF
11651165
test_cmp expect.err actual.err
11661166
'
@@ -1173,7 +1173,7 @@ test_expect_success 'submodule update --recursive skip submodules with strategy=
11731173
git -C top-cloned/middle config submodule.bottom.update none &&
11741174
git -C top-cloned submodule update --recursive 2>actual.err &&
11751175
cat >expect.err <<-\EOF &&
1176-
Skipping submodule '\''../middle/'\''
1176+
Skipping submodule '\''middle/bottom'\''
11771177
EOF
11781178
test_cmp expect.err actual.err
11791179
'

0 commit comments

Comments
 (0)