Thread (17 messages) 17 messages, 2 authors, 2016-06-15

[PATCH v5 02/11] ref-filter: make `color` use `ref_formatting_state`

flat view
STALE3775d SUPERSEDED

From: Karthik Nayak <hidden>
Date: 2016-06-15 23:05:53
Subsystem: the rest · Maintainer: Linus Torvalds

Revision v5 of 11 in this series.

Revisions (11)
  1. v2 [diff vs current]
  2. v3 [diff vs current]
  3. v4 [diff vs current]
  4. v5 current
  5. v6 [diff vs current]
  6. v6 [diff vs current]
  7. v7 [diff vs current]
  8. v10 [diff vs current]
  9. v13 [diff vs current]
  10. v16 [diff vs current]
  11. v17 [diff vs current]
Make the `color` atom a pseudo atom and ensure that it uses
`ref_formatting_state`.
---
 ref-filter.c | 19 ++++++++++++++++++-
 ref-filter.h |  4 +++-
 2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index a3625e8..cc25c85 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -662,6 +662,8 @@ static void populate_value(struct ref_array_item *ref)
 			if (color_parse(name + 6, color) < 0)
 				die(_("unable to parse format"));
 			v->s = xstrdup(color);
+			v->pseudo_atom = 1;
+			v->color = 1;
 			continue;
 		} else if (!strcmp(name, "flag")) {
 			char buf[256], *cp = buf;
@@ -1195,6 +1197,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(state->color);
+		state->color = NULL;
+	}
 	strbuf_addf(value, "%s", v->s);
 }
 
@@ -1266,6 +1273,13 @@ static void emit(const char *cp, const char *ep)
 	}
 }
 
+static void apply_pseudo_state(struct ref_formatting_state *state,
+			       struct atom_value *v)
+{
+	if (v->color)
+		state->color = (char *)v->s;
+}
+
 void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style)
 {
 	const char *cp, *sp, *ep;
@@ -1281,7 +1295,10 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
 		if (cp < sp)
 			emit(cp, sp);
 		get_ref_atom_value(info, parse_ref_filter_atom(sp + 2, ep), &atomv);
-		print_value(&state, atomv);
+		if (atomv->pseudo_atom)
+			apply_pseudo_state(&state, atomv);
+		else
+			print_value(&state, atomv);
 	}
 	if (*cp) {
 		sp = cp + strlen(cp);
diff --git a/ref-filter.h b/ref-filter.h
index f24e3ef..7687879 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -19,11 +19,13 @@
 struct atom_value {
 	const char *s;
 	unsigned long ul; /* used for sorting when not FIELD_STR */
-	unsigned int pseudo_atom : 1; /*  atoms which aren't placeholders for ref attributes */
+	unsigned int pseudo_atom : 1, /*  atoms which aren't placeholders for ref attributes */
+		color : 1;
 };
 
 struct ref_formatting_state {
 	int quote_style;
+	char *color;
 };
 
 struct ref_sorting {
-- 
2.4.6
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help