Re: [PATCH 01/10] get_sha1: detect buggy calls with multiple disambiguators
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 26, 2016, 17:50 UTC
- Message-ID
- <xmqq7f9yturq.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20160926172111.sve6tsse2figcved@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 7 quoted lines
>> Other than your reinvention of HAS_MULTI_BITS(), which has been with
>> us since db7244bd ("parse-options new features.", 2007-11-07), this
>> looks like a reasonable thing to do.
>
> Heh, I _thought_ we had something like that but couldn't find it. I
> grepped for "[^&]& .*-", which does match it, but stupidly did it only
> in '*.c'. Definitely it should use the existing macro instead.OK, I'll queue this on top to be squashed, so no need to resend only for this one.
sha1_name.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c index f9812ff..0ff83a9 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -310,11 +310,6 @@ static int prepare_prefixes(const char *name, int len, return 0; } -static int multiple_bits_set(unsigned flags) -{ - return !!(flags & (flags - 1)); -} - static int get_short_sha1(const char *name, int len, unsigned char *sha1, unsigned flags) { @@ -333,7 +328,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1, memset(&ds, 0, sizeof(ds)); - if (multiple_bits_set(flags & GET_SHA1_DISAMBIGUATORS)) + if (HAS_MULTI_BITS(flags & GET_SHA1_DISAMBIGUATORS)) die("BUG: multiple get_short_sha1 disambiguator flags"); if (flags & GET_SHA1_COMMIT)