grep: convert to struct object_id

Convert the remaining parts of grep to use struct object_id.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brandon Williams
2017-05-30 10:30:44 -07:00
committed by Junio C Hamano
parent 5ee8a954e0
commit 1c41c82bc4
4 changed files with 27 additions and 21 deletions

17
grep.c
View File

@ -1403,7 +1403,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver,
*/
df = alloc_filespec(gs->path);
switch (gs->type) {
case GREP_SOURCE_SHA1:
case GREP_SOURCE_OID:
fill_filespec(df, gs->identifier, 1, 0100644);
break;
case GREP_SOURCE_FILE:
@ -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;
@ -1772,7 +1771,7 @@ void grep_source_clear_data(struct grep_source *gs)
{
switch (gs->type) {
case GREP_SOURCE_FILE:
case GREP_SOURCE_SHA1:
case GREP_SOURCE_OID:
case GREP_SOURCE_SUBMODULE:
free(gs->buf);
gs->buf = NULL;
@ -1784,7 +1783,7 @@ void grep_source_clear_data(struct grep_source *gs)
}
}
static int grep_source_load_sha1(struct grep_source *gs)
static int grep_source_load_oid(struct grep_source *gs)
{
enum object_type type;
@ -1795,7 +1794,7 @@ static int grep_source_load_sha1(struct grep_source *gs)
if (!gs->buf)
return error(_("'%s': unable to read %s"),
gs->name,
sha1_to_hex(gs->identifier));
oid_to_hex(gs->identifier));
return 0;
}
@ -1841,8 +1840,8 @@ static int grep_source_load(struct grep_source *gs)
switch (gs->type) {
case GREP_SOURCE_FILE:
return grep_source_load_file(gs);
case GREP_SOURCE_SHA1:
return grep_source_load_sha1(gs);
case GREP_SOURCE_OID:
return grep_source_load_oid(gs);
case GREP_SOURCE_BUF:
return gs->buf ? 0 : -1;
case GREP_SOURCE_SUBMODULE: