static int grep_file(struct grep_opt *opt, const char *filename) { struct strbuf buf = STRBUF_INIT; if (opt->relative && opt->prefix_length) quote_path_relative(filename, -1, &buf, opt->prefix); else strbuf_addstr(&buf, filename); #ifndef NO_PTHREADS if (use_threads) { add_work(opt, GREP_SOURCE_FILE, buf.buf, filename, filename); strbuf_release(&buf); return 0; } else #endif { struct grep_source gs; int hit; grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename); strbuf_release(&buf); hit = grep_source(opt, &gs); grep_source_clear(&gs); return hit; } }
static int grep_oid(struct grep_opt *opt, const struct object_id *oid, const char *filename, int tree_name_len, const char *path) { struct strbuf pathbuf = STRBUF_INIT; if (opt->relative && opt->prefix_length) { quote_path_relative(filename + tree_name_len, opt->prefix, &pathbuf); strbuf_insert(&pathbuf, 0, filename, tree_name_len); } else { strbuf_addstr(&pathbuf, filename); } #ifndef NO_PTHREADS if (num_threads) { add_work(opt, GREP_SOURCE_OID, pathbuf.buf, path, oid); strbuf_release(&pathbuf); return 0; } else #endif { struct grep_source gs; int hit; grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid); strbuf_release(&pathbuf); hit = grep_source(opt, &gs); grep_source_clear(&gs); return hit; } }
static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1, const char *filename, int tree_name_len, const char *path) { struct strbuf pathbuf = STRBUF_INIT; if (opt->relative && opt->prefix_length) { quote_path_relative(filename + tree_name_len, -1, &pathbuf, opt->prefix); strbuf_insert(&pathbuf, 0, filename, tree_name_len); } else { strbuf_addstr(&pathbuf, filename); } #ifndef NO_PTHREADS if (use_threads) { add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1); strbuf_release(&pathbuf); return 0; } else #endif { struct grep_source gs; int hit; grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1); strbuf_release(&pathbuf); hit = grep_source(opt, &gs); grep_source_clear(&gs); return hit; } }
static int grep_file(struct grep_opt *opt, const char *filename) { struct strbuf buf = STRBUF_INIT; struct grep_source gs; if (opt->relative && opt->prefix_length) quote_path_relative(filename, opt->prefix, &buf); else strbuf_addstr(&buf, filename); grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename); strbuf_release(&buf); #ifndef NO_PTHREADS if (num_threads) { /* * add_work() copies gs and thus assumes ownership of * its fields, so do not call grep_source_clear() */ add_work(opt, &gs); return 0; } else #endif { int hit; hit = grep_source(opt, &gs); grep_source_clear(&gs); return hit; } }
int grep_buffer(struct grep_opt *opt, char *buf, unsigned long size) { struct grep_source gs; int r; grep_source_init(&gs, GREP_SOURCE_BUF, NULL, NULL, NULL); gs.buf = buf; gs.size = size; r = grep_source(opt, &gs); grep_source_clear(&gs); return r; }
static void *run(void *arg) { int hit = 0; struct grep_opt *opt = arg; while (1) { struct work_item *w = get_work(); if (!w) break; opt->output_priv = w; hit |= grep_source(opt, &w->source); grep_source_clear_data(&w->source); work_done(w); } free_grep_patterns(arg); free(arg); return (void*) (intptr_t) hit; }
static void *run(void *arg) { int hit = 0; struct grep_opt *opt = arg; while (1) { struct work_item *w = get_work(); if (!w) break; opt->output_priv = w; if (w->source.type == GREP_SOURCE_SUBMODULE) hit |= grep_submodule_launch(opt, &w->source); else hit |= grep_source(opt, &w->source); grep_source_clear_data(&w->source); work_done(w); } free_grep_patterns(arg); free(arg); return (void*) (intptr_t) hit; }
static int grep_oid(struct grep_opt *opt, const struct object_id *oid, const char *filename, int tree_name_len, const char *path) { struct strbuf pathbuf = STRBUF_INIT; struct grep_source gs; if (opt->relative && opt->prefix_length) { quote_path_relative(filename + tree_name_len, opt->prefix, &pathbuf); strbuf_insert(&pathbuf, 0, filename, tree_name_len); } else { strbuf_addstr(&pathbuf, filename); } grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid); strbuf_release(&pathbuf); #ifndef NO_PTHREADS if (num_threads) { /* * add_work() copies gs and thus assumes ownership of * its fields, so do not call grep_source_clear() */ add_work(opt, &gs); return 0; } else #endif { int hit; hit = grep_source(opt, &gs); grep_source_clear(&gs); return hit; } }