blame: move textconv_object with related functions

textconv_object is used in places other than blame.c and should be moved to a more appropriate location. Other textconv related functions are located in diff.c so that seems as good a place as any. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Smith committed May 24, 2017 at 00:15 UTC 3a35cb2ea8ab5d44d6ea6290b7af8a7c8623e4c2
5 files changed +31 -30
builtin.h
-2
@@ -25,8 +25,6 @@ struct fmt_merge_msg_opts {
25 extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
26 struct fmt_merge_msg_opts *);
27
28 -extern int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
29 -
28 extern int is_builtin(const char *s);
29
30 extern int cmd_add(int argc, const char **argv, const char *prefix);
builtin/blame.c
-28
@@ -146,34 +146,6 @@ static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b,
146 return xdi_diff(file_a, file_b, &xpp, &xecfg, &ecb);
147 }
148
149 -/*
150 - * Prepare diff_filespec and convert it using diff textconv API
151 - * if the textconv driver exists.
152 - * Return 1 if the conversion succeeds, 0 otherwise.
153 - */
154 -int textconv_object(const char *path,
155 - unsigned mode,
156 - const struct object_id *oid,
157 - int oid_valid,
158 - char **buf,
159 - unsigned long *buf_size)
160 -{
161 - struct diff_filespec *df;
162 - struct userdiff_driver *textconv;
163 -
164 - df = alloc_filespec(path);
165 - fill_filespec(df, oid->hash, oid_valid, mode);
166 - textconv = get_textconv(df);
167 - if (!textconv) {
168 - free_filespec(df);
169 - return 0;
170 - }
171 -
172 - *buf_size = fill_textconv(textconv, df, buf);
173 - free_filespec(df);
174 - return 1;
175 -}
176 -
149 /*
150 * Given an origin, prepare mmfile_t structure to be used by the
151 * diff machinery
builtin/cat-file.c
+1
@@ -5,6 +5,7 @@
5 */
6 #include "cache.h"
7 #include "builtin.h"
8 +#include "diff.h"
9 #include "parse-options.h"
10 #include "userdiff.h"
11 #include "streaming.h"
diff.c
+23
@@ -5270,6 +5270,29 @@ size_t fill_textconv(struct userdiff_driver *driver,
5270 return size;
5271 }
5272
5273 +int textconv_object(const char *path,
5274 + unsigned mode,
5275 + const struct object_id *oid,
5276 + int oid_valid,
5277 + char **buf,
5278 + unsigned long *buf_size)
5279 +{
5280 + struct diff_filespec *df;
5281 + struct userdiff_driver *textconv;
5282 +
5283 + df = alloc_filespec(path);
5284 + fill_filespec(df, oid->hash, oid_valid, mode);
5285 + textconv = get_textconv(df);
5286 + if (!textconv) {
5287 + free_filespec(df);
5288 + return 0;
5289 + }
5290 +
5291 + *buf_size = fill_textconv(textconv, df, buf);
5292 + free_filespec(df);
5293 + return 1;
5294 +}
5295 +
5296 void setup_diff_pager(struct diff_options *opt)
5297 {
5298 /*
diff.h
+7
@@ -385,6 +385,13 @@ extern size_t fill_textconv(struct userdiff_driver *driver,
385 */
386 extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
387
388 +/*
389 + * Prepare diff_filespec and convert it using diff textconv API
390 + * if the textconv driver exists.
391 + * Return 1 if the conversion succeeds, 0 otherwise.
392 + */
393 +extern int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
394 +
395 extern int parse_rename_score(const char **cp_p);
396
397 extern long parse_algorithm_value(const char *value);