summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d0d7cbe)
raw | patch | inline | side by side (parent: d0d7cbe)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sun, 17 Apr 2005 23:19:32 +0000 (16:19 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sun, 17 Apr 2005 23:19:32 +0000 (16:19 -0700) |
This allows fsck to verify not just that an object exists, but
also that it has the type it was expected to have.
also that it has the type it was expected to have.
fsck-cache.c | patch | blob | history | |
rev-tree.c | patch | blob | history | |
revision.h | patch | blob | history |
diff --git a/fsck-cache.c b/fsck-cache.c
index a8050f84a9f13f97c3b5ae719d261ca8f782c2b2..b8b66d7d1d5cd4d1795e53a0ff04ae1693498eab 100644 (file)
--- a/fsck-cache.c
+++ b/fsck-cache.c
struct revision *rev = revs[i];
if (show_unreachable && !(rev->flags & REACHABLE)) {
- printf("unreachable %s\n", sha1_to_hex(rev->sha1));
+ printf("unreachable %s %s\n", rev->tag, sha1_to_hex(rev->sha1));
continue;
}
switch (rev->flags & (SEEN | USED)) {
case 0:
- printf("bad %s\n", sha1_to_hex(rev->sha1));
+ printf("bad %s %s\n", rev->tag, sha1_to_hex(rev->sha1));
break;
case USED:
- printf("missing %s\n", sha1_to_hex(rev->sha1));
+ printf("missing %s, %s\n", rev->tag, sha1_to_hex(rev->sha1));
break;
case SEEN:
- printf("dangling %s\n", sha1_to_hex(rev->sha1));
+ printf("dangling %s %s\n", rev->tag, sha1_to_hex(rev->sha1));
break;
}
}
}
-static void mark_needs_sha1(unsigned char *parent, const char * tag, unsigned char *child)
+static void mark_needs_sha1(unsigned char *parent, const char *ptag, unsigned char *child, const char *ctag)
{
- struct revision * child_rev = add_relationship(lookup_rev(parent), child);
+ struct revision * child_rev = add_relationship(lookup_rev(parent, ptag), child, ctag);
child_rev->flags |= USED;
}
-static int mark_sha1_seen(unsigned char *sha1, char *tag)
+static int mark_sha1_seen(unsigned char *sha1, const char *tag)
{
- struct revision *rev = lookup_rev(sha1);
+ struct revision *rev = lookup_rev(sha1, tag);
rev->flags |= SEEN;
return 0;
data += len + 20;
size -= len + 20;
- mark_needs_sha1(sha1, S_ISDIR(mode) ? "tree" : "blob", file_sha1);
+ mark_needs_sha1(sha1, "tree", file_sha1, S_ISDIR(mode) ? "tree" : "blob");
}
return 0;
}
return -1;
if (get_sha1_hex(data + 5, tree_sha1) < 0)
return -1;
- mark_needs_sha1(sha1, "tree", tree_sha1);
+ mark_needs_sha1(sha1, "commit", tree_sha1, "tree");
data += 5 + 40 + 1; /* "tree " + <hex sha1> + '\n' */
parents = 0;
while (!memcmp(data, "parent ", 7)) {
if (get_sha1_hex(data + 7, parent_sha1) < 0)
return -1;
- mark_needs_sha1(sha1, "commit", parent_sha1);
+ mark_needs_sha1(sha1, "commit", parent_sha1, "commit");
data += 7 + 40 + 1; /* "parent " + <hex sha1> + '\n' */
parents++;
}
continue;
}
if (!get_sha1_hex(argv[i], head_sha1)) {
- mark_reachable(lookup_rev(head_sha1), REACHABLE);
+ mark_reachable(lookup_rev(head_sha1, "commit"), REACHABLE);
heads++;
continue;
}
diff --git a/rev-tree.c b/rev-tree.c
index fe114ab3604d04fd002011fdc73573f9b5a67eed..3c54769258b82a9384248fbf10530e25d8b2dd8f 100644 (file)
--- a/rev-tree.c
+++ b/rev-tree.c
break;
if (get_sha1_hex(buf+1, sha1))
break;
- rev = lookup_rev(sha1);
+ rev = lookup_rev(sha1, "commit");
rev->flags |= SEEN;
rev->date = date;
unsigned char parent[20];
if (get_sha1_hex(buf + 1, parent))
break;
- add_relationship(rev, parent);
+ add_relationship(rev, parent, "commit");
}
}
fclose(file);
* Now we have the maximal tree. Walk the different sha files back to the root.
*/
for (i = 0; i < nr; i++)
- mark_reachable(lookup_rev(sha1[i]), 1 << i);
+ mark_reachable(lookup_rev(sha1[i], "commit"), 1 << i);
/*
* Now print out the results..
diff --git a/revision.h b/revision.h
index 482729575cfe94db3dec486ad5d1811e65e717b4..7791a72e0abc7b7fad4b99aadbbe2e604b03c881 100644 (file)
--- a/revision.h
+++ b/revision.h
unsigned char sha1[20];
unsigned long date;
struct parent *parent;
+ char tag[1];
};
static struct revision **revs;
return -first-1;
}
-static struct revision *lookup_rev(unsigned char *sha1)
+static struct revision *lookup_rev(unsigned char *sha1, const char *tag)
{
int pos = find_rev(sha1);
struct revision *n;
- if (pos >= 0)
- return revs[pos];
+ if (pos >= 0) {
+ n = revs[pos];
+ if (strcmp(n->tag, tag))
+ error("expected tag %s on object %s: got %s", tag, sha1_to_hex(sha1), n->tag);
+ return n;
+ }
pos = -pos-1;
rev_allocs = alloc_nr(rev_allocs);
revs = realloc(revs, rev_allocs * sizeof(struct revision *));
}
- n = malloc(sizeof(struct revision));
+ n = malloc(sizeof(struct revision) + strlen(tag));
n->flags = 0;
memcpy(n->sha1, sha1, 20);
n->parent = NULL;
+ strcpy(n->tag, tag);
/* Insert it into the right place */
memmove(revs + pos + 1, revs + pos, (nr_revs - pos) * sizeof(struct revision *));
return n;
}
-static struct revision *add_relationship(struct revision *rev, unsigned char *needs)
+static struct revision *add_relationship(struct revision *rev, unsigned char *needs, const char *tag)
{
- struct revision *parent_rev = lookup_rev(needs);
+ struct revision *parent_rev = lookup_rev(needs, tag);
struct parent **pp = &rev->parent, *p;
while ((p = *pp) != NULL) {
static struct revision * parse_commit(unsigned char *sha1)
{
- struct revision *rev = lookup_rev(sha1);
+ struct revision *rev = lookup_rev(sha1, "commit");
if (!(rev->flags & SEEN)) {
void *buffer, *bufptr;
die("%s is not a commit object", sha1_to_hex(sha1));
bufptr += 46; /* "tree " + "hex sha1" + "\n" */
while (!memcmp(bufptr, "parent ", 7) && !get_sha1_hex(bufptr+7, parent)) {
- add_relationship(rev, parent);
+ add_relationship(rev, parent, "commit");
parse_commit(parent);
bufptr += 48; /* "parent " + "hex sha1" + "\n" */
}