Skip to content

Commit a8c565b

Browse files
committed
Merge branch 'ek/alt-odb-entry-fix'
* ek/alt-odb-entry-fix: sha1_file: do not add own object directory as alternate
2 parents 9b1c2a3 + 539e750 commit a8c565b

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

sha1_file.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ static struct alternate_object_database **alt_odb_tail;
268268
* SHA1, an extra slash for the first level indirection, and the
269269
* terminating NUL.
270270
*/
271-
static int link_alt_odb_entry(const char *entry, const char *relative_base, int depth)
271+
static int link_alt_odb_entry(const char *entry, const char *relative_base,
272+
int depth, const char *normalized_objdir)
272273
{
273-
const char *objdir = get_object_directory();
274274
struct alternate_object_database *ent;
275275
struct alternate_object_database *alt;
276276
int pfxlen, entlen;
@@ -321,7 +321,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base, int
321321
return -1;
322322
}
323323
}
324-
if (!strcmp(ent->base, objdir)) {
324+
if (!strcmp_icase(ent->base, normalized_objdir)) {
325325
free(ent);
326326
return -1;
327327
}
@@ -345,13 +345,17 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
345345
struct string_list entries = STRING_LIST_INIT_NODUP;
346346
char *alt_copy;
347347
int i;
348+
struct strbuf objdirbuf = STRBUF_INIT;
348349

349350
if (depth > 5) {
350351
error("%s: ignoring alternate object stores, nesting too deep.",
351352
relative_base);
352353
return;
353354
}
354355

356+
strbuf_addstr(&objdirbuf, absolute_path(get_object_directory()));
357+
normalize_path_copy(objdirbuf.buf, objdirbuf.buf);
358+
355359
alt_copy = xmemdupz(alt, len);
356360
string_list_split_in_place(&entries, alt_copy, sep, -1);
357361
for (i = 0; i < entries.nr; i++) {
@@ -362,11 +366,12 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
362366
error("%s: ignoring relative alternate object store %s",
363367
relative_base, entry);
364368
} else {
365-
link_alt_odb_entry(entry, relative_base, depth);
369+
link_alt_odb_entry(entry, relative_base, depth, objdirbuf.buf);
366370
}
367371
}
368372
string_list_clear(&entries, 0);
369373
free(alt_copy);
374+
strbuf_release(&objdirbuf);
370375
}
371376

372377
void read_info_alternates(const char * relative_base, int depth)

t/t7702-repack-cyclic-alternate.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2014 Ephrim Khong
4+
#
5+
6+
test_description='repack involving cyclic alternate'
7+
. ./test-lib.sh
8+
9+
test_expect_success setup '
10+
GIT_OBJECT_DIRECTORY=.git//../.git/objects &&
11+
export GIT_OBJECT_DIRECTORY &&
12+
touch a &&
13+
git add a &&
14+
git commit -m 1 &&
15+
git repack -adl &&
16+
echo "$(pwd)"/.git/objects/../objects >.git/objects/info/alternates
17+
'
18+
19+
test_expect_success 're-packing repository with itsself as alternate' '
20+
git repack -adl &&
21+
git fsck
22+
'
23+
24+
test_done

0 commit comments

Comments
 (0)