2005-04-12 22:40:03 +02:00
|
|
|
#define _XOPEN_SOURCE /* glibc2 needs this */
|
2005-04-15 17:39:57 +02:00
|
|
|
#define _BSD_SOURCE /* for tm.tm_gmtoff */
|
2005-04-12 22:40:03 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <ctype.h>
|
2005-04-14 06:37:59 +02:00
|
|
|
|
2005-04-11 22:55:10 +02:00
|
|
|
#include "cache.h"
|
2005-04-14 06:37:59 +02:00
|
|
|
#include "revision.h"
|
2005-04-11 22:55:10 +02:00
|
|
|
|
2005-04-12 02:23:58 +02:00
|
|
|
/*
|
2005-04-14 06:37:59 +02: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 02:23:58 +02:00
|
|
|
*/
|
2005-04-14 06:37:59 +02:00
|
|
|
#define MAX_COMMITS 16
|
2005-04-12 02:23:58 +02:00
|
|
|
|
|
|
|
static int show_edges = 0;
|
2005-04-12 21:35:11 +02:00
|
|
|
static int basemask = 0;
|
2005-04-12 01:42:13 +02:00
|
|
|
|
2005-04-11 22:55:10 +02:00
|
|
|
static void read_cache_file(const char *path)
|
|
|
|
{
|
|
|
|
FILE *file = fopen(path, "r");
|
2005-04-12 22:40:03 +02:00
|
|
|
char line[500];
|
2005-04-11 22:55:10 +02:00
|
|
|
|
2005-04-12 02:23:58 +02:00
|
|
|
if (!file)
|
2005-04-13 11:28:48 +02:00
|
|
|
die("bad revtree cache file (%s)", path);
|
2005-04-12 02:23:58 +02:00
|
|
|
|
2005-04-11 22:55:10 +02:00
|
|
|
while (fgets(line, sizeof(line), file)) {
|
2005-04-12 22:40:03 +02:00
|
|
|
unsigned long date;
|
|
|
|
unsigned char sha1[20];
|
2005-04-12 02:23:58 +02:00
|
|
|
struct revision *rev;
|
2005-04-12 22:40:03 +02:00
|
|
|
const char *buf;
|
|
|
|
|
|
|
|
if (sscanf(line, "%lu", &date) != 1)
|
|
|
|
break;
|
|
|
|
buf = strchr(line, ' ');
|
|
|
|
if (!buf)
|
|
|
|
break;
|
|
|
|
if (get_sha1_hex(buf+1, sha1))
|
|
|
|
break;
|
2005-04-12 02:23:58 +02:00
|
|
|
rev = lookup_rev(sha1);
|
|
|
|
rev->flags |= SEEN;
|
2005-04-12 22:40:03 +02:00
|
|
|
rev->date = date;
|
|
|
|
|
|
|
|
/* parents? */
|
|
|
|
while ((buf = strchr(buf+1, ' ')) != NULL) {
|
|
|
|
unsigned char parent[20];
|
|
|
|
if (get_sha1_hex(buf + 1, parent))
|
|
|
|
break;
|
|
|
|
add_relationship(rev, parent);
|
|
|
|
}
|
2005-04-11 22:55:10 +02:00
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-04-12 02:23:58 +02: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.
|
|
|
|
*/
|
|
|
|
static int interesting(struct revision *rev)
|
|
|
|
{
|
|
|
|
unsigned mask = marked(rev);
|
|
|
|
|
|
|
|
if (!mask)
|
|
|
|
return 0;
|
|
|
|
if (show_edges) {
|
|
|
|
struct parent *p = rev->parent;
|
|
|
|
while (p) {
|
|
|
|
if (mask != marked(p->parent))
|
|
|
|
return 1;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-12 21:35:11 +02:00
|
|
|
if (mask & basemask)
|
|
|
|
return 0;
|
|
|
|
|
2005-04-12 02:23:58 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Usage: rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id2>]
|
2005-04-11 22:55:10 +02: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 02:23:58 +02:00
|
|
|
int nr = 0;
|
|
|
|
unsigned char sha1[MAX_COMMITS][20];
|
2005-04-11 22:55:10 +02:00
|
|
|
|
2005-04-12 02:23:58 +02: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];
|
|
|
|
|
|
|
|
if (!strcmp(arg, "--cache")) {
|
2005-04-11 22:55:10 +02:00
|
|
|
read_cache_file(argv[2]);
|
2005-04-12 02:23:58 +02:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(arg, "--edges")) {
|
|
|
|
show_edges = 1;
|
2005-04-11 22:55:10 +02:00
|
|
|
continue;
|
|
|
|
}
|
2005-04-12 02:23:58 +02:00
|
|
|
|
2005-04-12 21:35:11 +02:00
|
|
|
if (arg[0] == '^') {
|
|
|
|
arg++;
|
|
|
|
basemask |= 1<<nr;
|
|
|
|
}
|
2005-04-12 02:23:58 +02:00
|
|
|
if (nr >= MAX_COMMITS || get_sha1_hex(arg, sha1[nr]))
|
|
|
|
usage("rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id>]");
|
|
|
|
parse_commit(sha1[nr]);
|
|
|
|
nr++;
|
2005-04-11 22:55:10 +02:00
|
|
|
}
|
|
|
|
|
2005-04-12 02:23:58 +02:00
|
|
|
/*
|
|
|
|
* Now we have the maximal tree. Walk the different sha files back to the root.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < nr; i++)
|
2005-04-17 21:09:20 +02:00
|
|
|
mark_reachable(lookup_rev(sha1[i]), 1 << i);
|
2005-04-12 02:23:58 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now print out the results..
|
|
|
|
*/
|
2005-04-12 01:42:13 +02:00
|
|
|
for (i = 0; i < nr_revs; i++) {
|
|
|
|
struct revision *rev = revs[i];
|
|
|
|
struct parent *p;
|
|
|
|
|
2005-04-12 02:23:58 +02:00
|
|
|
if (!interesting(rev))
|
|
|
|
continue;
|
|
|
|
|
2005-04-12 22:40:03 +02:00
|
|
|
printf("%lu %s:%d", rev->date, sha1_to_hex(rev->sha1), marked(rev));
|
2005-04-12 01:42:13 +02:00
|
|
|
p = rev->parent;
|
|
|
|
while (p) {
|
2005-04-12 02:40:58 +02:00
|
|
|
printf(" %s:%d", sha1_to_hex(p->parent->sha1), marked(p->parent));
|
2005-04-12 01:42:13 +02:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
printf("\n");
|
2005-04-11 22:55:10 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|