Merge branch 'jk/oid-array-cleanups'

Code cleanup.

* jk/oid-array-cleanups:
  oidset: stop referring to sha1-array
  ref-filter: stop referring to "sha1 array"
  bisect: stop referring to sha1_array
  test-tool: rename sha1-array to oid-array
  oid_array: rename source file from sha1-array
  oid_array: use size_t for iteration
  oid_array: use size_t for count and allocation
This commit is contained in:
Junio C Hamano 2020-04-22 13:42:49 -07:00
commit a768f866e9
32 changed files with 54 additions and 55 deletions

View File

@ -738,7 +738,7 @@ TEST_BUILTINS_OBJS += test-run-command.o
TEST_BUILTINS_OBJS += test-scrap-cache-tree.o TEST_BUILTINS_OBJS += test-scrap-cache-tree.o
TEST_BUILTINS_OBJS += test-serve-v2.o TEST_BUILTINS_OBJS += test-serve-v2.o
TEST_BUILTINS_OBJS += test-sha1.o TEST_BUILTINS_OBJS += test-sha1.o
TEST_BUILTINS_OBJS += test-sha1-array.o TEST_BUILTINS_OBJS += test-oid-array.o
TEST_BUILTINS_OBJS += test-sha256.o TEST_BUILTINS_OBJS += test-sha256.o
TEST_BUILTINS_OBJS += test-sigchain.o TEST_BUILTINS_OBJS += test-sigchain.o
TEST_BUILTINS_OBJS += test-strcmp-offset.o TEST_BUILTINS_OBJS += test-strcmp-offset.o
@ -929,6 +929,7 @@ LIB_OBJS += notes-utils.o
LIB_OBJS += object.o LIB_OBJS += object.o
LIB_OBJS += oidmap.o LIB_OBJS += oidmap.o
LIB_OBJS += oidset.o LIB_OBJS += oidset.o
LIB_OBJS += oid-array.o
LIB_OBJS += packfile.o LIB_OBJS += packfile.o
LIB_OBJS += pack-bitmap.o LIB_OBJS += pack-bitmap.o
LIB_OBJS += pack-bitmap-write.o LIB_OBJS += pack-bitmap-write.o
@ -978,7 +979,6 @@ LIB_OBJS += sequencer.o
LIB_OBJS += serve.o LIB_OBJS += serve.o
LIB_OBJS += server-info.o LIB_OBJS += server-info.o
LIB_OBJS += setup.o LIB_OBJS += setup.o
LIB_OBJS += sha1-array.o
LIB_OBJS += sha1-lookup.o LIB_OBJS += sha1-lookup.o
LIB_OBJS += sha1-file.o LIB_OBJS += sha1-file.o
LIB_OBJS += sha1-name.o LIB_OBJS += sha1-name.o

View File

@ -10,7 +10,7 @@
#include "run-command.h" #include "run-command.h"
#include "log-tree.h" #include "log-tree.h"
#include "bisect.h" #include "bisect.h"
#include "sha1-array.h" #include "oid-array.h"
#include "argv-array.h" #include "argv-array.h"
#include "commit-slab.h" #include "commit-slab.h"
#include "commit-reach.h" #include "commit-reach.h"
@ -473,7 +473,7 @@ static void read_bisect_paths(struct argv_array *array)
fclose(fp); fclose(fp);
} }
static char *join_sha1_array_hex(struct oid_array *array, char delim) static char *join_oid_array_hex(struct oid_array *array, char delim)
{ {
struct strbuf joined_hexs = STRBUF_INIT; struct strbuf joined_hexs = STRBUF_INIT;
int i; int i;
@ -765,7 +765,7 @@ static enum bisect_error handle_bad_merge_base(void)
{ {
if (is_expected_rev(current_bad_oid)) { if (is_expected_rev(current_bad_oid)) {
char *bad_hex = oid_to_hex(current_bad_oid); char *bad_hex = oid_to_hex(current_bad_oid);
char *good_hex = join_sha1_array_hex(&good_revs, ' '); char *good_hex = join_oid_array_hex(&good_revs, ' ');
if (!strcmp(term_bad, "bad") && !strcmp(term_good, "good")) { if (!strcmp(term_bad, "bad") && !strcmp(term_good, "good")) {
fprintf(stderr, _("The merge base %s is bad.\n" fprintf(stderr, _("The merge base %s is bad.\n"
"This means the bug has been fixed " "This means the bug has been fixed "
@ -796,7 +796,7 @@ static void handle_skipped_merge_base(const struct object_id *mb)
{ {
char *mb_hex = oid_to_hex(mb); char *mb_hex = oid_to_hex(mb);
char *bad_hex = oid_to_hex(current_bad_oid); char *bad_hex = oid_to_hex(current_bad_oid);
char *good_hex = join_sha1_array_hex(&good_revs, ' '); char *good_hex = join_oid_array_hex(&good_revs, ' ');
warning(_("the merge base between %s and [%s] " warning(_("the merge base between %s and [%s] "
"must be skipped.\n" "must be skipped.\n"

View File

@ -12,7 +12,7 @@
#include "userdiff.h" #include "userdiff.h"
#include "streaming.h" #include "streaming.h"
#include "tree-walk.h" #include "tree-walk.h"
#include "sha1-array.h" #include "oid-array.h"
#include "packfile.h" #include "packfile.h"
#include "object-store.h" #include "object-store.h"
#include "promisor-remote.h" #include "promisor-remote.h"

View File

@ -17,7 +17,7 @@
#include "log-tree.h" #include "log-tree.h"
#include "builtin.h" #include "builtin.h"
#include "submodule.h" #include "submodule.h"
#include "sha1-array.h" #include "oid-array.h"
#define DIFF_NO_INDEX_EXPLICIT 1 #define DIFF_NO_INDEX_EXPLICIT 1
#define DIFF_NO_INDEX_IMPLICIT 2 #define DIFF_NO_INDEX_IMPLICIT 2

View File

@ -3,7 +3,7 @@
#include "fetch-pack.h" #include "fetch-pack.h"
#include "remote.h" #include "remote.h"
#include "connect.h" #include "connect.h"
#include "sha1-array.h" #include "oid-array.h"
#include "protocol.h" #include "protocol.h"
static const char fetch_pack_usage[] = static const char fetch_pack_usage[] =

View File

@ -26,7 +26,7 @@
#include "pack-bitmap.h" #include "pack-bitmap.h"
#include "delta-islands.h" #include "delta-islands.h"
#include "reachable.h" #include "reachable.h"
#include "sha1-array.h" #include "oid-array.h"
#include "argv-array.h" #include "argv-array.h"
#include "list.h" #include "list.h"
#include "packfile.h" #include "packfile.h"

View File

@ -12,7 +12,7 @@
#include "parse-options.h" #include "parse-options.h"
#include "exec-cmd.h" #include "exec-cmd.h"
#include "run-command.h" #include "run-command.h"
#include "sha1-array.h" #include "oid-array.h"
#include "remote.h" #include "remote.h"
#include "dir.h" #include "dir.h"
#include "rebase.h" #include "rebase.h"

View File

@ -13,7 +13,7 @@
#include "remote.h" #include "remote.h"
#include "connect.h" #include "connect.h"
#include "string-list.h" #include "string-list.h"
#include "sha1-array.h" #include "oid-array.h"
#include "connected.h" #include "connected.h"
#include "argv-array.h" #include "argv-array.h"
#include "version.h" #include "version.h"

View File

@ -11,7 +11,7 @@
#include "quote.h" #include "quote.h"
#include "transport.h" #include "transport.h"
#include "version.h" #include "version.h"
#include "sha1-array.h" #include "oid-array.h"
#include "gpg-interface.h" #include "gpg-interface.h"
#include "gettext.h" #include "gettext.h"
#include "protocol.h" #include "protocol.h"

View File

@ -17,7 +17,7 @@
#include "diff.h" #include "diff.h"
#include "revision.h" #include "revision.h"
#include "gpg-interface.h" #include "gpg-interface.h"
#include "sha1-array.h" #include "oid-array.h"
#include "column.h" #include "column.h"
#include "ref-filter.h" #include "ref-filter.h"

View File

@ -14,7 +14,7 @@
#include "pack-revindex.h" #include "pack-revindex.h"
#include "hash.h" #include "hash.h"
#include "path.h" #include "path.h"
#include "sha1-array.h" #include "oid-array.h"
#include "repository.h" #include "repository.h"
#include "mem-pool.h" #include "mem-pool.h"

View File

@ -10,7 +10,7 @@
#include "log-tree.h" #include "log-tree.h"
#include "refs.h" #include "refs.h"
#include "userdiff.h" #include "userdiff.h"
#include "sha1-array.h" #include "oid-array.h"
#include "revision.h" #include "revision.h"
static int compare_paths(const struct combine_diff_path *one, static int compare_paths(const struct combine_diff_path *one,

View File

@ -9,7 +9,7 @@
#include "connect.h" #include "connect.h"
#include "url.h" #include "url.h"
#include "string-list.h" #include "string-list.h"
#include "sha1-array.h" #include "oid-array.h"
#include "transport.h" #include "transport.h"
#include "strbuf.h" #include "strbuf.h"
#include "version.h" #include "version.h"

View File

@ -17,7 +17,7 @@
#include "pack-bitmap.h" #include "pack-bitmap.h"
#include "pack-objects.h" #include "pack-objects.h"
#include "delta-islands.h" #include "delta-islands.h"
#include "sha1-array.h" #include "oid-array.h"
#include "config.h" #include "config.h"
KHASH_INIT(str, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) KHASH_INIT(str, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)

View File

@ -15,7 +15,7 @@
#include "connect.h" #include "connect.h"
#include "transport.h" #include "transport.h"
#include "version.h" #include "version.h"
#include "sha1-array.h" #include "oid-array.h"
#include "oidset.h" #include "oidset.h"
#include "packfile.h" #include "packfile.h"
#include "object-store.h" #include "object-store.h"

View File

@ -4,7 +4,7 @@
#include "cache.h" #include "cache.h"
#include "oidmap.h" #include "oidmap.h"
#include "list.h" #include "list.h"
#include "sha1-array.h" #include "oid-array.h"
#include "strbuf.h" #include "strbuf.h"
#include "thread-utils.h" #include "thread-utils.h"

View File

@ -1,5 +1,5 @@
#include "cache.h" #include "cache.h"
#include "sha1-array.h" #include "oid-array.h"
#include "sha1-lookup.h" #include "sha1-lookup.h"
void oid_array_append(struct oid_array *array, const struct object_id *oid) void oid_array_append(struct oid_array *array, const struct object_id *oid)
@ -46,9 +46,9 @@ int oid_array_for_each(struct oid_array *array,
for_each_oid_fn fn, for_each_oid_fn fn,
void *data) void *data)
{ {
int i; size_t i;
/* No oid_array_sort() here! See sha1-array.h */ /* No oid_array_sort() here! See oid-array.h */
for (i = 0; i < array->nr; i++) { for (i = 0; i < array->nr; i++) {
int ret = fn(array->oid + i, data); int ret = fn(array->oid + i, data);
@ -62,7 +62,7 @@ int oid_array_for_each_unique(struct oid_array *array,
for_each_oid_fn fn, for_each_oid_fn fn,
void *data) void *data)
{ {
int i; size_t i;
if (!array->sorted) if (!array->sorted)
oid_array_sort(array); oid_array_sort(array);
@ -82,7 +82,7 @@ void oid_array_filter(struct oid_array *array,
for_each_oid_fn want, for_each_oid_fn want,
void *cb_data) void *cb_data)
{ {
unsigned nr = array->nr, src, dst; size_t nr = array->nr, src, dst;
struct object_id *oids = array->oid; struct object_id *oids = array->oid;
for (src = dst = 0; src < nr; src++) { for (src = dst = 0; src < nr; src++) {

View File

@ -19,7 +19,7 @@
* *
* void some_func(void) * void some_func(void)
* { * {
* struct sha1_array hashes = OID_ARRAY_INIT; * struct oid_array hashes = OID_ARRAY_INIT;
* struct object_id oid; * struct object_id oid;
* *
* // Read objects into our set * // Read objects into our set
@ -49,8 +49,8 @@
*/ */
struct oid_array { struct oid_array {
struct object_id *oid; struct object_id *oid;
int nr; size_t nr;
int alloc; size_t alloc;
int sorted; int sorted;
}; };

View File

@ -4,7 +4,7 @@
#include "khash.h" #include "khash.h"
/** /**
* This API is similar to sha1-array, in that it maintains a set of object ids * This API is similar to oid-array, in that it maintains a set of object ids
* in a memory-efficient way. The major differences are: * in a memory-efficient way. The major differences are:
* *
* 1. It uses a hash, so we can do online duplicate removal, rather than * 1. It uses a hash, so we can do online duplicate removal, rather than

View File

@ -5,7 +5,7 @@
#include "color.h" #include "color.h"
#include "string-list.h" #include "string-list.h"
#include "argv-array.h" #include "argv-array.h"
#include "sha1-array.h" #include "oid-array.h"
/*----- some often used options -----*/ /*----- some often used options -----*/

View File

@ -1976,10 +1976,9 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
} }
/* /*
* Given a ref (sha1, refname), check if the ref belongs to the array * Given a ref (oid, refname), check if the ref belongs to the array
* of sha1s. If the given ref is a tag, check if the given tag points * of oids. If the given ref is a tag, check if the given tag points
* at one of the sha1s in the given sha1 array. * at one of the oids in the given oid array.
* the given sha1_array.
* NEEDSWORK: * NEEDSWORK:
* 1. Only a single level of inderection is obtained, we might want to * 1. Only a single level of inderection is obtained, we might want to
* change this to account for multiple levels (e.g. annotated tags * change this to account for multiple levels (e.g. annotated tags

View File

@ -1,7 +1,7 @@
#ifndef REF_FILTER_H #ifndef REF_FILTER_H
#define REF_FILTER_H #define REF_FILTER_H
#include "sha1-array.h" #include "oid-array.h"
#include "refs.h" #include "refs.h"
#include "commit.h" #include "commit.h"
#include "parse-options.h" #include "parse-options.h"

View File

@ -12,7 +12,7 @@
#include "sideband.h" #include "sideband.h"
#include "argv-array.h" #include "argv-array.h"
#include "credential.h" #include "credential.h"
#include "sha1-array.h" #include "oid-array.h"
#include "send-pack.h" #include "send-pack.h"
#include "protocol.h" #include "protocol.h"
#include "quote.h" #include "quote.h"

View File

@ -12,7 +12,7 @@
#include "quote.h" #include "quote.h"
#include "transport.h" #include "transport.h"
#include "version.h" #include "version.h"
#include "sha1-array.h" #include "oid-array.h"
#include "gpg-interface.h" #include "gpg-interface.h"
#include "cache.h" #include "cache.h"

View File

@ -8,7 +8,7 @@
#include "refs.h" #include "refs.h"
#include "remote.h" #include "remote.h"
#include "dir.h" #include "dir.h"
#include "sha1-array.h" #include "oid-array.h"
#include "packfile.h" #include "packfile.h"
#include "object-store.h" #include "object-store.h"
#include "repository.h" #include "repository.h"

View File

@ -8,7 +8,7 @@
#include "pkt-line.h" #include "pkt-line.h"
#include "remote.h" #include "remote.h"
#include "refs.h" #include "refs.h"
#include "sha1-array.h" #include "oid-array.h"
#include "diff.h" #include "diff.h"
#include "revision.h" #include "revision.h"
#include "commit-slab.h" #include "commit-slab.h"

View File

@ -12,7 +12,7 @@
#include "diffcore.h" #include "diffcore.h"
#include "refs.h" #include "refs.h"
#include "string-list.h" #include "string-list.h"
#include "sha1-array.h" #include "oid-array.h"
#include "argv-array.h" #include "argv-array.h"
#include "blob.h" #include "blob.h"
#include "thread-utils.h" #include "thread-utils.h"

View File

@ -1,6 +1,6 @@
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "sha1-array.h" #include "oid-array.h"
static int print_oid(const struct object_id *oid, void *data) static int print_oid(const struct object_id *oid, void *data)
{ {
@ -8,7 +8,7 @@ static int print_oid(const struct object_id *oid, void *data)
return 0; return 0;
} }
int cmd__sha1_array(int argc, const char **argv) int cmd__oid_array(int argc, const char **argv)
{ {
struct oid_array array = OID_ARRAY_INIT; struct oid_array array = OID_ARRAY_INIT;
struct strbuf line = STRBUF_INIT; struct strbuf line = STRBUF_INIT;
@ -19,11 +19,11 @@ int cmd__sha1_array(int argc, const char **argv)
if (skip_prefix(line.buf, "append ", &arg)) { if (skip_prefix(line.buf, "append ", &arg)) {
if (get_oid_hex(arg, &oid)) if (get_oid_hex(arg, &oid))
die("not a hexadecimal SHA1: %s", arg); die("not a hexadecimal oid: %s", arg);
oid_array_append(&array, &oid); oid_array_append(&array, &oid);
} else if (skip_prefix(line.buf, "lookup ", &arg)) { } else if (skip_prefix(line.buf, "lookup ", &arg)) {
if (get_oid_hex(arg, &oid)) if (get_oid_hex(arg, &oid))
die("not a hexadecimal SHA1: %s", arg); die("not a hexadecimal oid: %s", arg);
printf("%d\n", oid_array_lookup(&array, &oid)); printf("%d\n", oid_array_lookup(&array, &oid));
} else if (!strcmp(line.buf, "clear")) } else if (!strcmp(line.buf, "clear"))
oid_array_clear(&array); oid_array_clear(&array);

View File

@ -37,6 +37,7 @@ static struct test_cmd cmds[] = {
{ "match-trees", cmd__match_trees }, { "match-trees", cmd__match_trees },
{ "mergesort", cmd__mergesort }, { "mergesort", cmd__mergesort },
{ "mktemp", cmd__mktemp }, { "mktemp", cmd__mktemp },
{ "oid-array", cmd__oid_array },
{ "oidmap", cmd__oidmap }, { "oidmap", cmd__oidmap },
{ "online-cpus", cmd__online_cpus }, { "online-cpus", cmd__online_cpus },
{ "parse-options", cmd__parse_options }, { "parse-options", cmd__parse_options },
@ -57,7 +58,6 @@ static struct test_cmd cmds[] = {
{ "scrap-cache-tree", cmd__scrap_cache_tree }, { "scrap-cache-tree", cmd__scrap_cache_tree },
{ "serve-v2", cmd__serve_v2 }, { "serve-v2", cmd__serve_v2 },
{ "sha1", cmd__sha1 }, { "sha1", cmd__sha1 },
{ "sha1-array", cmd__sha1_array },
{ "sha256", cmd__sha256 }, { "sha256", cmd__sha256 },
{ "sigchain", cmd__sigchain }, { "sigchain", cmd__sigchain },
{ "strcmp-offset", cmd__strcmp_offset }, { "strcmp-offset", cmd__strcmp_offset },

View File

@ -47,7 +47,7 @@ int cmd__run_command(int argc, const char **argv);
int cmd__scrap_cache_tree(int argc, const char **argv); int cmd__scrap_cache_tree(int argc, const char **argv);
int cmd__serve_v2(int argc, const char **argv); int cmd__serve_v2(int argc, const char **argv);
int cmd__sha1(int argc, const char **argv); int cmd__sha1(int argc, const char **argv);
int cmd__sha1_array(int argc, const char **argv); int cmd__oid_array(int argc, const char **argv);
int cmd__sha256(int argc, const char **argv); int cmd__sha256(int argc, const char **argv);
int cmd__sigchain(int argc, const char **argv); int cmd__sigchain(int argc, const char **argv);
int cmd__strcmp_offset(int argc, const char **argv); int cmd__strcmp_offset(int argc, const char **argv);

View File

@ -18,7 +18,7 @@ test_expect_success 'ordered enumeration' '
{ {
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echo for_each_unique echo for_each_unique
} | test-tool sha1-array >actual && } | test-tool oid-array >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -28,7 +28,7 @@ test_expect_success 'ordered enumeration with duplicate suppression' '
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echo for_each_unique echo for_each_unique
} | test-tool sha1-array >actual && } | test-tool oid-array >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -36,7 +36,7 @@ test_expect_success 'lookup' '
{ {
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echoid lookup 55 echoid lookup 55
} | test-tool sha1-array >actual && } | test-tool oid-array >actual &&
n=$(cat actual) && n=$(cat actual) &&
test "$n" -eq 1 test "$n" -eq 1
' '
@ -45,7 +45,7 @@ test_expect_success 'lookup non-existing entry' '
{ {
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echoid lookup 33 echoid lookup 33
} | test-tool sha1-array >actual && } | test-tool oid-array >actual &&
n=$(cat actual) && n=$(cat actual) &&
test "$n" -lt 0 test "$n" -lt 0
' '
@ -55,7 +55,7 @@ test_expect_success 'lookup with duplicates' '
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echoid lookup 55 echoid lookup 55
} | test-tool sha1-array >actual && } | test-tool oid-array >actual &&
n=$(cat actual) && n=$(cat actual) &&
test "$n" -ge 2 && test "$n" -ge 2 &&
test "$n" -le 3 test "$n" -le 3
@ -66,7 +66,7 @@ test_expect_success 'lookup non-existing entry with duplicates' '
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echoid append 88 44 aa 55 && echoid append 88 44 aa 55 &&
echoid lookup 66 echoid lookup 66
} | test-tool sha1-array >actual && } | test-tool oid-array >actual &&
n=$(cat actual) && n=$(cat actual) &&
test "$n" -lt 0 test "$n" -lt 0
' '
@ -81,7 +81,7 @@ test_expect_success 'lookup with almost duplicate values' '
echo "append $id1" && echo "append $id1" &&
echo "append $id2" && echo "append $id2" &&
echoid lookup 55 echoid lookup 55
} | test-tool sha1-array >actual && } | test-tool oid-array >actual &&
n=$(cat actual) && n=$(cat actual) &&
test "$n" -eq 0 test "$n" -eq 0
' '
@ -90,7 +90,7 @@ test_expect_success 'lookup with single duplicate value' '
{ {
echoid append 55 55 && echoid append 55 55 &&
echoid lookup 55 echoid lookup 55
} | test-tool sha1-array >actual && } | test-tool oid-array >actual &&
n=$(cat actual) && n=$(cat actual) &&
test "$n" -ge 0 && test "$n" -ge 0 &&
test "$n" -le 1 test "$n" -le 1

View File

@ -16,7 +16,7 @@
#include "url.h" #include "url.h"
#include "submodule.h" #include "submodule.h"
#include "string-list.h" #include "string-list.h"
#include "sha1-array.h" #include "oid-array.h"
#include "sigchain.h" #include "sigchain.h"
#include "transport-internal.h" #include "transport-internal.h"
#include "protocol.h" #include "protocol.h"