notes-cache.c: remove the_repository references

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Nov 10, 2018 at 06:49 UTC bd7ad45b64bf8b5a5256bd1eeb3907f8516244a8
9 files changed +28 -21
combine-diff.c
+1 -1
@@ -991,7 +991,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
991 if (!userdiff)
992 userdiff = userdiff_find_by_name("default");
993 if (opt->flags.allow_textconv)
994 - textconv = userdiff_get_textconv(userdiff);
994 + textconv = userdiff_get_textconv(opt->repo, userdiff);
995
996 /* Read the result of merge first */
997 if (!working_tree_file)
diff.c
+6 -6
@@ -3312,14 +3312,14 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const
3312 options->b_prefix = b;
3313 }
3314
3315 -struct userdiff_driver *get_textconv(struct index_state *istate,
3315 +struct userdiff_driver *get_textconv(struct repository *r,
3316 struct diff_filespec *one)
3317 {
3318 if (!DIFF_FILE_VALID(one))
3319 return NULL;
3320
3321 - diff_filespec_load_driver(one, istate);
3322 - return userdiff_get_textconv(one->driver);
3321 + diff_filespec_load_driver(one, r->index);
3322 + return userdiff_get_textconv(r, one->driver);
3323 }
3324
3325 static void builtin_diff(const char *name_a,
@@ -3368,8 +3368,8 @@ static void builtin_diff(const char *name_a,
3368 }
3369
3370 if (o->flags.allow_textconv) {
3371 - textconv_one = get_textconv(o->repo->index, one);
3372 - textconv_two = get_textconv(o->repo->index, two);
3371 + textconv_one = get_textconv(o->repo, one);
3372 + textconv_two = get_textconv(o->repo, two);
3373 }
3374
3375 /* Never use a non-valid filename anywhere if at all possible */
@@ -6436,7 +6436,7 @@ int textconv_object(struct repository *r,
6436
6437 df = alloc_filespec(path);
6438 fill_filespec(df, oid, oid_valid, mode);
6439 - textconv = get_textconv(r->index, df);
6439 + textconv = get_textconv(r, df);
6440 if (!textconv) {
6441 free_filespec(df);
6442 return 0;
diff.h
+1 -1
@@ -461,7 +461,7 @@ size_t fill_textconv(struct repository *r,
461 * and only if it has textconv enabled (otherwise return NULL). The result
462 * can be passed to fill_textconv().
463 */
464 -struct userdiff_driver *get_textconv(struct index_state *istate,
464 +struct userdiff_driver *get_textconv(struct repository *r,
465 struct diff_filespec *one);
466
467 /*
diffcore-pickaxe.c
+2 -2
@@ -139,8 +139,8 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
139 return 0;
140
141 if (o->flags.allow_textconv) {
142 - textconv_one = get_textconv(o->repo->index, p->one);
143 - textconv_two = get_textconv(o->repo->index, p->two);
142 + textconv_one = get_textconv(o->repo, p->one);
143 + textconv_two = get_textconv(o->repo, p->two);
144 }
145
146 /*
grep.c
+1 -1
@@ -1811,7 +1811,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
1811 * is not thread-safe.
1812 */
1813 grep_attr_lock();
1814 - textconv = userdiff_get_textconv(gs->driver);
1814 + textconv = userdiff_get_textconv(opt->repo, gs->driver);
1815 grep_attr_unlock();
1816 }
1817
notes-cache.c
+7 -5
@@ -5,7 +5,9 @@
5 #include "commit.h"
6 #include "refs.h"
7
8 -static int notes_cache_match_validity(const char *ref, const char *validity)
8 +static int notes_cache_match_validity(struct repository *r,
9 + const char *ref,
10 + const char *validity)
11 {
12 struct object_id oid;
13 struct commit *commit;
@@ -16,7 +18,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
18 if (read_ref(ref, &oid) < 0)
19 return 0;
20
19 - commit = lookup_commit_reference_gently(the_repository, &oid, 1);
21 + commit = lookup_commit_reference_gently(r, &oid, 1);
22 if (!commit)
23 return 0;
24
@@ -30,8 +32,8 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
32 return ret;
33 }
34
33 -void notes_cache_init(struct notes_cache *c, const char *name,
34 - const char *validity)
35 +void notes_cache_init(struct repository *r, struct notes_cache *c,
36 + const char *name, const char *validity)
37 {
38 struct strbuf ref = STRBUF_INIT;
39 int flags = NOTES_INIT_WRITABLE;
@@ -40,7 +42,7 @@ void notes_cache_init(struct notes_cache *c, const char *name,
42 c->validity = xstrdup(validity);
43
44 strbuf_addf(&ref, "refs/notes/%s", name);
43 - if (!notes_cache_match_validity(ref.buf, validity))
45 + if (!notes_cache_match_validity(r, ref.buf, validity))
46 flags |= NOTES_INIT_EMPTY;
47 init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
48 strbuf_release(&ref);
notes-cache.h
+4 -2
@@ -3,13 +3,15 @@
3
4 #include "notes.h"
5
6 +struct repository;
7 +
8 struct notes_cache {
9 struct notes_tree tree;
10 char *validity;
11 };
12
11 -void notes_cache_init(struct notes_cache *c, const char *name,
12 - const char *validity);
13 +void notes_cache_init(struct repository *r, struct notes_cache *c,
14 + const char *name, const char *validity);
15 int notes_cache_write(struct notes_cache *c);
16
17 char *notes_cache_get(struct notes_cache *c, struct object_id *oid, size_t
userdiff.c
+3 -2
@@ -290,7 +290,8 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
290 return userdiff_find_by_name(check->items[0].value);
291 }
292
293 -struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
293 +struct userdiff_driver *userdiff_get_textconv(struct repository *r,
294 + struct userdiff_driver *driver)
295 {
296 if (!driver->textconv)
297 return NULL;
@@ -300,7 +301,7 @@ struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
301 struct strbuf name = STRBUF_INIT;
302
303 strbuf_addf(&name, "textconv/%s", driver->name);
303 - notes_cache_init(c, name.buf, driver->textconv);
304 + notes_cache_init(r, c, name.buf, driver->textconv);
305 driver->textconv_cache = c;
306 strbuf_release(&name);
307 }
userdiff.h
+3 -1
@@ -4,6 +4,7 @@
4 #include "notes-cache.h"
5
6 struct index_state;
7 +struct repository;
8
9 struct userdiff_funcname {
10 const char *pattern;
@@ -30,6 +31,7 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
31 * Initialize any textconv-related fields in the driver and return it, or NULL
32 * if it does not have textconv enabled at all.
33 */
33 -struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver);
34 +struct userdiff_driver *userdiff_get_textconv(struct repository *r,
35 + struct userdiff_driver *driver);
36
37 #endif /* USERDIFF */