git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: [PATCH] Fix 'diff=pgm' attribute to consult config
Date: Sun, 22 Apr 2007 21:41:59 -0700	[thread overview]
Message-ID: <11773033192350-git-send-email-junkio@cox.net> (raw)

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 <junkio@cox.net>
---
 diff.c                   |   60 ++++++++++++++++++++++++++++++++++++++++++++-
 t/t4020-diff-external.sh |    4 ++-
 2 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/diff.c b/diff.c
index ebc1997..db61a78 100644
--- a/diff.c
+++ b/diff.c
@@ -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;
 }
diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh
index 60a93a7..bae9c46 100755
--- a/t/t4020-diff-external.sh
+++ b/t/t4020-diff-external.sh
@@ -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 &&
-- 
1.5.1.2.936.ge4dd

                 reply	other threads:[~2007-04-23  4:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11773033192350-git-send-email-junkio@cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).