[PATCH] git-for-each-ref: add new field name "symbolic"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



%(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@xxxxxxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]