1 #define _XOPEN_SOURCE /* glibc2 needs this */
2 #define _BSD_SOURCE /* for tm.tm_gmtoff */
10 * revision.h leaves the low 16 bits of the "flags" field of the
11 * revision data structure unused. We use it for a "reachable from
12 * this commit <N>" bitmask.
14 #define MAX_COMMITS 16
16 static int show_edges = 0;
17 static int basemask = 0;
19 static void read_cache_file(const char *path)
21 FILE *file = fopen(path, "r");
25 die("bad revtree cache file (%s)", path);
27 while (fgets(line, sizeof(line), file)) {
29 unsigned char sha1[20];
33 if (sscanf(line, "%lu", &date) != 1)
35 buf = strchr(line, ' ');
38 if (get_sha1_hex(buf+1, sha1))
40 rev = lookup_rev(sha1);
45 while ((buf = strchr(buf+1, ' ')) != NULL) {
46 unsigned char parent[20];
47 if (get_sha1_hex(buf + 1, parent))
49 add_relationship(rev, parent);
55 static void mark_sha1_path(struct revision *rev, unsigned int mask)
59 if (rev->flags & mask)
65 mark_sha1_path(p->parent, mask);
71 * Some revisions are less interesting than others.
73 * For example, if we use a cache-file, that one may contain
74 * revisions that were never used. They are never interesting.
76 * And sometimes we're only interested in "edge" commits, ie
77 * places where the marking changes between parent and child.
79 static int interesting(struct revision *rev)
81 unsigned mask = marked(rev);
86 struct parent *p = rev->parent;
88 if (mask != marked(p->parent))
101 * Usage: rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id2>]
103 * The cache-file can be quite important for big trees. This is an
104 * expensive operation if you have to walk the whole chain of
105 * parents in a tree with a long revision history.
107 int main(int argc, char **argv)
111 unsigned char sha1[MAX_COMMITS][20];
114 * First - pick up all the revisions we can (both from
115 * caches and from commit file chains).
117 for (i = 1; i < argc ; i++) {
120 if (!strcmp(arg, "--cache")) {
121 read_cache_file(argv[2]);
126 if (!strcmp(arg, "--edges")) {
135 if (nr >= MAX_COMMITS || get_sha1_hex(arg, sha1[nr]))
136 usage("rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id>]");
137 parse_commit(sha1[nr]);
142 * Now we have the maximal tree. Walk the different sha files back to the root.
144 for (i = 0; i < nr; i++)
145 mark_sha1_path(lookup_rev(sha1[i]), 1 << i);
148 * Now print out the results..
150 for (i = 0; i < nr_revs; i++) {
151 struct revision *rev = revs[i];
154 if (!interesting(rev))
157 printf("%lu %s:%d", rev->date, sha1_to_hex(rev->sha1), marked(rev));
160 printf(" %s:%d", sha1_to_hex(p->parent->sha1), marked(p->parent));