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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 23, 2011 at 16:30 UTC
3813e69031d2df2702f50b9649fa2e40ea11e558
3 files changed
+20
-13
diff.c
+1
-13
@@ -1976,19 +1976,7 @@ struct userdiff_driver *get_textconv(struct diff_filespec *one)
1976
return NULL;
1977
1978
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);
1980
}
1981
1982
static void builtin_diff(const char *name_a,
userdiff.c
+17
@@ -267,3 +267,20 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
267
return NULL;
268
return userdiff_find_by_name(check.value);
269
}
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
+2
@@ -23,4 +23,6 @@ int userdiff_config(const char *k, const char *v);
23
struct userdiff_driver *userdiff_find_by_name(const char *name);
24
struct userdiff_driver *userdiff_find_by_path(const char *path);
25
26
+struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver);
27
+
28
#endif /* USERDIFF */