Skip to content

Commit 29ec6af

Browse files
peffgitster
authored andcommitted
alternates: encapsulate alt->base munging
The alternate_object_database struct holds a path to the alternate objects, but we also use that buffer as scratch space for forming loose object filenames. Let's pull that logic into a helper function so that we can more easily modify it. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f0fa2c commit 29ec6af

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

sha1_file.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ const char *sha1_file_name(const unsigned char *sha1)
204204
return buf;
205205
}
206206

207+
static const char *alt_sha1_path(struct alternate_object_database *alt,
208+
const unsigned char *sha1)
209+
{
210+
fill_sha1_path(alt->name, sha1);
211+
return alt->base;
212+
}
213+
207214
/*
208215
* Return the name of the pack or index file with the specified sha1
209216
* in its filename. *base and *name are scratch space that must be
@@ -601,8 +608,8 @@ static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
601608
struct alternate_object_database *alt;
602609
prepare_alt_odb();
603610
for (alt = alt_odb_list; alt; alt = alt->next) {
604-
fill_sha1_path(alt->name, sha1);
605-
if (check_and_freshen_file(alt->base, freshen))
611+
const char *path = alt_sha1_path(alt, sha1);
612+
if (check_and_freshen_file(path, freshen))
606613
return 1;
607614
}
608615
return 0;
@@ -1600,8 +1607,8 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st)
16001607
prepare_alt_odb();
16011608
errno = ENOENT;
16021609
for (alt = alt_odb_list; alt; alt = alt->next) {
1603-
fill_sha1_path(alt->name, sha1);
1604-
if (!lstat(alt->base, st))
1610+
const char *path = alt_sha1_path(alt, sha1);
1611+
if (!lstat(path, st))
16051612
return 0;
16061613
}
16071614

@@ -1621,8 +1628,8 @@ static int open_sha1_file(const unsigned char *sha1)
16211628

16221629
prepare_alt_odb();
16231630
for (alt = alt_odb_list; alt; alt = alt->next) {
1624-
fill_sha1_path(alt->name, sha1);
1625-
fd = git_open_noatime(alt->base);
1631+
const char *path = alt_sha1_path(alt, sha1);
1632+
fd = git_open_noatime(path);
16261633
if (fd >= 0)
16271634
return fd;
16281635
if (most_interesting_errno == ENOENT)

0 commit comments

Comments
 (0)