Skip to content

Commit 0693806

Browse files
jonathantanmygitster
authored andcommitted
grep: add repository to OID grep sources
Record the repository whenever an OID grep source is created, and teach the worker threads to explicitly provide the repository when accessing objects. Signed-off-by: Jonathan Tan <[email protected]> Reviewed-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd45471 commit 0693806

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

builtin/grep.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
349349
struct grep_source gs;
350350

351351
grep_source_name(opt, filename, tree_name_len, &pathbuf);
352-
grep_source_init_oid(&gs, pathbuf.buf, path, oid);
352+
grep_source_init_oid(&gs, pathbuf.buf, path, oid, opt->repo);
353353
strbuf_release(&pathbuf);
354354

355355
if (num_threads > 1) {
@@ -462,14 +462,11 @@ static int grep_submodule(struct grep_opt *opt,
462462
repo_read_gitmodules(subrepo, 0);
463463

464464
/*
465-
* NEEDSWORK: This adds the submodule's object directory to the list of
466-
* alternates for the single in-memory object store. This has some bad
467-
* consequences for memory (processed objects will never be freed) and
468-
* performance (this increases the number of pack files git has to pay
469-
* attention to, to the sum of the number of pack files in all the
470-
* repositories processed so far). This can be removed once the object
471-
* store is no longer global and instead is a member of the repository
472-
* object.
465+
* All code paths tested by test code no longer need submodule ODBs to
466+
* be added as alternates, but add it to the list just in case.
467+
* Submodule ODBs added through add_submodule_odb_by_path() will be
468+
* lazily registered as alternates when needed (and except in an
469+
* unexpected code interaction, it won't be needed).
473470
*/
474471
add_submodule_odb_by_path(subrepo->objects->odb->path);
475472
obj_read_unlock();

grep.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,8 @@ void grep_source_init_file(struct grep_source *gs, const char *name,
18631863
}
18641864

18651865
void grep_source_init_oid(struct grep_source *gs, const char *name,
1866-
const char *path, const struct object_id *oid)
1866+
const char *path, const struct object_id *oid,
1867+
struct repository *repo)
18671868
{
18681869
gs->type = GREP_SOURCE_OID;
18691870
gs->name = xstrdup_or_null(name);
@@ -1872,6 +1873,7 @@ void grep_source_init_oid(struct grep_source *gs, const char *name,
18721873
gs->size = 0;
18731874
gs->driver = NULL;
18741875
gs->identifier = oiddup(oid);
1876+
gs->repo = repo;
18751877
}
18761878

18771879
void grep_source_clear(struct grep_source *gs)
@@ -1900,7 +1902,8 @@ static int grep_source_load_oid(struct grep_source *gs)
19001902
{
19011903
enum object_type type;
19021904

1903-
gs->buf = read_object_file(gs->identifier, &type, &gs->size);
1905+
gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
1906+
&gs->size);
19041907
if (!gs->buf)
19051908
return error(_("'%s': unable to read %s"),
19061909
gs->name,

grep.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,20 @@ struct grep_opt {
120120
struct grep_pat *header_list;
121121
struct grep_pat **header_tail;
122122
struct grep_expr *pattern_expression;
123+
124+
/*
125+
* NEEDSWORK: See if we can remove this field, because the repository
126+
* should probably be per-source. That is, grep.c functions using this
127+
* field should probably start using "repo" in "struct grep_source"
128+
* instead.
129+
*
130+
* This is potentially the cause of at least one bug - "git grep"
131+
* ignoring the textconv attributes from submodules. See [1] for more
132+
* information.
133+
* [1] https://lore.kernel.org/git/CAHd-oW5iEQarYVxEXoTG-ua2zdoybTrSjCBKtO0YT292fm0NQQ@mail.gmail.com/
134+
*/
123135
struct repository *repo;
136+
124137
const char *prefix;
125138
int prefix_length;
126139
regex_t regexp;
@@ -187,6 +200,7 @@ struct grep_source {
187200
GREP_SOURCE_BUF,
188201
} type;
189202
void *identifier;
203+
struct repository *repo; /* if GREP_SOURCE_OID */
190204

191205
char *buf;
192206
unsigned long size;
@@ -198,7 +212,8 @@ struct grep_source {
198212
void grep_source_init_file(struct grep_source *gs, const char *name,
199213
const char *path);
200214
void grep_source_init_oid(struct grep_source *gs, const char *name,
201-
const char *path, const struct object_id *oid);
215+
const char *path, const struct object_id *oid,
216+
struct repository *repo);
202217
void grep_source_clear_data(struct grep_source *gs);
203218
void grep_source_clear(struct grep_source *gs);
204219
void grep_source_load_driver(struct grep_source *gs,

0 commit comments

Comments
 (0)