Skip to content

Commit 67c305f

Browse files
committed
Merge branch 'ds/midx-normalize-pathname-before-comparison' into maint
The path taken by "git multi-pack-index" command from the end user was compared with path internally prepared by the tool withut first normalizing, which lead to duplicated paths not being noticed, which has been corrected. source: <[email protected]> * ds/midx-normalize-pathname-before-comparison: cache: use const char * for get_object_directory() multi-pack-index: use --object-dir real path midx: use real paths in lookup_multi_pack_index()
2 parents 363d54f + 11f9e8d commit 67c305f

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

builtin/multi-pack-index.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,31 @@ static char const * const builtin_multi_pack_index_usage[] = {
4444
};
4545

4646
static struct opts_multi_pack_index {
47-
const char *object_dir;
47+
char *object_dir;
4848
const char *preferred_pack;
4949
const char *refs_snapshot;
5050
unsigned long batch_size;
5151
unsigned flags;
5252
int stdin_packs;
5353
} opts;
5454

55+
56+
static int parse_object_dir(const struct option *opt, const char *arg,
57+
int unset)
58+
{
59+
free(opts.object_dir);
60+
if (unset)
61+
opts.object_dir = xstrdup(get_object_directory());
62+
else
63+
opts.object_dir = real_pathdup(arg, 1);
64+
return 0;
65+
}
66+
5567
static struct option common_opts[] = {
56-
OPT_FILENAME(0, "object-dir", &opts.object_dir,
57-
N_("object directory containing set of packfile and pack-index pairs")),
68+
OPT_CALLBACK(0, "object-dir", &opts.object_dir,
69+
N_("directory"),
70+
N_("object directory containing set of packfile and pack-index pairs"),
71+
parse_object_dir),
5872
OPT_END(),
5973
};
6074

@@ -232,31 +246,40 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv)
232246
int cmd_multi_pack_index(int argc, const char **argv,
233247
const char *prefix)
234248
{
249+
int res;
235250
struct option *builtin_multi_pack_index_options = common_opts;
236251

237252
git_config(git_default_config, NULL);
238253

254+
if (the_repository &&
255+
the_repository->objects &&
256+
the_repository->objects->odb)
257+
opts.object_dir = xstrdup(the_repository->objects->odb->path);
258+
239259
argc = parse_options(argc, argv, prefix,
240260
builtin_multi_pack_index_options,
241261
builtin_multi_pack_index_usage,
242262
PARSE_OPT_STOP_AT_NON_OPTION);
243263

244-
if (!opts.object_dir)
245-
opts.object_dir = get_object_directory();
246-
247264
if (!argc)
248265
goto usage;
249266

250267
if (!strcmp(argv[0], "repack"))
251-
return cmd_multi_pack_index_repack(argc, argv);
268+
res = cmd_multi_pack_index_repack(argc, argv);
252269
else if (!strcmp(argv[0], "write"))
253-
return cmd_multi_pack_index_write(argc, argv);
270+
res = cmd_multi_pack_index_write(argc, argv);
254271
else if (!strcmp(argv[0], "verify"))
255-
return cmd_multi_pack_index_verify(argc, argv);
272+
res = cmd_multi_pack_index_verify(argc, argv);
256273
else if (!strcmp(argv[0], "expire"))
257-
return cmd_multi_pack_index_expire(argc, argv);
274+
res = cmd_multi_pack_index_expire(argc, argv);
275+
else {
276+
error(_("unrecognized subcommand: %s"), argv[0]);
277+
goto usage;
278+
}
279+
280+
free(opts.object_dir);
281+
return res;
258282

259-
error(_("unrecognized subcommand: %s"), argv[0]);
260283
usage:
261284
usage_with_options(builtin_multi_pack_index_usage,
262285
builtin_multi_pack_index_options);

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ extern char *git_work_tree_cfg;
566566
int is_inside_work_tree(void);
567567
const char *get_git_dir(void);
568568
const char *get_git_common_dir(void);
569-
char *get_object_directory(void);
569+
const char *get_object_directory(void);
570570
char *get_index_file(void);
571571
char *get_graft_file(struct repository *r);
572572
void set_git_dir(const char *path, int make_realpath);

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ const char *get_git_work_tree(void)
273273
return the_repository->worktree;
274274
}
275275

276-
char *get_object_directory(void)
276+
const char *get_object_directory(void)
277277
{
278278
if (!the_repository->objects->odb)
279279
BUG("git environment hasn't been setup");

midx.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,17 +1132,26 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
11321132
static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
11331133
const char *object_dir)
11341134
{
1135+
struct multi_pack_index *result = NULL;
11351136
struct multi_pack_index *cur;
1137+
char *obj_dir_real = real_pathdup(object_dir, 1);
1138+
struct strbuf cur_path_real = STRBUF_INIT;
11361139

11371140
/* Ensure the given object_dir is local, or a known alternate. */
1138-
find_odb(r, object_dir);
1141+
find_odb(r, obj_dir_real);
11391142

11401143
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
1141-
if (!strcmp(object_dir, cur->object_dir))
1142-
return cur;
1144+
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
1145+
if (!strcmp(obj_dir_real, cur_path_real.buf)) {
1146+
result = cur;
1147+
goto cleanup;
1148+
}
11431149
}
11441150

1145-
return NULL;
1151+
cleanup:
1152+
free(obj_dir_real);
1153+
strbuf_release(&cur_path_real);
1154+
return result;
11461155
}
11471156

11481157
static int write_midx_internal(const char *object_dir,

0 commit comments

Comments
 (0)