git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>, git@vger.kernel.org
Subject: Re: [PATCH] Per-path attribute based hunk header selection.
Date: Fri, 6 Jul 2007 13:38:42 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0707061320510.4093@racer.site> (raw)
In-Reply-To: <7v8x9uexji.fsf_-_@assigned-by-dhcp.cox.net>

Hi,

On Fri, 6 Jul 2007, Junio C Hamano wrote:

> diff --git a/diff.c b/diff.c
> @@ -1143,6 +1154,82 @@ int diff_filespec_is_binary(struct diff_filespec *one)
>  	return one->is_binary;
>  }
>  
> +static struct hunk_header_regexp {
> +	char *name;
> +	char *regexp;
> +	struct hunk_header_regexp *next;
> +} *hunk_header_regexp_list, **hunk_header_regexp_tail;
> +
> +static int hunk_header_config(const char *var, const char *value)
> +{
> +	static const char funcname[] = "funcname.";
> +	struct hunk_header_regexp *hh;
> +
> +	if (prefixcmp(var, funcname))
> +		return 0;
> +	var += strlen(funcname);
> +	for (hh = hunk_header_regexp_list; hh; hh = hh->next)
> +		if (!strcmp(var, hh->name)) {
> +			free(hh->regexp);
> +			hh->regexp = xstrdup(value);
> +			return 0;
> +		}

Heh. By reordering your code, you could say

	if ((hh = hunk_header_regexp(var))) {
		free(hh->regexp);
		hh->regexp = xstrdup(value);
		return 0;
	}

> +	hh = xcalloc(1, sizeof(*hh));
> +	hh->name = xstrdup(var);
> +	hh->regexp = xstrdup(value);
> +	hh->next = NULL;
> +	*hunk_header_regexp_tail = hh;
> +	return 0;
> +}

Is that tail expansion not overly complex? Why not just set "hh->next = 
hunk_header_regexp_list; hunk_header_regexp_list = hh";

Yes, your code seems correct, but I took some extra cycles to get at that 
impression. A "static int parsed_config_for_hunk_headers" would have 
helped, instead of reusing _tail for two purposes. And this variable could 
be set at the beginning of hunk_header_config(), so that 
hunk_header_regexp() is usable from inside hunk_header_config().

> +static const char *hunk_header_regexp(const char *ident)
> +{
> +	struct hunk_header_regexp *hh;
> +
> +	if (!hunk_header_regexp_tail) {
> +		hunk_header_regexp_tail = &hunk_header_regexp_list;
> +		git_config(hunk_header_config);
> +	}
> +	for (hh = hunk_header_regexp_list; hh; hh = hh->next)
> +		if (!strcmp(ident, hh->name))
> +			return hh->regexp;
> +	return NULL;
> +}

Another thing. These long names are a bit inconsistent. In the config, you 
name it "funcname". In xdiff, we name them "FUNCNAMES". Yes, here they are 
hunk_headers.

Also, since the expressions are not strictly regular expressions, but 
lists of them, and with your idea they are even more different, why not 
just go for "funcname_list"? It's easier to read, and static anyway.

Rest looks fine to me...

Ciao,
Dscho

  reply	other threads:[~2007-07-06 12:46 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-04 18:06 [PATCH 2/2] diff: add custom regular expressions for function names Johannes Schindelin
2007-07-04 18:41 ` Linus Torvalds
2007-07-04 18:45   ` Johannes Schindelin
2007-07-04 20:44   ` Junio C Hamano
2007-07-04 21:20     ` Johannes Schindelin
2007-07-05  5:00     ` Junio C Hamano
2007-07-05  5:02       ` [PATCH 1/2] Future-proof source for changes in xdemitconf_t Junio C Hamano
2007-07-05 11:01         ` Johannes Schindelin
2007-07-05  5:02       ` [PATCH 2/2] WIP per-path attribute based hunk header selection Junio C Hamano
2007-07-05 11:25         ` Johannes Schindelin
2007-07-05 16:43           ` Junio C Hamano
2007-07-06  8:37           ` [PATCH 1/3] Introduce diff_filespec_is_binary() Junio C Hamano
2007-07-06 12:20             ` Johannes Schindelin
2007-07-06  8:39           ` [PATCH] Per-path attribute based hunk header selection Junio C Hamano
2007-07-06 12:38             ` Johannes Schindelin [this message]
2007-07-06 17:59             ` Linus Torvalds
2007-07-07  2:00               ` Junio C Hamano
2007-07-07 10:08                 ` しらいしななこ
2007-07-07 10:22                   ` Junio C Hamano
2007-07-07 12:17                     ` Johannes Schindelin
2007-07-07 20:36                       ` Junio C Hamano
2007-07-08  7:23                       ` Junio C Hamano
2007-07-08 11:58                         ` Johannes Schindelin
2007-07-09  3:22                 ` Nicolas Pitre
2007-07-09  5:05                   ` Junio C Hamano
2007-07-09 11:40                     ` Johannes Schindelin
2007-07-07 10:12               ` [PATCH] Fix configuration syntax to specify customized hunk header patterns Junio C Hamano
2007-07-05  8:24       ` [PATCH 2/2] diff: add custom regular expressions for function names Florian Weimer
2007-07-05 11:44       ` Johannes Schindelin

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

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

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0707061320510.4093@racer.site \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=torvalds@linux-foundation.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.
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 NNTP newsgroup(s).