2005-04-12 04:55:10 +08:00
|
|
|
#include "cache.h"
|
2005-04-19 02:39:48 +08:00
|
|
|
#include "commit.h"
|
2005-04-12 04:55:10 +08:00
|
|
|
|
2005-04-12 08:23:58 +08:00
|
|
|
/*
|
2005-04-14 12:37:59 +08:00
|
|
|
* revision.h leaves the low 16 bits of the "flags" field of the
|
|
|
|
* revision data structure unused. We use it for a "reachable from
|
|
|
|
* this commit <N>" bitmask.
|
2005-04-12 08:23:58 +08:00
|
|
|
*/
|
2005-04-14 12:37:59 +08:00
|
|
|
#define MAX_COMMITS 16
|
2005-05-25 12:34:12 +08:00
|
|
|
#define REACHABLE (1U << 16)
|
|
|
|
|
|
|
|
#define cmit_flags(cmit) ((cmit)->object.flags & ~REACHABLE)
|
2005-04-12 08:23:58 +08:00
|
|
|
|
|
|
|
static int show_edges = 0;
|
2005-04-13 03:35:11 +08:00
|
|
|
static int basemask = 0;
|
2005-04-12 07:42:13 +08:00
|
|
|
|
2005-04-12 04:55:10 +08:00
|
|
|
static void read_cache_file(const char *path)
|
|
|
|
{
|
2005-04-19 02:39:48 +08:00
|
|
|
die("no revtree cache file yet");
|
2005-04-12 04:55:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-04-12 08:23:58 +08:00
|
|
|
* Some revisions are less interesting than others.
|
|
|
|
*
|
|
|
|
* For example, if we use a cache-file, that one may contain
|
|
|
|
* revisions that were never used. They are never interesting.
|
|
|
|
*
|
|
|
|
* And sometimes we're only interested in "edge" commits, ie
|
|
|
|
* places where the marking changes between parent and child.
|
|
|
|
*/
|
2005-04-19 02:39:48 +08:00
|
|
|
static int interesting(struct commit *rev)
|
2005-04-12 08:23:58 +08:00
|
|
|
{
|
2005-05-25 12:34:12 +08:00
|
|
|
unsigned mask = cmit_flags(rev);
|
2005-04-12 08:23:58 +08:00
|
|
|
|
|
|
|
if (!mask)
|
|
|
|
return 0;
|
|
|
|
if (show_edges) {
|
2005-04-19 02:39:48 +08:00
|
|
|
struct commit_list *p = rev->parents;
|
2005-04-12 08:23:58 +08:00
|
|
|
while (p) {
|
2005-05-25 12:34:12 +08:00
|
|
|
if (mask != cmit_flags(p->item))
|
2005-04-12 08:23:58 +08:00
|
|
|
return 1;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-13 03:35:11 +08:00
|
|
|
if (mask & basemask)
|
|
|
|
return 0;
|
|
|
|
|
2005-04-12 08:23:58 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-05-19 19:17:16 +08:00
|
|
|
* Usage: git-rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id2>]
|
2005-04-12 04:55:10 +08:00
|
|
|
*
|
|
|
|
* The cache-file can be quite important for big trees. This is an
|
|
|
|
* expensive operation if you have to walk the whole chain of
|
|
|
|
* parents in a tree with a long revision history.
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
2005-04-12 08:23:58 +08:00
|
|
|
int nr = 0;
|
|
|
|
unsigned char sha1[MAX_COMMITS][20];
|
2005-05-25 12:34:12 +08:00
|
|
|
struct commit_list *list = NULL;
|
2005-04-12 04:55:10 +08:00
|
|
|
|
2005-04-12 08:23:58 +08:00
|
|
|
/*
|
|
|
|
* First - pick up all the revisions we can (both from
|
|
|
|
* caches and from commit file chains).
|
|
|
|
*/
|
|
|
|
for (i = 1; i < argc ; i++) {
|
|
|
|
char *arg = argv[i];
|
2005-05-25 12:34:12 +08:00
|
|
|
struct commit *commit;
|
2005-04-12 08:23:58 +08:00
|
|
|
|
|
|
|
if (!strcmp(arg, "--cache")) {
|
2005-04-22 00:58:24 +08:00
|
|
|
read_cache_file(argv[++i]);
|
2005-04-12 08:23:58 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(arg, "--edges")) {
|
|
|
|
show_edges = 1;
|
2005-04-12 04:55:10 +08:00
|
|
|
continue;
|
|
|
|
}
|
2005-04-12 08:23:58 +08:00
|
|
|
|
2005-04-13 03:35:11 +08:00
|
|
|
if (arg[0] == '^') {
|
|
|
|
arg++;
|
|
|
|
basemask |= 1<<nr;
|
|
|
|
}
|
2005-05-02 07:36:56 +08:00
|
|
|
if (nr >= MAX_COMMITS || get_sha1(arg, sha1[nr]))
|
2005-05-19 19:17:16 +08:00
|
|
|
usage("git-rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id>]");
|
2005-05-25 12:34:12 +08:00
|
|
|
|
|
|
|
commit = lookup_commit_reference(sha1[nr]);
|
|
|
|
if (!commit || parse_commit(commit) < 0)
|
|
|
|
die("bad commit object");
|
|
|
|
commit_list_insert(commit, &list);
|
2005-04-12 08:23:58 +08:00
|
|
|
nr++;
|
2005-04-12 04:55:10 +08:00
|
|
|
}
|
|
|
|
|
2005-05-25 12:34:12 +08:00
|
|
|
/*
|
|
|
|
* Parse all the commits in date order.
|
|
|
|
*
|
|
|
|
* We really should stop once we know enough, but that's a
|
|
|
|
* decision that isn't trivial to make.
|
|
|
|
*/
|
|
|
|
while (list)
|
|
|
|
pop_most_recent_commit(&list, REACHABLE);
|
|
|
|
|
2005-04-12 08:23:58 +08:00
|
|
|
/*
|
|
|
|
* Now we have the maximal tree. Walk the different sha files back to the root.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < nr; i++)
|
2005-05-25 12:34:12 +08:00
|
|
|
mark_reachable(&lookup_commit_reference(sha1[i])->object, 1 << i);
|
2005-04-12 08:23:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now print out the results..
|
|
|
|
*/
|
2005-04-19 02:39:48 +08:00
|
|
|
for (i = 0; i < nr_objs; i++) {
|
|
|
|
struct object *obj = objs[i];
|
|
|
|
struct commit *commit;
|
|
|
|
struct commit_list *p;
|
|
|
|
|
|
|
|
if (obj->type != commit_type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
commit = (struct commit *) obj;
|
2005-04-12 07:42:13 +08:00
|
|
|
|
2005-04-19 02:39:48 +08:00
|
|
|
if (!interesting(commit))
|
2005-04-12 08:23:58 +08:00
|
|
|
continue;
|
|
|
|
|
2005-05-25 12:34:12 +08:00
|
|
|
printf("%lu %s:%d", commit->date, sha1_to_hex(obj->sha1),
|
|
|
|
cmit_flags(commit));
|
2005-04-19 02:39:48 +08:00
|
|
|
p = commit->parents;
|
2005-04-12 07:42:13 +08:00
|
|
|
while (p) {
|
2005-04-19 02:39:48 +08:00
|
|
|
printf(" %s:%d", sha1_to_hex(p->item->object.sha1),
|
2005-05-25 12:34:12 +08:00
|
|
|
cmit_flags(p->item));
|
2005-04-12 07:42:13 +08:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
printf("\n");
|
2005-04-12 04:55:10 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|