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 die("no revtree cache file yet");
25 * Some revisions are less interesting than others.
27 * For example, if we use a cache-file, that one may contain
28 * revisions that were never used. They are never interesting.
30 * And sometimes we're only interested in "edge" commits, ie
31 * places where the marking changes between parent and child.
33 static int interesting(struct commit
*rev
)
35 unsigned mask
= rev
->object
.flags
;
40 struct commit_list
*p
= rev
->parents
;
42 if (mask
!= p
->item
->object
.flags
)
54 void process_commit(unsigned char *sha1
)
56 struct commit_list
*parents
;
57 struct commit
*obj
= lookup_commit(sha1
);
59 if (obj
->object
.parsed
)
64 parents
= obj
->parents
;
66 process_commit(parents
->item
->object
.sha1
);
67 parents
= parents
->next
;
72 * Usage: rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id2>]
74 * The cache-file can be quite important for big trees. This is an
75 * expensive operation if you have to walk the whole chain of
76 * parents in a tree with a long revision history.
78 int main(int argc
, char **argv
)
82 unsigned char sha1
[MAX_COMMITS
][20];
85 * First - pick up all the revisions we can (both from
86 * caches and from commit file chains).
88 for (i
= 1; i
< argc
; i
++) {
91 if (!strcmp(arg
, "--cache")) {
92 read_cache_file(argv
[++i
]);
96 if (!strcmp(arg
, "--edges")) {
105 if (nr
>= MAX_COMMITS
|| get_sha1_hex(arg
, sha1
[nr
]))
106 usage("rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id>]");
107 process_commit(sha1
[nr
]);
112 * Now we have the maximal tree. Walk the different sha files back to the root.
114 for (i
= 0; i
< nr
; i
++)
115 mark_reachable(&lookup_commit(sha1
[i
])->object
, 1 << i
);
118 * Now print out the results..
120 for (i
= 0; i
< nr_objs
; i
++) {
121 struct object
*obj
= objs
[i
];
122 struct commit
*commit
;
123 struct commit_list
*p
;
125 if (obj
->type
!= commit_type
)
128 commit
= (struct commit
*) obj
;
130 if (!interesting(commit
))
133 printf("%lu %s:%d", commit
->date
, sha1_to_hex(obj
->sha1
),
137 printf(" %s:%d", sha1_to_hex(p
->item
->object
.sha1
),
138 p
->item
->object
.flags
);