Re: [PATCH 08/33] grep: convert to struct object_id
From: Junio C Hamano <hidden>
Date: 2017-06-02 01:00:46
Brandon Williams [off-list ref] writes:
quoted hunk
Convert the remaining parts of grep to use struct object_id. Signed-off-by: Brandon Williams <redacted> --- 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.