mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
grep: simplify grep_oid and grep_file
In the NO_PTHREADS or !num_threads case, this doesn't change anything. In the threaded case, note that grep_source_init duplicates its third argument, so there is no need to keep [path]buf.buf alive across the call of add_work(). Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e2e05d619a
commit
38ef24dccf
|
@ -326,6 +326,7 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
|
||||||
}
|
}
|
||||||
|
|
||||||
grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
|
grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
|
||||||
|
strbuf_release(&pathbuf);
|
||||||
|
|
||||||
#ifndef NO_PTHREADS
|
#ifndef NO_PTHREADS
|
||||||
if (num_threads) {
|
if (num_threads) {
|
||||||
|
@ -334,14 +335,12 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
|
||||||
* its fields, so do not call grep_source_clear()
|
* its fields, so do not call grep_source_clear()
|
||||||
*/
|
*/
|
||||||
add_work(opt, &gs);
|
add_work(opt, &gs);
|
||||||
strbuf_release(&pathbuf);
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int hit;
|
int hit;
|
||||||
|
|
||||||
strbuf_release(&pathbuf);
|
|
||||||
hit = grep_source(opt, &gs);
|
hit = grep_source(opt, &gs);
|
||||||
|
|
||||||
grep_source_clear(&gs);
|
grep_source_clear(&gs);
|
||||||
|
@ -360,6 +359,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
|
||||||
strbuf_addstr(&buf, filename);
|
strbuf_addstr(&buf, filename);
|
||||||
|
|
||||||
grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename);
|
grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename);
|
||||||
|
strbuf_release(&buf);
|
||||||
|
|
||||||
#ifndef NO_PTHREADS
|
#ifndef NO_PTHREADS
|
||||||
if (num_threads) {
|
if (num_threads) {
|
||||||
|
@ -368,14 +368,12 @@ static int grep_file(struct grep_opt *opt, const char *filename)
|
||||||
* its fields, so do not call grep_source_clear()
|
* its fields, so do not call grep_source_clear()
|
||||||
*/
|
*/
|
||||||
add_work(opt, &gs);
|
add_work(opt, &gs);
|
||||||
strbuf_release(&buf);
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int hit;
|
int hit;
|
||||||
|
|
||||||
strbuf_release(&buf);
|
|
||||||
hit = grep_source(opt, &gs);
|
hit = grep_source(opt, &gs);
|
||||||
|
|
||||||
grep_source_clear(&gs);
|
grep_source_clear(&gs);
|
||||||
|
|
Loading…
Reference in a new issue