Thread (21 messages) flat view 21 messages, 2 authors, 2016-06-15
STALE3727d

Revision v2 of 2 in this series.

Revisions (2)
  1. v2 current
  2. v3 [diff vs current]

[PATCH 11/12] for-each-ref: use skip_prefix instead of starts_with

From: Jeff King <hidden>
Date: 2016-06-15 23:04:37
Subsystem: the rest · Maintainer: Linus Torvalds

This saves us having to maintain a magic number to skip past
the matched prefix.

Signed-off-by: Jeff King <redacted>
---
Noticed because I'm adding similar code in the next patch...

 builtin/for-each-ref.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 18d209b..345d8dd 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -659,10 +659,12 @@ static void populate_value(struct refinfo *ref)
 		else if (starts_with(name, "symref"))
 			refname = ref->symref ? ref->symref : "";
 		else if (starts_with(name, "upstream")) {
+			const char *branch_name;
 			/* only local branches may have an upstream */
-			if (!starts_with(ref->refname, "refs/heads/"))
+			if (!skip_prefix(ref->refname, "refs/heads/",
+					 &branch_name))
 				continue;
-			branch = branch_get(ref->refname + 11);
+			branch = branch_get(branch_name);
 
 			refname = branch_get_upstream(branch, NULL);
 			if (!refname)
-- 
2.4.0.rc3.477.gc25258d
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help