From 57836f10ad47c2b2c3b94502024758871841091f Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sun, 26 Mar 2017 16:01:32 +0000 Subject: test-sha1-array: convert most code to struct object_id This helper is very small, so convert the entire thing. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/helper/test-sha1-array.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 't/helper') diff --git a/t/helper/test-sha1-array.c b/t/helper/test-sha1-array.c index f7a53c4ad6..b4bb97fccc 100644 --- a/t/helper/test-sha1-array.c +++ b/t/helper/test-sha1-array.c @@ -14,16 +14,16 @@ int cmd_main(int argc, const char **argv) while (strbuf_getline(&line, stdin) != EOF) { const char *arg; - unsigned char sha1[20]; + struct object_id oid; if (skip_prefix(line.buf, "append ", &arg)) { - if (get_sha1_hex(arg, sha1)) + if (get_oid_hex(arg, &oid)) die("not a hexadecimal SHA1: %s", arg); - sha1_array_append(&array, sha1); + sha1_array_append(&array, oid.hash); } else if (skip_prefix(line.buf, "lookup ", &arg)) { - if (get_sha1_hex(arg, sha1)) + if (get_oid_hex(arg, &oid)) die("not a hexadecimal SHA1: %s", arg); - printf("%d\n", sha1_array_lookup(&array, sha1)); + printf("%d\n", sha1_array_lookup(&array, oid.hash)); } else if (!strcmp(line.buf, "clear")) sha1_array_clear(&array); else if (!strcmp(line.buf, "for_each_unique")) -- cgit v1.2.3 From 98a72ddc12e13231537150607f4a6a8ff8b43854 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Fri, 31 Mar 2017 01:39:56 +0000 Subject: Make sha1_array_append take a struct object_id * Convert the callers to pass struct object_id by changing the function declaration and definition and applying the following semantic patch: @@ expression E1, E2; @@ - sha1_array_append(E1, E2.hash) + sha1_array_append(E1, &E2) @@ expression E1, E2; @@ - sha1_array_append(E1, E2->hash) + sha1_array_append(E1, E2) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/helper/test-sha1-array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/helper') diff --git a/t/helper/test-sha1-array.c b/t/helper/test-sha1-array.c index b4bb97fccc..181c36e0a5 100644 --- a/t/helper/test-sha1-array.c +++ b/t/helper/test-sha1-array.c @@ -19,7 +19,7 @@ int cmd_main(int argc, const char **argv) if (skip_prefix(line.buf, "append ", &arg)) { if (get_oid_hex(arg, &oid)) die("not a hexadecimal SHA1: %s", arg); - sha1_array_append(&array, oid.hash); + sha1_array_append(&array, &oid); } else if (skip_prefix(line.buf, "lookup ", &arg)) { if (get_oid_hex(arg, &oid)) die("not a hexadecimal SHA1: %s", arg); -- cgit v1.2.3 From 5d3206d5010423b3bbf479e32567d0fddc7095e0 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Fri, 31 Mar 2017 01:39:58 +0000 Subject: Convert sha1_array_lookup to take struct object_id Convert this function by changing the declaration and definition and applying the following semantic patch to update the callers: @@ expression E1, E2; @@ - sha1_array_lookup(E1, E2.hash) + sha1_array_lookup(E1, &E2) @@ expression E1, E2; @@ - sha1_array_lookup(E1, E2->hash) + sha1_array_lookup(E1, E2) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/helper/test-sha1-array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/helper') diff --git a/t/helper/test-sha1-array.c b/t/helper/test-sha1-array.c index 181c36e0a5..3680511849 100644 --- a/t/helper/test-sha1-array.c +++ b/t/helper/test-sha1-array.c @@ -23,7 +23,7 @@ int cmd_main(int argc, const char **argv) } else if (skip_prefix(line.buf, "lookup ", &arg)) { if (get_oid_hex(arg, &oid)) die("not a hexadecimal SHA1: %s", arg); - printf("%d\n", sha1_array_lookup(&array, oid.hash)); + printf("%d\n", sha1_array_lookup(&array, &oid)); } else if (!strcmp(line.buf, "clear")) sha1_array_clear(&array); else if (!strcmp(line.buf, "for_each_unique")) -- cgit v1.2.3 From 1b7ba794d21836f72e5888db63ab790077c04e1b Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Fri, 31 Mar 2017 01:39:59 +0000 Subject: Convert sha1_array_for_each_unique and for_each_abbrev to object_id Make sha1_array_for_each_unique take a callback using struct object_id. Since one of these callbacks is an argument to for_each_abbrev, convert those as well. Rename various functions, replacing "sha1" with "oid". Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/helper/test-sha1-array.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 't/helper') diff --git a/t/helper/test-sha1-array.c b/t/helper/test-sha1-array.c index 3680511849..2f3d406b63 100644 --- a/t/helper/test-sha1-array.c +++ b/t/helper/test-sha1-array.c @@ -1,9 +1,9 @@ #include "cache.h" #include "sha1-array.h" -static int print_sha1(const unsigned char sha1[20], void *data) +static int print_oid(const struct object_id *oid, void *data) { - puts(sha1_to_hex(sha1)); + puts(oid_to_hex(oid)); return 0; } @@ -27,7 +27,7 @@ int cmd_main(int argc, const char **argv) } else if (!strcmp(line.buf, "clear")) sha1_array_clear(&array); else if (!strcmp(line.buf, "for_each_unique")) - sha1_array_for_each_unique(&array, print_sha1, NULL); + sha1_array_for_each_unique(&array, print_oid, NULL); else die("unknown command: %s", line.buf); } -- cgit v1.2.3 From 910650d2f8755359ab7b1f0e2a2d576c06a68091 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Fri, 31 Mar 2017 01:40:00 +0000 Subject: Rename sha1_array to oid_array Since this structure handles an array of object IDs, rename it to struct oid_array. Also rename the accessor functions and the initialization constant. This commit was produced mechanically by providing non-Documentation files to the following Perl one-liners: perl -pi -E 's/struct sha1_array/struct oid_array/g' perl -pi -E 's/\bsha1_array_/oid_array_/g' perl -pi -E 's/SHA1_ARRAY_INIT/OID_ARRAY_INIT/g' Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/helper/test-sha1-array.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 't/helper') diff --git a/t/helper/test-sha1-array.c b/t/helper/test-sha1-array.c index 2f3d406b63..edfd52d82a 100644 --- a/t/helper/test-sha1-array.c +++ b/t/helper/test-sha1-array.c @@ -9,7 +9,7 @@ static int print_oid(const struct object_id *oid, void *data) int cmd_main(int argc, const char **argv) { - struct sha1_array array = SHA1_ARRAY_INIT; + struct oid_array array = OID_ARRAY_INIT; struct strbuf line = STRBUF_INIT; while (strbuf_getline(&line, stdin) != EOF) { @@ -19,15 +19,15 @@ int cmd_main(int argc, const char **argv) if (skip_prefix(line.buf, "append ", &arg)) { if (get_oid_hex(arg, &oid)) die("not a hexadecimal SHA1: %s", arg); - sha1_array_append(&array, &oid); + oid_array_append(&array, &oid); } else if (skip_prefix(line.buf, "lookup ", &arg)) { if (get_oid_hex(arg, &oid)) die("not a hexadecimal SHA1: %s", arg); - printf("%d\n", sha1_array_lookup(&array, &oid)); + printf("%d\n", oid_array_lookup(&array, &oid)); } else if (!strcmp(line.buf, "clear")) - sha1_array_clear(&array); + oid_array_clear(&array); else if (!strcmp(line.buf, "for_each_unique")) - sha1_array_for_each_unique(&array, print_oid, NULL); + oid_array_for_each_unique(&array, print_oid, NULL); else die("unknown command: %s", line.buf); } -- cgit v1.2.3