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
, "commit");
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
, "commit");
56 * Some revisions are less interesting than others.
58 * For example, if we use a cache-file, that one may contain
59 * revisions that were never used. They are never interesting.
61 * And sometimes we're only interested in "edge" commits, ie
62 * places where the marking changes between parent and child.
64 static int interesting(struct revision
*rev
)
66 unsigned mask
= marked(rev
);
71 struct parent
*p
= rev
->parent
;
73 if (mask
!= marked(p
->parent
))
86 * Usage: rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id2>]
88 * The cache-file can be quite important for big trees. This is an
89 * expensive operation if you have to walk the whole chain of
90 * parents in a tree with a long revision history.
92 int main(int argc
, char **argv
)
96 unsigned char sha1
[MAX_COMMITS
][20];
99 * First - pick up all the revisions we can (both from
100 * caches and from commit file chains).
102 for (i
= 1; i
< argc
; i
++) {
105 if (!strcmp(arg
, "--cache")) {
106 read_cache_file(argv
[2]);
111 if (!strcmp(arg
, "--edges")) {
120 if (nr
>= MAX_COMMITS
|| get_sha1_hex(arg
, sha1
[nr
]))
121 usage("rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id>]");
122 parse_commit(sha1
[nr
]);
127 * Now we have the maximal tree. Walk the different sha files back to the root.
129 for (i
= 0; i
< nr
; i
++)
130 mark_reachable(lookup_rev(sha1
[i
], "commit"), 1 << i
);
133 * Now print out the results..
135 for (i
= 0; i
< nr_revs
; i
++) {
136 struct revision
*rev
= revs
[i
];
139 if (!interesting(rev
))
142 printf("%lu %s:%d", rev
->date
, sha1_to_hex(rev
->sha1
), marked(rev
));
145 printf(" %s:%d", sha1_to_hex(p
->parent
->sha1
), marked(p
->parent
));