Skip to content

Commit 3a35cb2

Browse files
whydoubtgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b84bc9c commit 3a35cb2

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

builtin.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ struct fmt_merge_msg_opts {
2525
extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
2626
struct fmt_merge_msg_opts *);
2727

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-
3028
extern int is_builtin(const char *s);
3129

3230
extern int cmd_add(int argc, const char **argv, const char *prefix);

builtin/blame.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -146,34 +146,6 @@ static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b,
146146
return xdi_diff(file_a, file_b, &xpp, &xecfg, &ecb);
147147
}
148148

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-
177149
/*
178150
* Given an origin, prepare mmfile_t structure to be used by the
179151
* diff machinery

builtin/cat-file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include "cache.h"
77
#include "builtin.h"
8+
#include "diff.h"
89
#include "parse-options.h"
910
#include "userdiff.h"
1011
#include "streaming.h"

diff.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5270,6 +5270,29 @@ size_t fill_textconv(struct userdiff_driver *driver,
52705270
return size;
52715271
}
52725272

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+
52735296
void setup_diff_pager(struct diff_options *opt)
52745297
{
52755298
/*

diff.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ extern size_t fill_textconv(struct userdiff_driver *driver,
385385
*/
386386
extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
387387

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+
388395
extern int parse_rename_score(const char **cp_p);
389396

390397
extern long parse_algorithm_value(const char *value);

0 commit comments

Comments
 (0)