git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-for-each-ref: add new field name "symbolic"
@ 2010-02-13  5:55 Larry D'Anna
  2010-02-13  7:45 ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Larry D'Anna @ 2010-02-13  5:55 UTC (permalink / raw)
  To: git; +Cc: Larry D'Anna

%(symbolic) will expand to "true" for symbolic refs, and "false" otherwise.
This is a lot faster than calling git-symbolic-ref on every single ref from your
shell script.

Signed-off-by: Larry D'Anna <larry@elder-gods.org>
---
 Documentation/git-for-each-ref.txt |    3 +++
 builtin-for-each-ref.c             |    5 +++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 7e83288..c2a694f 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -92,6 +92,9 @@ upstream::
 	from the displayed ref. Respects `:short` in the same way as
 	`refname` above.
 
+symbolic::
+	"true" for symbolic refs, "false" otherwise.
+
 In addition to the above, for commit and tag objects, the header
 field names (`tree`, `parent`, `object`, `type`, and `tag`) can
 be used to specify the value in the header field.
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index a5a83f1..fd6973e 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -33,6 +33,7 @@ struct ref_sort {
 struct refinfo {
 	char *refname;
 	unsigned char objectname[20];
+	int flag;
 	struct atom_value *value;
 };
 
@@ -66,6 +67,7 @@ static struct {
 	{ "creatordate", FIELD_TIME },
 	{ "subject" },
 	{ "body" },
+	{ "symbolic" },
 	{ "contents" },
 	{ "upstream" },
 };
@@ -576,6 +578,8 @@ static void populate_value(struct refinfo *ref)
 
 		if (!prefixcmp(name, "refname"))
 			refname = ref->refname;
+		else if (!prefixcmp(name, "symbolic"))
+			refname = (ref->flag & REF_ISSYMREF) ? "true" : "false";
 		else if (!prefixcmp(name, "upstream")) {
 			struct branch *branch;
 			/* only local branches may have an upstream */
@@ -716,6 +720,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
 	 * by maxcount logic.
 	 */
 	ref = xcalloc(1, sizeof(*ref));
+	ref->flag = flag;
 	ref->refname = xstrdup(refname);
 	hashcpy(ref->objectname, sha1);
 
-- 
1.7.0.rc2.40.g7d8aa

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-02-15  8:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-13  5:55 [PATCH] git-for-each-ref: add new field name "symbolic" Larry D'Anna
2010-02-13  7:45 ` Junio C Hamano
2010-02-13  8:51   ` Jeff King
2010-02-13 20:30     ` [PATCH 0/4] for-each-ref --format='%(symref) %(symref:short) %(flag)' Junio C Hamano
2010-02-13 20:30       ` [PATCH 1/4] builtin-for-each-ref.c: comment fixes Junio C Hamano
2010-02-13 20:30       ` [PATCH 2/4] builtin-for-each-ref.c: check if we need to peel onion while parsing the format Junio C Hamano
2010-02-13 20:30       ` [PATCH 3/4] for-each-ref --format='%(symref) %(symref:short)' Junio C Hamano
2010-02-14  6:32         ` Jeff King
2010-02-14 10:32           ` Junio C Hamano
2010-02-15  8:39             ` Jeff King
2010-02-13 20:30       ` [PATCH 4/4] for-each-ref --format='%(flag)' Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).