From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: sxenos@google.com
Cc: git@vger.kernel.org, Stefan Xenos <sxenos@gmail.com>
Subject: Re: [PATCH v2 2/8] sha1-array: Implement oid_array_readonly_contains
Date: Mon, 28 Jan 2019 14:05:13 +0100 [thread overview]
Message-ID: <20190128130513.GA12887@szeder.dev> (raw)
In-Reply-To: <20190127194128.161250-2-sxenos@google.com>
On Sun, Jan 27, 2019 at 11:41:22AM -0800, sxenos@google.com wrote:
> From: Stefan Xenos <sxenos@gmail.com>
>
> Implement a "readonly_contains" function for oid_array that won't
> sort the array if it is unsorted. This can be used to test containment in
> the rare situations where the array order matters.
>
> The function has intentionally been given a name that is more cumbersome
> than the "lookup" function, which is what most callers will will want
> in most situations.
>
> Signed-off-by: Stefan Xenos <sxenos@google.com>
> ---
> sha1-array.c | 15 +++++++++++++++
> sha1-array.h | 2 ++
> t/helper/test-sha1-array.c | 6 ++++++
> t/t0064-sha1-array.sh | 22 ++++++++++++++++++++++
> 4 files changed, 45 insertions(+)
>
> diff --git a/sha1-array.c b/sha1-array.c
> index b94e0ec0f5..071fce7e90 100644
> --- a/sha1-array.c
> +++ b/sha1-array.c
> @@ -26,6 +26,21 @@ static const unsigned char *sha1_access(size_t index, void *table)
> return array[index].hash;
> }
>
> +int oid_array_readonly_contains(const struct oid_array* array,
> + const struct object_id* oid)
> +{
> + int i;
> + if (array->sorted) {
> + return sha1_pos(oid->hash, array->oid, array->nr, sha1_access) >= 0;
> + }
Style nit: unnecessary braces. According to CodingGuidelines we tend
not to use braces when the body of a loop or if statement is only a
single line.
> + for (i = 0; i < array->nr; i++) {
> + if (hashcmp(array->oid[i].hash, oid->hash) == 0) {
Please use oideq() instead.
> + return 1;
> + }
> + }
> + return 0;
> +}
> +
> int oid_array_lookup(struct oid_array *array, const struct object_id *oid)
> {
> if (!array->sorted)
> diff --git a/t/t0064-sha1-array.sh b/t/t0064-sha1-array.sh
> index 5dda570b9a..c1bac6fcdd 100755
> --- a/t/t0064-sha1-array.sh
> +++ b/t/t0064-sha1-array.sh
> @@ -32,6 +32,28 @@ test_expect_success 'ordered enumeration with duplicate suppression' '
> test_cmp expect actual
> '
>
> +test_expect_success 'readonly_contains finds existing' '
> + echo 1 > expect &&
> + echoid "" 88 44 aa 55 >> expect &&
Style nit: not space between redirection operator and filename.
> + {
> + echoid append 88 44 aa 55 &&
> + echoid readonly_contains 55 &&
> + echo for_each
> + } | test-tool sha1-array >actual &&
> + test_cmp expect actual
> +'
> +
> +test_expect_success 'readonly_contains non-existing query' '
> + echo 0 > expect &&
> + echoid "" 88 44 aa 55 >> expect &&
> + {
> + echoid append 88 44 aa 55 &&
> + echoid readonly_contains 33 &&
> + echo for_each
> + } | test-tool sha1-array >actual &&
> + test_cmp expect actual
> +'
> +
> test_expect_success 'lookup' '
> {
> echoid append 88 44 aa 55 &&
> --
> 2.20.1.495.gaa96b0ce6b-goog
>
next prev parent reply other threads:[~2019-01-28 13:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-27 19:41 [PATCH v2 1/8] technical doc: add a design doc for the evolve command sxenos
2019-01-27 19:41 ` [PATCH v2 2/8] sha1-array: Implement oid_array_readonly_contains sxenos
2019-01-28 13:05 ` SZEDER Gábor [this message]
[not found] ` <CABh8og41XhiYzg=X3to7M+zWszJq6a+n8bwHrwkU-GoxYa8-VQ@mail.gmail.com>
2019-01-29 11:15 ` SZEDER Gábor
2019-01-27 19:41 ` [PATCH v2 3/8] ref-filter: Add the metas namespace to ref-filter sxenos
2019-01-27 19:41 ` [PATCH v2 4/8] evolve: Add support for parsing metacommits sxenos
2019-01-27 19:41 ` [PATCH v2 5/8] evolve: Add the change-table structure sxenos
2019-01-27 19:41 ` [PATCH v2 6/8] evolve: Add support for writing metacommits sxenos
2019-01-29 11:15 ` SZEDER Gábor
2019-01-27 19:41 ` [PATCH v2 7/8] evolve: Implement the git change command sxenos
2019-01-27 19:41 ` [PATCH v2 8/8] evolve: Add the git change list command sxenos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190128130513.GA12887@szeder.dev \
--to=szeder.dev@gmail.com \
--cc=git@vger.kernel.org \
--cc=sxenos@gmail.com \
--cc=sxenos@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).