1#include"cache.h" 2#include"revision.h" 3 4/* 5 * This is stupid. We could have much better heurstics, I bet. 6 */ 7static intbetter(struct revision *new,struct revision *old) 8{ 9return new->date > old->date; 10} 11 12static struct revision *common_parent(struct revision *rev1,struct revision *rev2) 13{ 14int i; 15struct revision *best = NULL; 16 17mark_reachable(rev1,1); 18mark_reachable(rev2,2); 19for(i =0; i < nr_revs ;i++) { 20struct revision *rev = revs[i]; 21if((rev->flags &3) !=3) 22continue; 23if(!best) { 24 best = rev; 25continue; 26} 27if(better(rev, best)) 28 best = rev; 29} 30return best; 31} 32 33intmain(int argc,char**argv) 34{ 35unsigned char rev1[20], rev2[20]; 36struct revision *common; 37 38if(argc !=3||get_sha1_hex(argv[1], rev1) ||get_sha1_hex(argv[2], rev2)) 39usage("merge-base <commit1> <commit2>"); 40 41/* 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.. 45 * 46 * That's some time off, though, and in the meantime we know 47 * that we have a solution to the eventual expense. 48 */ 49parse_commit(rev1); 50parse_commit(rev2); 51 52 common =common_parent(lookup_rev(rev1),lookup_rev(rev2)); 53if(!common) 54die("no common parent found"); 55printf("%s\n",sha1_to_hex(common->sha1)); 56return0; 57}