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

Re: [PATCH 2/2] builtin/blame: highlight recently changed lines

From
René Scharfe <l.s.r@web.de>
Date
Jun 9, 2018, 11:26 UTC
Message-ID
<737e4f2e-9896-0119-2c43-655ac29fe018@web.de>
In-Reply-To
<20180417213049.118995-2-sbeller@google.com>
Am 17.04.2018 um 23:30 schrieb Stefan Beller:
Show 9 quoted lines
> +static void parse_color_fields(const char *s)
> +{
> +	struct string_list l = STRING_LIST_INIT_DUP;
> +	struct string_list_item *item;
> +	enum { EXPECT_DATE, EXPECT_COLOR } next = EXPECT_COLOR;
> +
> +	colorfield_nr = 0;
> +
> +	/* Ideally this would be stripped and split at the same time? */
Why?  Both approxidate() and color_parse() handle spaces.
Show 24 quoted lines
> +	string_list_split(&l, s, ',', -1);
> +	ALLOC_GROW(colorfield, colorfield_nr + 1, colorfield_alloc);
> +
> +	for_each_string_list_item(item, &l) {
> +		switch (next) {
> +		case EXPECT_DATE:
> +			colorfield[colorfield_nr].hop = approxidate(item->string);
> +			next = EXPECT_COLOR;
> +			colorfield_nr++;
> +			ALLOC_GROW(colorfield, colorfield_nr + 1, colorfield_alloc);
> +			break;
> +		case EXPECT_COLOR:
> +			if (color_parse(item->string, colorfield[colorfield_nr].col))
> +				die(_("expecting a color: %s"), item->string);
> +			next = EXPECT_DATE;
> +			break;
> +		}
> +	}
> +
> +	if (next == EXPECT_COLOR)
> +		die (_("must end with a color"));
> +
> +	colorfield[colorfield_nr].hop = TIME_MAX;
> +}
This adds a minor memory leak; fix below.
-- >8 --
Subject: [PATCH] blame: release string_list after use in parse_color_fields()
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/blame.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/builtin/blame.c b/builtin/blame.c
index 4202584f97..3295718841 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -411,6 +411,7 @@ static void parse_color_fields(const char *s)
 		die (_("must end with a color"));
 
 	colorfield[colorfield_nr].hop = TIME_MAX;
+	string_list_clear(&l, 0);
 }
 
 static void setup_default_color_by_age(void)
-- 
2.17.1
Previous: Junio C HamanoNext: Stefan Beller
Message 14 of 18 in “blame: color line by commit”
  1. 0/2 blame: color line by commitStefan Beller, Apr 16, 2018
  2. 1/2 builtin/blame: dim uninteresting metadata linesStefan Beller, Apr 16, 2018
  3. Junio C HamanoApr 17, 2018
  4. Stefan BellerApr 17, 2018
  5. 2/2 builtin/blame: highlight recently changed linesStefan Beller, Apr 16, 2018
  6. Junio C HamanoApr 17, 2018
  7. Junio C HamanoApr 17, 2018
  8. Stefan BellerApr 17, 2018
  9. Stefan BellerApr 17, 2018
  10. 1/2 builtin/blame: dim uninteresting metadata linesStefan Beller, Apr 17, 2018
  11. 2/2 builtin/blame: highlight recently changed linesStefan Beller, Apr 17, 2018
  12. Eric SunshineApr 17, 2018
  13. Junio C HamanoApr 18, 2018
  14. René ScharfeJun 9, 2018
  15. Stefan BellerJun 11, 2018
  16. Junio C HamanoJun 14, 2018
  17. Junio C HamanoApr 18, 2018
  18. Junio C HamanoApr 18, 2018

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.