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