Skip to content

Commit

Permalink
detect broken alternates.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Feb 22, 2006
1 parent aa06474 commit 26125f6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
for ( ; cp < ep && *cp != sep; cp++)
;
if (last != cp) {
struct stat st;
struct alternate_object_database *alt;
/* 43 = 40-byte + 2 '/' + terminating NUL */
int pfxlen = cp - last;
Expand All @@ -269,9 +270,19 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
}
else
memcpy(ent->base, last, pfxlen);

ent->name = ent->base + pfxlen + 1;
ent->base[pfxlen] = ent->base[pfxlen + 3] = '/';
ent->base[entlen-1] = 0;
ent->base[pfxlen + 3] = '/';
ent->base[pfxlen] = ent->base[entlen-1] = 0;

/* Detect cases where alternate disappeared */
if (stat(ent->base, &st) || !S_ISDIR(st.st_mode)) {
error("object directory %s does not exist; "
"check .git/objects/info/alternates.",
ent->base);
goto bad;
}
ent->base[pfxlen] = '/';

/* Prevent the common mistake of listing the same
* thing twice, or object directory itself.
Expand Down Expand Up @@ -552,7 +563,9 @@ static void prepare_packed_git_one(char *objdir, int local)
len = strlen(path);
dir = opendir(path);
if (!dir) {
fprintf(stderr, "unable to open object pack directory: %s: %s\n", path, strerror(errno));
if (errno != ENOENT)
error("unable to open object pack directory: %s: %s\n",
path, strerror(errno));
return;
}
path[len++] = '/';
Expand Down

0 comments on commit 26125f6

Please sign in to comment.