Update README to reflect the hierarchical tree objects,
[git/spearce.git] / merge-base.c
blobdac5e4b5e0da239dccc0ee1d43ffc6fb35e1a817
1 #include "cache.h"
2 #include "revision.h"
4 /*
5 * This is stupid. We could have much better heurstics, I bet.
6 */
7 static int better(struct revision *new, struct revision *old)
9 return new->date > old->date;
12 static struct revision *common_parent(struct revision *rev1, struct revision *rev2)
14 int i;
15 struct revision *best = NULL;
17 mark_reachable(rev1, 1);
18 mark_reachable(rev2, 2);
19 for (i = 0; i < nr_revs ;i++) {
20 struct revision *rev = revs[i];
21 if ((rev->flags & 3) != 3)
22 continue;
23 if (!best) {
24 best = rev;
25 continue;
27 if (better(rev, best))
28 best = rev;
30 return best;
33 int main(int argc, char **argv)
35 unsigned char rev1[20], rev2[20];
36 struct revision *common;
38 if (argc != 3 || get_sha1_hex(argv[1], rev1) || get_sha1_hex(argv[2], rev2))
39 usage("merge-base <commit1> <commit2>");
42 * We will eventually want to include a revision cache file
43 * that "rev-tree.c" has generated, since this is going to
44 * otherwise be quite expensive for big trees..
46 * That's some time off, though, and in the meantime we know
47 * that we have a solution to the eventual expense.
49 common = common_parent(parse_commit(rev1), parse_commit(rev2));
50 if (!common)
51 die("no common parent found");
52 printf("%s\n", sha1_to_hex(common->sha1));
53 return 0;