5 * revision.h leaves the low 16 bits of the "flags" field of the
6 * revision data structure unused. We use it for a "reachable from
7 * this commit <N>" bitmask.
11 static int show_edges
= 0;
12 static int basemask
= 0;
14 static void read_cache_file(const char *path
)
16 die("no revtree cache file yet");
20 * Some revisions are less interesting than others.
22 * For example, if we use a cache-file, that one may contain
23 * revisions that were never used. They are never interesting.
25 * And sometimes we're only interested in "edge" commits, ie
26 * places where the marking changes between parent and child.
28 static int interesting(struct commit
*rev
)
30 unsigned mask
= rev
->object
.flags
;
35 struct commit_list
*p
= rev
->parents
;
37 if (mask
!= p
->item
->object
.flags
)
49 static void process_commit(unsigned char *sha1
)
51 struct commit_list
*parents
;
52 struct commit
*obj
= lookup_commit(sha1
);
54 if (obj
&& obj
->object
.parsed
)
56 if (!obj
|| parse_commit(obj
))
57 die("unable to parse commit (%s)", sha1_to_hex(sha1
));
59 parents
= obj
->parents
;
61 process_commit(parents
->item
->object
.sha1
);
62 parents
= parents
->next
;
67 * Usage: git-rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id2>]
69 * The cache-file can be quite important for big trees. This is an
70 * expensive operation if you have to walk the whole chain of
71 * parents in a tree with a long revision history.
73 int main(int argc
, char **argv
)
77 unsigned char sha1
[MAX_COMMITS
][20];
80 * First - pick up all the revisions we can (both from
81 * caches and from commit file chains).
83 for (i
= 1; i
< argc
; i
++) {
86 if (!strcmp(arg
, "--cache")) {
87 read_cache_file(argv
[++i
]);
91 if (!strcmp(arg
, "--edges")) {
100 if (nr
>= MAX_COMMITS
|| get_sha1(arg
, sha1
[nr
]))
101 usage("git-rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id>]");
102 process_commit(sha1
[nr
]);
107 * Now we have the maximal tree. Walk the different sha files back to the root.
109 for (i
= 0; i
< nr
; i
++)
110 mark_reachable(&lookup_commit(sha1
[i
])->object
, 1 << i
);
113 * Now print out the results..
115 for (i
= 0; i
< nr_objs
; i
++) {
116 struct object
*obj
= objs
[i
];
117 struct commit
*commit
;
118 struct commit_list
*p
;
120 if (obj
->type
!= commit_type
)
123 commit
= (struct commit
*) obj
;
125 if (!interesting(commit
))
128 printf("%lu %s:%d", commit
->date
, sha1_to_hex(obj
->sha1
),
132 printf(" %s:%d", sha1_to_hex(p
->item
->object
.sha1
),
133 p
->item
->object
.flags
);