Fix 'diff=pgm' attribute to consult config
PATCH 1/1 Fix 'diff=pgm' attribute to consult config
This builds on top of the previous 'diff=pgm' attribute support. Attributes only name a low-level diff driver, which is defined in the configuration:
[lldiff "drivername"] command = ...
The earlier one lacked this indirection, which was a mistake.
Signed-off-by Junio C Hamano <[email protected]>
--- diff.c | 60 ++++++++++++++++++++++++++++++++++++++++++++- t/t4020-diff-external.sh | 4 ++- 2 files changed, 61 insertions(+), 3 deletions(-)
diff.c +58 -2
@@ -1747,6 +1747,53 @@ static void run_external_diff(const char *pgm, } } +static struct ll_diff_driver { +const char *name; +struct ll_diff_driver *next; +char *cmd; +} *user_diff, **user_diff_tail; + +static int parse_lldiff_config (const char *var,const char *value) +{ +const char *ep, *name; +int namelen; +struct ll_diff_driver *drv; + +if (prefixcmp (var,"lldiff." )) +return 0 ; + +/* "lldiff.<drivername>.<variable>" */ +if ((ep =strrchr (var,'.' )) == var +6 ) +return 0 ; + name = var +7 ; + namelen = ep - name; +for (drv = user_diff; drv; drv = drv->next) +if (!strncmp (drv->name, name, namelen) && !drv->name[namelen]) +break ; +if (!drv) { +char *namebuf; + drv =xcalloc (1 ,sizeof (struct ll_diff_driver )); + namebuf =xmalloc (namelen +1 ); +memcpy (namebuf, name, namelen); + namebuf[namelen] =0 ; + drv->name = namebuf; + drv->next =NULL ; + *user_diff_tail = drv; + user_diff_tail = &(drv->next); + } + + ep++; + +if (!strcmp ("command" , ep)) { +if (!value) +return error ("%s: lacks value" , var); + drv->cmd =strdup (value); +return 0 ; + } + +return 0 ; +} +static const char *external_diff_attr (const char *name) {struct git_attr_check attr_diff_check;
@@ -1756,8 +1803,17 @@ static const char *external_diff_attr(const char *name)const char *value = attr_diff_check.value;if (!ATTR_TRUE (value) && !ATTR_FALSE (value) && - !ATTR_UNSET (value)) -return value; + !ATTR_UNSET (value)) { +struct ll_diff_driver *drv; + +if (!user_diff_tail) { + user_diff_tail = &user_diff; +git_config (parse_lldiff_config); + } +for (drv = user_diff; drv; drv = drv->next) +if (!strcmp (drv->name, value)) +return drv->cmd; + } }return NULL ; }
t/t4020-diff-external.sh +3 -1
@@ -45,7 +45,9 @@ test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' ' test_expect_success 'diff attribute' ' - echo >.gitattributes "file diff=echo" && + git config lldiff.parrot.command echo && + + echo >.gitattributes "file diff=parrot" && git diff | { read path oldfile oldhex oldmode newfile newhex newmode &&
Signature · 1 line
1.5.1.2.936.ge4dd