2018-03-24 07:44:57 +00:00
|
|
|
#include "test-tool.h"
|
2023-02-24 00:09:27 +00:00
|
|
|
#include "hex.h"
|
2020-03-30 14:03:46 +00:00
|
|
|
#include "oid-array.h"
|
2023-03-21 06:26:05 +00:00
|
|
|
#include "setup.h"
|
2023-04-22 20:17:08 +00:00
|
|
|
#include "strbuf.h"
|
2014-10-01 15:00:33 +00:00
|
|
|
|
2023-07-03 06:44:36 +00:00
|
|
|
static int print_oid(const struct object_id *oid, void *data UNUSED)
|
2014-10-01 15:00:33 +00:00
|
|
|
{
|
2017-03-31 01:39:59 +00:00
|
|
|
puts(oid_to_hex(oid));
|
2016-09-26 12:00:29 +00:00
|
|
|
return 0;
|
2014-10-01 15:00:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-28 20:57:25 +00:00
|
|
|
int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
|
2014-10-01 15:00:33 +00:00
|
|
|
{
|
2017-03-31 01:40:00 +00:00
|
|
|
struct oid_array array = OID_ARRAY_INIT;
|
2014-10-01 15:00:33 +00:00
|
|
|
struct strbuf line = STRBUF_INIT;
|
2020-06-19 17:55:55 +00:00
|
|
|
int nongit_ok;
|
|
|
|
|
|
|
|
setup_git_directory_gently(&nongit_ok);
|
2014-10-01 15:00:33 +00:00
|
|
|
|
2015-10-28 20:32:10 +00:00
|
|
|
while (strbuf_getline(&line, stdin) != EOF) {
|
2014-10-01 15:00:33 +00:00
|
|
|
const char *arg;
|
2017-03-26 16:01:32 +00:00
|
|
|
struct object_id oid;
|
2014-10-01 15:00:33 +00:00
|
|
|
|
|
|
|
if (skip_prefix(line.buf, "append ", &arg)) {
|
2017-03-26 16:01:32 +00:00
|
|
|
if (get_oid_hex(arg, &oid))
|
2020-03-30 14:04:03 +00:00
|
|
|
die("not a hexadecimal oid: %s", arg);
|
2017-03-31 01:40:00 +00:00
|
|
|
oid_array_append(&array, &oid);
|
2014-10-01 15:00:33 +00:00
|
|
|
} else if (skip_prefix(line.buf, "lookup ", &arg)) {
|
2017-03-26 16:01:32 +00:00
|
|
|
if (get_oid_hex(arg, &oid))
|
2020-03-30 14:04:03 +00:00
|
|
|
die("not a hexadecimal oid: %s", arg);
|
2017-03-31 01:40:00 +00:00
|
|
|
printf("%d\n", oid_array_lookup(&array, &oid));
|
2014-10-01 15:00:33 +00:00
|
|
|
} else if (!strcmp(line.buf, "clear"))
|
2017-03-31 01:40:00 +00:00
|
|
|
oid_array_clear(&array);
|
2014-10-01 15:00:33 +00:00
|
|
|
else if (!strcmp(line.buf, "for_each_unique"))
|
2017-03-31 01:40:00 +00:00
|
|
|
oid_array_for_each_unique(&array, print_oid, NULL);
|
2014-10-01 15:00:33 +00:00
|
|
|
else
|
|
|
|
die("unknown command: %s", line.buf);
|
|
|
|
}
|
2021-10-07 10:01:34 +00:00
|
|
|
|
|
|
|
strbuf_release(&line);
|
|
|
|
oid_array_clear(&array);
|
|
|
|
|
2014-10-01 15:00:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|