dccbd48178416d2ecc5c2a3261821bc4670dad0f
   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 commit_list *X;
  14        struct strbuf buf = STRBUF_INIT;
  15        struct repository *r = the_repository;
  16
  17        setup_git_directory();
  18
  19        if (ac < 2)
  20                exit(1);
  21
  22        A = B = NULL;
  23        X = NULL;
  24
  25        while (strbuf_getline(&buf, stdin) != EOF) {
  26                struct object_id oid;
  27                struct object *o;
  28                struct commit *c;
  29                if (buf.len < 3)
  30                        continue;
  31
  32                if (get_oid_committish(buf.buf + 2, &oid))
  33                        die("failed to resolve %s", buf.buf + 2);
  34
  35                o = parse_object(r, &oid);
  36                o = deref_tag_noverify(o);
  37
  38                if (!o)
  39                        die("failed to load commit for input %s resulting in oid %s\n",
  40                            buf.buf, oid_to_hex(&oid));
  41
  42                c = object_as_type(r, o, OBJ_COMMIT, 0);
  43
  44                if (!c)
  45                        die("failed to load commit for input %s resulting in oid %s\n",
  46                            buf.buf, oid_to_hex(&oid));
  47
  48                switch (buf.buf[0]) {
  49                        case 'A':
  50                                oidcpy(&oid_A, &oid);
  51                                A = c;
  52                                break;
  53
  54                        case 'B':
  55                                oidcpy(&oid_B, &oid);
  56                                B = c;
  57                                break;
  58
  59                        case 'X':
  60                                commit_list_insert(c, &X);
  61                                break;
  62
  63                        default:
  64                                die("unexpected start of line: %c", buf.buf[0]);
  65                }
  66        }
  67        strbuf_release(&buf);
  68
  69        if (!strcmp(av[1], "ref_newer"))
  70                printf("%s(A,B):%d\n", av[1], ref_newer(&oid_A, &oid_B));
  71        else if (!strcmp(av[1], "in_merge_bases"))
  72                printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
  73        else if (!strcmp(av[1], "is_descendant_of"))
  74                printf("%s(A,X):%d\n", av[1], is_descendant_of(A, X));
  75
  76        exit(0);
  77}