4 #include "commit-reach.h"
6 #include "parse-options.h"
7 #include "string-list.h"
10 static void print_sorted_commit_ids(struct commit_list *list)
13 struct string_list s = STRING_LIST_INIT_DUP;
16 string_list_append(&s, oid_to_hex(&list->item->object.oid));
22 for (i = 0; i < s.nr; i++)
23 printf("%s\n", s.items[i].string);
25 string_list_clear(&s, 0);
28 int cmd__reach(int ac, const char **av)
30 struct object_id oid_A, oid_B;
32 struct commit_list *X;
33 struct commit **X_array;
35 struct strbuf buf = STRBUF_INIT;
36 struct repository *r = the_repository;
38 setup_git_directory();
47 ALLOC_ARRAY(X_array, X_alloc);
49 while (strbuf_getline(&buf, stdin) != EOF) {
56 if (get_oid_committish(buf.buf + 2, &oid))
57 die("failed to resolve %s", buf.buf + 2);
59 o = parse_object(r, &oid);
60 o = deref_tag_noverify(o);
63 die("failed to load commit for input %s resulting in oid %s\n",
64 buf.buf, oid_to_hex(&oid));
66 c = object_as_type(r, o, OBJ_COMMIT, 0);
69 die("failed to load commit for input %s resulting in oid %s\n",
70 buf.buf, oid_to_hex(&oid));
84 commit_list_insert(c, &X);
85 ALLOC_GROW(X_array, X_nr + 1, X_alloc);
90 die("unexpected start of line: %c", buf.buf[0]);
95 if (!strcmp(av[1], "ref_newer"))
96 printf("%s(A,B):%d\n", av[1], ref_newer(&oid_A, &oid_B));
97 else if (!strcmp(av[1], "in_merge_bases"))
98 printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
99 else if (!strcmp(av[1], "is_descendant_of"))
100 printf("%s(A,X):%d\n", av[1], is_descendant_of(A, X));
101 else if (!strcmp(av[1], "get_merge_bases_many")) {
102 struct commit_list *list = get_merge_bases_many(A, X_nr, X_array);
103 printf("%s(A,X):\n", av[1]);
104 print_sorted_commit_ids(list);