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

[PATCH v4 02/10] ref-filter: make the 'color' use ref_formatting_state

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jul 24, 2015, 19:04 UTC
Message-ID
<1437764685-8633-3-git-send-email-Karthik.188@gmail.com>
In-Reply-To
<1437764685-8633-1-git-send-email-Karthik.188@gmail.com>

Make color which was considered as an atom, to use ref_formatting_state and act as a pseudo atom. This allows interchangeability between 'align' and 'color'.

Helped-by: Junio C Hamano <gitster@pobox.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 ref-filter.c | 16 ++++++++++++----
 ref-filter.h |  1 +
 2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 3c90ffc..fd13a23 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -663,7 +663,8 @@ static void populate_value(struct ref_formatting_state *state,
 
 			if (color_parse(name + 6, color) < 0)
 				die(_("unable to parse format"));
-			v->s = xstrdup(color);
+			state->color = xstrdup(color);
+			v->pseudo_atom = 1;
 			continue;
 		} else if (!strcmp(name, "flag")) {
 			char buf[256], *cp = buf;
@@ -1217,6 +1218,11 @@ void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array)
 static void ref_formatting(struct ref_formatting_state *state, struct atom_value *v,
 			   struct strbuf *value)
 {
+	if (state->color) {
+		strbuf_addstr(value, state->color);
+		free((void *)state->color);
+		state->color = NULL;
+	}
 	if (state->pad_to_right) {
 		if (!is_utf8(v->s))
 			strbuf_addf(value, "%-*s", state->pad_to_right, v->s);
@@ -1224,8 +1230,9 @@ static void ref_formatting(struct ref_formatting_state *state, struct atom_value
 			int len = strlen(v->s) - utf8_strwidth(v->s);
 			strbuf_addf(value, "%-*s", state->pad_to_right + len, v->s);
 		}
-	} else
-		strbuf_addf(value, "%s", v->s);
+		return;
+	}
+	strbuf_addf(value, "%s", v->s);
 }
 
 static void print_value(struct ref_formatting_state *state, struct atom_value *v)
@@ -1326,7 +1333,8 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
 
 		if (color_parse("reset", color) < 0)
 			die("BUG: couldn't parse 'reset' as a color");
-		resetv.s = color;
+		resetv.s = "";
+		state.color = xstrdup(color);
 		print_value(&state, &resetv);
 	}
 	putchar('\n');
diff --git a/ref-filter.h b/ref-filter.h
index ea2d0e6..bacbb23 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -31,6 +31,7 @@ struct ref_sorting {
 struct ref_formatting_state {
 	unsigned int pad_to_right; /*pad atoms to the right*/
 	int quote_style;
+	const char *color;
 };
 
 struct ref_array_item {
-- 
2.4.6
Previous: Duy NguyenNext: Junio C Hamano
Message 15 of 36 in “port tag.c to use ref-filter APIs”
  1. 0/10 port tag.c to use ref-filter APIsKarthik Nayak, Jul 24, 2015
  2. 01/10 ref-filter: add option to align atoms to the leftKarthik Nayak, Jul 24, 2015
  3. Junio C HamanoJul 24, 2015
  4. Junio C HamanoJul 24, 2015
  5. Karthik NayakJul 25, 2015
  6. Eric SunshineJul 26, 2015
  7. Karthik NayakJul 26, 2015
  8. Eric SunshineJul 26, 2015
  9. Karthik NayakJul 26, 2015
  10. Matthieu MoyJul 27, 2015
  11. Duy NguyenJul 27, 2015
  12. Jacob KellerJul 27, 2015
  13. Duy NguyenJul 27, 2015
  14. Duy NguyenJul 28, 2015
  15. 02/10 ref-filter: make the 'color' use ref_formatting_stateKarthik Nayak, Jul 24, 2015
  16. Junio C HamanoJul 24, 2015
  17. Karthik NayakJul 25, 2015
  18. Eric SunshineJul 26, 2015
  19. Eric SunshineJul 26, 2015
  20. Karthik NayakJul 26, 2015
  21. 03/10 ref-filter: add option to filter only tagsKarthik Nayak, Jul 24, 2015
  22. 04/10 ref-filter: support printing N lines from tag annotationKarthik Nayak, Jul 24, 2015
  23. Eric SunshineJul 26, 2015
  24. Karthik NayakJul 26, 2015
  25. 05/10 ref-filter: add support to sort by versionKarthik Nayak, Jul 24, 2015
  26. Junio C HamanoJul 25, 2015
  27. Karthik NayakJul 26, 2015
  28. Junio C HamanoJul 27, 2015
  29. Karthik NayakJul 27, 2015
  30. 06/10 ref-filter: add option to match literal patternKarthik Nayak, Jul 24, 2015
  31. Eric SunshineJul 26, 2015
  32. Karthik NayakJul 26, 2015
  33. 07/10 tag.c: use 'ref-filter' data structuresKarthik Nayak, Jul 24, 2015
  34. 08/10 tag.c: use 'ref-filter' APIsKarthik Nayak, Jul 24, 2015
  35. 09/10 tag.c: implement '--format' optionKarthik Nayak, Jul 24, 2015
  36. 10/10 tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak, Jul 24, 2015

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.