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;
}
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..
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" */
}