Skip to content

Commit f32996d

Browse files
committed
Merge branch 'gc/resolve-alternate-symlinks'
Resolve symbolic links when processing the locations of alternate object stores, since failing to do so can lead to confusing and buggy behavior. * gc/resolve-alternate-symlinks: object-file: use real paths when adding alternates
2 parents 815c1e8 + 199337d commit f32996d

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

object-file.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -508,20 +508,22 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
508508
{
509509
struct object_directory *ent;
510510
struct strbuf pathbuf = STRBUF_INIT;
511+
struct strbuf tmp = STRBUF_INIT;
511512
khiter_t pos;
513+
int ret = -1;
512514

513515
if (!is_absolute_path(entry->buf) && relative_base) {
514516
strbuf_realpath(&pathbuf, relative_base, 1);
515517
strbuf_addch(&pathbuf, '/');
516518
}
517519
strbuf_addbuf(&pathbuf, entry);
518520

519-
if (strbuf_normalize_path(&pathbuf) < 0 && relative_base) {
521+
if (!strbuf_realpath(&tmp, pathbuf.buf, 0)) {
520522
error(_("unable to normalize alternate object path: %s"),
521523
pathbuf.buf);
522-
strbuf_release(&pathbuf);
523-
return -1;
524+
goto error;
524525
}
526+
strbuf_swap(&pathbuf, &tmp);
525527

526528
/*
527529
* The trailing slash after the directory name is given by
@@ -530,10 +532,8 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
530532
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
531533
strbuf_setlen(&pathbuf, pathbuf.len - 1);
532534

533-
if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos)) {
534-
strbuf_release(&pathbuf);
535-
return -1;
536-
}
535+
if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
536+
goto error;
537537

538538
CALLOC_ARRAY(ent, 1);
539539
/* pathbuf.buf is already in r->objects->odb_by_path */
@@ -548,8 +548,11 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
548548

549549
/* recursively add alternates */
550550
read_info_alternates(r, ent->path, depth + 1);
551-
552-
return 0;
551+
ret = 0;
552+
error:
553+
strbuf_release(&tmp);
554+
strbuf_release(&pathbuf);
555+
return ret;
553556
}
554557

555558
static const char *parse_alt_odb_entry(const char *string,
@@ -596,10 +599,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
596599
return;
597600
}
598601

599-
strbuf_add_absolute_path(&objdirbuf, r->objects->odb->path);
600-
if (strbuf_normalize_path(&objdirbuf) < 0)
601-
die(_("unable to normalize object directory: %s"),
602-
objdirbuf.buf);
602+
strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
603603

604604
while (*alt) {
605605
alt = parse_alt_odb_entry(alt, sep, &entry);

t/t7700-repack.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
9090
test_has_duplicate_object false
9191
'
9292

93+
test_expect_success SYMLINKS '--local keeps packs when alternate is objectdir ' '
94+
test_when_finished "rm -rf repo" &&
95+
git init repo &&
96+
test_commit -C repo A &&
97+
(
98+
cd repo &&
99+
git repack -a &&
100+
ls .git/objects/pack/*.pack >../expect &&
101+
ln -s objects .git/alt_objects &&
102+
echo "$(pwd)/.git/alt_objects" >.git/objects/info/alternates &&
103+
git repack -a -d -l &&
104+
ls .git/objects/pack/*.pack >../actual
105+
) &&
106+
test_cmp expect actual
107+
'
108+
93109
test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
94110
mkdir alt_objects/pack &&
95111
mv .git/objects/pack/* alt_objects/pack &&

0 commit comments

Comments
 (0)