Re: [PATCH 08/33] grep: convert to struct object_id
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 2, 2017, 01:00 UTC
- Message-ID
- <xmqqlgpb2og9.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20170530173109.54904-9-bmwill@google.com>
Brandon Williams <bmwill@google.com> writes:
Show 36 quoted lines
> Convert the remaining parts of grep to use struct object_id.
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
> builtin/grep.c | 22 +++++++++++-----------
> cache.h | 7 +++++++
> grep.c | 17 ++++++++---------
> grep.h | 2 +-
> 4 files changed, 27 insertions(+), 21 deletions(-)
> ...
> +static inline struct object_id *oiddup(const struct object_id *src)
> +{
> + struct object_id *dst = xmalloc(sizeof(struct object_id));
> + oidcpy(dst, src);
> + return dst;
> +}
> +
> static inline void hashclr(unsigned char *hash)
> {
> memset(hash, 0, GIT_SHA1_RAWSZ);
> diff --git a/grep.c b/grep.c
> index 47cee4506..a240b4cdb 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -1747,9 +1747,8 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
> * If the identifier is non-NULL (in the submodule case) it
> * will be a SHA1 that needs to be copied.
> */
> - case GREP_SOURCE_SHA1:
> - gs->identifier = xmalloc(20);
> - hashcpy(gs->identifier, identifier);
> + case GREP_SOURCE_OID:
> + gs->identifier = oiddup(identifier);
> break;
> case GREP_SOURCE_BUF:
> gs->identifier = NULL;These hunks triggered my "Huh?" meter a bit, simply because I tend to wonder not just "is this useful in many other places?" but also "is it a good idea to encourage the use of this thing?"; these look OK.
Thanks.