Skip to content

Commit 3813e69

Browse files
peffgitster
authored andcommitted
refactor get_textconv to not require diff_filespec
This function actually does two things: 1. Load the userdiff driver for the filespec. 2. Decide whether the driver has a textconv component, and initialize the textconv cache if applicable. Only part (1) requires the filespec object, and some callers may not have a filespec at all. So let's split them it into two functions, and put part (2) with the userdiff code, which is a better fit. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4d5f347 commit 3813e69

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

diff.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,19 +1976,7 @@ struct userdiff_driver *get_textconv(struct diff_filespec *one)
19761976
return NULL;
19771977

19781978
diff_filespec_load_driver(one);
1979-
if (!one->driver->textconv)
1980-
return NULL;
1981-
1982-
if (one->driver->textconv_want_cache && !one->driver->textconv_cache) {
1983-
struct notes_cache *c = xmalloc(sizeof(*c));
1984-
struct strbuf name = STRBUF_INIT;
1985-
1986-
strbuf_addf(&name, "textconv/%s", one->driver->name);
1987-
notes_cache_init(c, name.buf, one->driver->textconv);
1988-
one->driver->textconv_cache = c;
1989-
}
1990-
1991-
return one->driver;
1979+
return userdiff_get_textconv(one->driver);
19921980
}
19931981

19941982
static void builtin_diff(const char *name_a,

userdiff.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,20 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
267267
return NULL;
268268
return userdiff_find_by_name(check.value);
269269
}
270+
271+
struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
272+
{
273+
if (!driver->textconv)
274+
return NULL;
275+
276+
if (driver->textconv_want_cache && !driver->textconv_cache) {
277+
struct notes_cache *c = xmalloc(sizeof(*c));
278+
struct strbuf name = STRBUF_INIT;
279+
280+
strbuf_addf(&name, "textconv/%s", driver->name);
281+
notes_cache_init(c, name.buf, driver->textconv);
282+
driver->textconv_cache = c;
283+
}
284+
285+
return driver;
286+
}

userdiff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ int userdiff_config(const char *k, const char *v);
2323
struct userdiff_driver *userdiff_find_by_name(const char *name);
2424
struct userdiff_driver *userdiff_find_by_path(const char *path);
2525

26+
struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver);
27+
2628
#endif /* USERDIFF */

0 commit comments

Comments
 (0)