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