git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Per-path attribute based hunk header selection.

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 6, 2007, 12:38 UTC
Message-ID
<Pine.LNX.4.64.0707061320510.4093@racer.site>
In-Reply-To
<7v8x9uexji.fsf_-_@assigned-by-dhcp.cox.net>
Hi,
On Fri, 6 Jul 2007, Junio C Hamano wrote:
Show 25 quoted lines
> 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;
	}
Show 7 quoted lines
> +	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().

Show 13 quoted lines
> +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

Previous: Junio C HamanoNext: Linus Torvalds
Message 15 of 29 in “diff: add custom regular expressions for function names”
  1. 2/2 diff: add custom regular expressions for function namesJohannes Schindelin, Jul 4, 2007
  2. Linus TorvaldsJul 4, 2007
  3. Johannes SchindelinJul 4, 2007
  4. Junio C HamanoJul 4, 2007
  5. Johannes SchindelinJul 4, 2007
  6. Junio C HamanoJul 5, 2007
  7. 1/2 Future-proof source for changes in xdemitconf_tJunio C Hamano, Jul 5, 2007
  8. Johannes SchindelinJul 5, 2007
  9. 2/2 WIP per-path attribute based hunk header selection.Junio C Hamano, Jul 5, 2007
  10. Johannes SchindelinJul 5, 2007
  11. Junio C HamanoJul 5, 2007
  12. 1/3 Introduce diff_filespec_is_binary()Junio C Hamano, Jul 6, 2007
  13. Johannes SchindelinJul 6, 2007
  14. Per-path attribute based hunk header selection.Junio C Hamano, Jul 6, 2007
  15. Johannes SchindelinJul 6, 2007
  16. Linus TorvaldsJul 6, 2007
  17. Junio C HamanoJul 7, 2007
  18. しらいしななこJul 7, 2007
  19. Junio C HamanoJul 7, 2007
  20. Johannes SchindelinJul 7, 2007
  21. Junio C HamanoJul 7, 2007
  22. Junio C HamanoJul 8, 2007
  23. Johannes SchindelinJul 8, 2007
  24. Nicolas PitreJul 9, 2007
  25. Junio C HamanoJul 9, 2007
  26. Johannes SchindelinJul 9, 2007
  27. Fix configuration syntax to specify customized hunk header patterns.Junio C Hamano, Jul 7, 2007
  28. Florian WeimerJul 5, 2007
  29. Johannes SchindelinJul 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.