Skip to content

Commit eafcc6d

Browse files
derrickstoleegitster
authored andcommitted
midx: use real paths in lookup_multi_pack_index()
This helper looks for a parsed multi-pack-index whose object directory matches the given object_dir. Before going into the loop over the parsed multi-pack-indexes, it calls find_odb() to ensure that the given object_dir is actually a known object directory. However, find_odb() uses real-path manipulations to compare the input to the alternate directories. This same real-path comparison is not used in the loop, leading to potential issues with the strcmp(). Update the method to use the real-path values instead. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d516b2d commit eafcc6d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

midx.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,17 +1113,26 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
11131113
static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
11141114
const char *object_dir)
11151115
{
1116+
struct multi_pack_index *result = NULL;
11161117
struct multi_pack_index *cur;
1118+
char *obj_dir_real = real_pathdup(object_dir, 1);
1119+
struct strbuf cur_path_real = STRBUF_INIT;
11171120

11181121
/* Ensure the given object_dir is local, or a known alternate. */
1119-
find_odb(r, object_dir);
1122+
find_odb(r, obj_dir_real);
11201123

11211124
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
1122-
if (!strcmp(object_dir, cur->object_dir))
1123-
return cur;
1125+
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
1126+
if (!strcmp(obj_dir_real, cur_path_real.buf)) {
1127+
result = cur;
1128+
goto cleanup;
1129+
}
11241130
}
11251131

1126-
return NULL;
1132+
cleanup:
1133+
free(obj_dir_real);
1134+
strbuf_release(&cur_path_real);
1135+
return result;
11271136
}
11281137

11291138
static int write_midx_internal(const char *object_dir,

0 commit comments

Comments
 (0)