5 static enum cb_next
print_oid(const struct object_id
*oid
, void *data
)
11 int cmd__oidtree(int argc
, const char **argv
)
14 struct strbuf line
= STRBUF_INIT
;
16 int algo
= GIT_HASH_UNKNOWN
;
19 setup_git_directory_gently(&nongit_ok
);
21 while (strbuf_getline(&line
, stdin
) != EOF
) {
25 if (skip_prefix(line
.buf
, "insert ", &arg
)) {
26 if (get_oid_hex_any(arg
, &oid
) == GIT_HASH_UNKNOWN
)
27 die("insert not a hexadecimal oid: %s", arg
);
29 oidtree_insert(&ot
, &oid
);
30 } else if (skip_prefix(line
.buf
, "contains ", &arg
)) {
31 if (get_oid_hex(arg
, &oid
))
32 die("contains not a hexadecimal oid: %s", arg
);
33 printf("%d\n", oidtree_contains(&ot
, &oid
));
34 } else if (skip_prefix(line
.buf
, "each ", &arg
)) {
35 char buf
[GIT_MAX_HEXSZ
+ 1] = { '0' };
36 memset(&oid
, 0, sizeof(oid
));
37 memcpy(buf
, arg
, strlen(arg
));
38 buf
[hash_algos
[algo
].hexsz
] = '\0';
39 get_oid_hex_any(buf
, &oid
);
41 oidtree_each(&ot
, &oid
, strlen(arg
), print_oid
, NULL
);
42 } else if (!strcmp(line
.buf
, "clear")) {
45 die("unknown command: %s", line
.buf
);
49 strbuf_release(&line
);