detect broken alternates.
The real problem triggered an earlier fix was that an alternate entry was pointing at a removed directory. Complaining on object/pack directory that cannot be opendir-ed produces noise in an ancient repository that does not have object/pack directory and has never been packed. Detect the real user error and report it. Also if opendir failed for other reasons (e.g. no read permissions), report that as well. Spotted by Andrew Vasquez <andrew.vasquez@qlogic.com>. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 22, 2006 at 11:16 UTC
26125f6b9be8dac31f56bf3da60dfa0df6dc0b59
1 file changed
+16
-3
sha1_file.c
+16
-3
@@ -247,6 +247,7 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
247
for ( ; cp < ep && *cp != sep; cp++)
248
;
249
if (last != cp) {
250
+ struct stat st;
251
struct alternate_object_database *alt;
252
/* 43 = 40-byte + 2 '/' + terminating NUL */
253
int pfxlen = cp - last;
@@ -269,9 +270,19 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
270
}
271
else
272
memcpy(ent->base, last, pfxlen);
273
+
274
ent->name = ent->base + pfxlen + 1;
273
- ent->base[pfxlen] = ent->base[pfxlen + 3] = '/';
274
- ent->base[entlen-1] = 0;
275
+ ent->base[pfxlen + 3] = '/';
276
+ ent->base[pfxlen] = ent->base[entlen-1] = 0;
277
+
278
+ /* Detect cases where alternate disappeared */
279
+ if (stat(ent->base, &st) || !S_ISDIR(st.st_mode)) {
280
+ error("object directory %s does not exist; "
281
+ "check .git/objects/info/alternates.",
282
+ ent->base);
283
+ goto bad;
284
+ }
285
+ ent->base[pfxlen] = '/';
286
287
/* Prevent the common mistake of listing the same
288
* thing twice, or object directory itself.
@@ -552,7 +563,9 @@ static void prepare_packed_git_one(char *objdir, int local)
563
len = strlen(path);
564
dir = opendir(path);
565
if (!dir) {
555
- fprintf(stderr, "unable to open object pack directory: %s: %s\n", path, strerror(errno));
566
+ if (errno != ENOENT)
567
+ error("unable to open object pack directory: %s: %s\n",
568
+ path, strerror(errno));
569
return;
570
}
571
path[len++] = '/';