grep: add submodules as a grep source type
Add `GREP_SOURCE_SUBMODULE` as a grep_source type and cases for this new type in the various switch statements in grep.c. When initializing a grep_source with type `GREP_SOURCE_SUBMODULE` the identifier can either be NULL (to indicate that the working tree will be used) or a SHA1 (the REV of the submodule to be grep'd). If the identifier is a SHA1 then we want to fall through to the `GREP_SOURCE_SHA1` case to handle the copying of the SHA1. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9ebf689aad
commit
4538eef564
16
grep.c
16
grep.c
@ -1735,12 +1735,23 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
|
|||||||
case GREP_SOURCE_FILE:
|
case GREP_SOURCE_FILE:
|
||||||
gs->identifier = xstrdup(identifier);
|
gs->identifier = xstrdup(identifier);
|
||||||
break;
|
break;
|
||||||
|
case GREP_SOURCE_SUBMODULE:
|
||||||
|
if (!identifier) {
|
||||||
|
gs->identifier = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* FALL THROUGH
|
||||||
|
* If the identifier is non-NULL (in the submodule case) it
|
||||||
|
* will be a SHA1 that needs to be copied.
|
||||||
|
*/
|
||||||
case GREP_SOURCE_SHA1:
|
case GREP_SOURCE_SHA1:
|
||||||
gs->identifier = xmalloc(20);
|
gs->identifier = xmalloc(20);
|
||||||
hashcpy(gs->identifier, identifier);
|
hashcpy(gs->identifier, identifier);
|
||||||
break;
|
break;
|
||||||
case GREP_SOURCE_BUF:
|
case GREP_SOURCE_BUF:
|
||||||
gs->identifier = NULL;
|
gs->identifier = NULL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1760,6 +1771,7 @@ void grep_source_clear_data(struct grep_source *gs)
|
|||||||
switch (gs->type) {
|
switch (gs->type) {
|
||||||
case GREP_SOURCE_FILE:
|
case GREP_SOURCE_FILE:
|
||||||
case GREP_SOURCE_SHA1:
|
case GREP_SOURCE_SHA1:
|
||||||
|
case GREP_SOURCE_SUBMODULE:
|
||||||
free(gs->buf);
|
free(gs->buf);
|
||||||
gs->buf = NULL;
|
gs->buf = NULL;
|
||||||
gs->size = 0;
|
gs->size = 0;
|
||||||
@ -1831,8 +1843,10 @@ static int grep_source_load(struct grep_source *gs)
|
|||||||
return grep_source_load_sha1(gs);
|
return grep_source_load_sha1(gs);
|
||||||
case GREP_SOURCE_BUF:
|
case GREP_SOURCE_BUF:
|
||||||
return gs->buf ? 0 : -1;
|
return gs->buf ? 0 : -1;
|
||||||
|
case GREP_SOURCE_SUBMODULE:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
die("BUG: invalid grep_source type");
|
die("BUG: invalid grep_source type to load");
|
||||||
}
|
}
|
||||||
|
|
||||||
void grep_source_load_driver(struct grep_source *gs)
|
void grep_source_load_driver(struct grep_source *gs)
|
||||||
|
Loading…
Reference in New Issue
Block a user