Skip to content

Commit b2ac148

Browse files
peffgitster
authored andcommitted
submodule--helper: prefer strip_suffix() to ends_with()
Using strip_suffix() lets us avoid repeating ourselves. It also makes the handling of "/" a bit less subtle (we strip one less character than we matched in order to leave it in place, but we can just as easily include the "/" when we add more path components). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4d0984b commit b2ac148

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/submodule--helper.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,24 +1268,25 @@ static int add_possible_reference_from_superproject(
12681268
struct alternate_object_database *alt, void *sas_cb)
12691269
{
12701270
struct submodule_alternate_setup *sas = sas_cb;
1271+
size_t len;
12711272

12721273
/*
12731274
* If the alternate object store is another repository, try the
12741275
* standard layout with .git/(modules/<name>)+/objects
12751276
*/
1276-
if (ends_with(alt->path, "/objects")) {
1277+
if (strip_suffix(alt->path, "/objects", &len)) {
12771278
char *sm_alternate;
12781279
struct strbuf sb = STRBUF_INIT;
12791280
struct strbuf err = STRBUF_INIT;
1280-
strbuf_add(&sb, alt->path, strlen(alt->path) - strlen("objects"));
1281+
strbuf_add(&sb, alt->path, len);
12811282

12821283
/*
12831284
* We need to end the new path with '/' to mark it as a dir,
12841285
* otherwise a submodule name containing '/' will be broken
12851286
* as the last part of a missing submodule reference would
12861287
* be taken as a file name.
12871288
*/
1288-
strbuf_addf(&sb, "modules/%s/", sas->submodule_name);
1289+
strbuf_addf(&sb, "/modules/%s/", sas->submodule_name);
12891290

12901291
sm_alternate = compute_alternate_path(sb.buf, &err);
12911292
if (sm_alternate) {

0 commit comments

Comments
 (0)