sha1_file: do not add own object directory as alternate
When adding alternate object directories, we try not to add the directory of the current repository to avoid cycles. Unfortunately, that test was broken, since it compared an absolute with a relative path. Signed-off-by: Ephrim Khong <dr.khong@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ephrim Khong committed
Jul 15, 2014 at 13:29 UTC
539e75069f5c8f0ecf9e99f1163647aa9f92c5bd
2 files changed
+33
-4
sha1_file.c
+9
-4
@@ -256,9 +256,9 @@ static int git_open_noatime(const char *name);
256
* SHA1, an extra slash for the first level indirection, and the
257
* terminating NUL.
258
*/
259
-static int link_alt_odb_entry(const char *entry, const char *relative_base, int depth)
259
+static int link_alt_odb_entry(const char *entry, const char *relative_base,
260
+ int depth, const char *normalized_objdir)
261
{
261
- const char *objdir = get_object_directory();
262
struct alternate_object_database *ent;
263
struct alternate_object_database *alt;
264
int pfxlen, entlen;
@@ -308,7 +308,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base, int
308
return -1;
309
}
310
}
311
- if (!strcmp(ent->base, objdir)) {
311
+ if (!strcmp_icase(ent->base, normalized_objdir)) {
312
free(ent);
313
return -1;
314
}
@@ -332,6 +332,7 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
332
struct string_list entries = STRING_LIST_INIT_NODUP;
333
char *alt_copy;
334
int i;
335
+ struct strbuf objdirbuf = STRBUF_INIT;
336
337
if (depth > 5) {
338
error("%s: ignoring alternate object stores, nesting too deep.",
@@ -339,6 +340,9 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
340
return;
341
}
342
343
+ strbuf_addstr(&objdirbuf, absolute_path(get_object_directory()));
344
+ normalize_path_copy(objdirbuf.buf, objdirbuf.buf);
345
+
346
alt_copy = xmemdupz(alt, len);
347
string_list_split_in_place(&entries, alt_copy, sep, -1);
348
for (i = 0; i < entries.nr; i++) {
@@ -349,11 +353,12 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
353
error("%s: ignoring relative alternate object store %s",
354
relative_base, entry);
355
} else {
352
- link_alt_odb_entry(entry, relative_base, depth);
356
+ link_alt_odb_entry(entry, relative_base, depth, objdirbuf.buf);
357
}
358
}
359
string_list_clear(&entries, 0);
360
free(alt_copy);
361
+ strbuf_release(&objdirbuf);
362
}
363
364
void read_info_alternates(const char * relative_base, int depth)
t/t7702-repack-cyclic-alternate.sh
new
+24
@@ -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