]> git.ipfire.org Git - thirdparty/git.git/commitdiff
midx: use real paths in lookup_multi_pack_index()
authorDerrick Stolee <derrickstolee@github.com>
Mon, 25 Apr 2022 18:27:12 +0000 (18:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Apr 2022 18:31:11 +0000 (11:31 -0700)
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 <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c

diff --git a/midx.c b/midx.c
index 837b46b2af5fd766b981964ca27be427225b7591..04600c698192834b6be470a335f1fb657ed4c8e3 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -1113,17 +1113,26 @@ cleanup:
 static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
                                                        const char *object_dir)
 {
+       struct multi_pack_index *result = NULL;
        struct multi_pack_index *cur;
+       char *obj_dir_real = real_pathdup(object_dir, 1);
+       struct strbuf cur_path_real = STRBUF_INIT;
 
        /* Ensure the given object_dir is local, or a known alternate. */
-       find_odb(r, object_dir);
+       find_odb(r, obj_dir_real);
 
        for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
-               if (!strcmp(object_dir, cur->object_dir))
-                       return cur;
+               strbuf_realpath(&cur_path_real, cur->object_dir, 1);
+               if (!strcmp(obj_dir_real, cur_path_real.buf)) {
+                       result = cur;
+                       goto cleanup;
+               }
        }
 
-       return NULL;
+cleanup:
+       free(obj_dir_real);
+       strbuf_release(&cur_path_real);
+       return result;
 }
 
 static int write_midx_internal(const char *object_dir,