f93ad5084d57547874da8457bcca96922c772015
1#include "test-tool.h"
2#include "cache.h"
3#include "commit.h"
4#include "commit-reach.h"
5#include "config.h"
6#include "parse-options.h"
7#include "tag.h"
8
9int cmd__reach(int ac, const char **av)
10{
11 struct object_id oid_A, oid_B;
12 struct commit *A, *B;
13 struct strbuf buf = STRBUF_INIT;
14 struct repository *r = the_repository;
15
16 setup_git_directory();
17
18 if (ac < 2)
19 exit(1);
20
21 A = B = NULL;
22
23 while (strbuf_getline(&buf, stdin) != EOF) {
24 struct object_id oid;
25 struct object *o;
26 struct commit *c;
27 if (buf.len < 3)
28 continue;
29
30 if (get_oid_committish(buf.buf + 2, &oid))
31 die("failed to resolve %s", buf.buf + 2);
32
33 o = parse_object(r, &oid);
34 o = deref_tag_noverify(o);
35
36 if (!o)
37 die("failed to load commit for input %s resulting in oid %s\n",
38 buf.buf, oid_to_hex(&oid));
39
40 c = object_as_type(r, o, OBJ_COMMIT, 0);
41
42 if (!c)
43 die("failed to load commit for input %s resulting in oid %s\n",
44 buf.buf, oid_to_hex(&oid));
45
46 switch (buf.buf[0]) {
47 case 'A':
48 oidcpy(&oid_A, &oid);
49 A = c;
50 break;
51
52 case 'B':
53 oidcpy(&oid_B, &oid);
54 B = c;
55 break;
56
57 default:
58 die("unexpected start of line: %c", buf.buf[0]);
59 }
60 }
61 strbuf_release(&buf);
62
63 if (!strcmp(av[1], "ref_newer"))
64 printf("%s(A,B):%d\n", av[1], ref_newer(&oid_A, &oid_B));
65 else if (!strcmp(av[1], "in_merge_bases"))
66 printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
67
68 exit(0);
69}