Skip to content

Commit aa6c22e

Browse files
committed
Merge branch 'jk/more-comments-on-textconv' into maint
The memory ownership rule of fill_textconv() API, which was a bit tricky, has been documented a bit better. * jk/more-comments-on-textconv: diff: clarify textconv interface
2 parents 6044329 + a64e6a4 commit aa6c22e

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5085,7 +5085,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
50855085
{
50865086
size_t size;
50875087

5088-
if (!driver || !driver->textconv) {
5088+
if (!driver) {
50895089
if (!DIFF_FILE_VALID(df)) {
50905090
*outbuf = "";
50915091
return 0;
@@ -5096,6 +5096,9 @@ size_t fill_textconv(struct userdiff_driver *driver,
50965096
return df->size;
50975097
}
50985098

5099+
if (!driver->textconv)
5100+
die("BUG: fill_textconv called with non-textconv driver");
5101+
50995102
if (driver->textconv_cache && df->sha1_valid) {
51005103
*outbuf = notes_cache_get(driver->textconv_cache, df->sha1,
51015104
&size);

diff.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,26 @@ extern void diff_no_index(struct rev_info *, int, const char **);
349349

350350
extern int index_differs_from(const char *def, int diff_flags);
351351

352+
/*
353+
* Fill the contents of the filespec "df", respecting any textconv defined by
354+
* its userdiff driver. The "driver" parameter must come from a
355+
* previous call to get_textconv(), and therefore should either be NULL or have
356+
* textconv enabled.
357+
*
358+
* Note that the memory ownership of the resulting buffer depends on whether
359+
* the driver field is NULL. If it is, then the memory belongs to the filespec
360+
* struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
361+
* that should be freed by the caller.
362+
*/
352363
extern size_t fill_textconv(struct userdiff_driver *driver,
353364
struct diff_filespec *df,
354365
char **outbuf);
355366

367+
/*
368+
* Look up the userdiff driver for the given filespec, and return it if
369+
* and only if it has textconv enabled (otherwise return NULL). The result
370+
* can be passed to fill_textconv().
371+
*/
356372
extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
357373

358374
extern int parse_rename_score(const char **cp_p);

userdiff.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ 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+
/*
27+
* Initialize any textconv-related fields in the driver and return it, or NULL
28+
* if it does not have textconv enabled at all.
29+
*/
2630
struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver);
2731

2832
#endif /* USERDIFF */

0 commit comments

Comments
 (0)