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.
10 #define REACHABLE (1U << 16)
12 #define cmit_flags(cmit) ((cmit)->object.flags & ~REACHABLE)
14 static int show_edges
= 0;
15 static int basemask
= 0;
17 static void read_cache_file(const char *path
)
19 die("no revtree cache file yet");
23 * Some revisions are less interesting than others.
25 * For example, if we use a cache-file, that one may contain
26 * revisions that were never used. They are never interesting.
28 * And sometimes we're only interested in "edge" commits, ie
29 * places where the marking changes between parent and child.
31 static int interesting(struct commit
*rev
)
33 unsigned mask
= cmit_flags(rev
);
38 struct commit_list
*p
= rev
->parents
;
40 if (mask
!= cmit_flags(p
->item
))
53 * Usage: git-rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id2>]
55 * The cache-file can be quite important for big trees. This is an
56 * expensive operation if you have to walk the whole chain of
57 * parents in a tree with a long revision history.
59 int main(int argc
, char **argv
)
63 unsigned char sha1
[MAX_COMMITS
][20];
64 struct commit_list
*list
= NULL
;
67 * First - pick up all the revisions we can (both from
68 * caches and from commit file chains).
70 for (i
= 1; i
< argc
; i
++) {
72 struct commit
*commit
;
74 if (!strcmp(arg
, "--cache")) {
75 read_cache_file(argv
[++i
]);
79 if (!strcmp(arg
, "--edges")) {
88 if (nr
>= MAX_COMMITS
|| get_sha1(arg
, sha1
[nr
]))
89 usage("git-rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id>]");
91 commit
= lookup_commit_reference(sha1
[nr
]);
92 if (!commit
|| parse_commit(commit
) < 0)
93 die("bad commit object");
94 commit_list_insert(commit
, &list
);
99 * Parse all the commits in date order.
101 * We really should stop once we know enough, but that's a
102 * decision that isn't trivial to make.
105 pop_most_recent_commit(&list
, REACHABLE
);
108 * Now we have the maximal tree. Walk the different sha files back to the root.
110 for (i
= 0; i
< nr
; i
++)
111 mark_reachable(&lookup_commit_reference(sha1
[i
])->object
, 1 << i
);
114 * Now print out the results..
116 for (i
= 0; i
< nr_objs
; i
++) {
117 struct object
*obj
= objs
[i
];
118 struct commit
*commit
;
119 struct commit_list
*p
;
121 if (obj
->type
!= commit_type
)
124 commit
= (struct commit
*) obj
;
126 if (!interesting(commit
))
129 printf("%lu %s:%d", commit
->date
, sha1_to_hex(obj
->sha1
),
133 printf(" %s:%d", sha1_to_hex(p
->item
->object
.sha1
),
134 cmit_flags(p
->item
));