Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: [PATCH] Add --symbolic flag to git-rev-parse.
Date: Tue, 16 Aug 2005 22:33:03 -0700	[thread overview]
Message-ID: <7v8xz13z74.fsf@assigned-by-dhcp.cox.net> (raw)

This is most useful with --all, --revs-only, --no-flags and --verify.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

    With this, "git-rev-parse --symbolic master pu" would output
    "master pu".  Why would this be useful?  The next one uses it.

 rev-parse.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

c7e32319f6c9338f186b62fe05919f0bc5ae7405
diff --git a/rev-parse.c b/rev-parse.c
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -16,6 +16,7 @@ static int output_revs = 0;
 static int flags_only = 0;
 static int no_flags = 0;
 static int output_sq = 0;
+static int symbolic = 0;
 
 #define NORMAL 0
 #define REVERSED 1
@@ -69,17 +70,18 @@ static void show(const char *arg)
 		puts(arg);
 }
 
-static void show_rev(int type, const unsigned char *sha1)
+static void show_rev(int type, const unsigned char *sha1, const char *name)
 {
 	if (no_revs)
 		return;
 	output_revs++;
 
-	/* Hexadecimal string plus possibly a carret;
-	 * this does not have to be quoted even under output_sq.
-	 */
-	printf("%s%s%c", type == show_type ? "" : "^", sha1_to_hex(sha1),
-	       output_sq ? ' ' : '\n');
+	if (type != show_type)
+		putchar('^');
+	if (symbolic && name)
+		show(name);
+	else
+		show(sha1_to_hex(sha1));
 }
 
 static void show_rev_arg(char *rev)
@@ -117,7 +119,7 @@ static void show_default(void)
 
 		def = NULL;
 		if (!get_sha1(s, sha1)) {
-			show_rev(NORMAL, sha1);
+			show_rev(NORMAL, sha1, s);
 			return;
 		}
 		show_arg(s);
@@ -126,7 +128,7 @@ static void show_default(void)
 
 static int show_reference(const char *refname, const unsigned char *sha1)
 {
-	show_rev(NORMAL, sha1);
+	show_rev(NORMAL, sha1, refname);
 	return 0;
 }
 
@@ -186,6 +188,10 @@ int main(int argc, char **argv)
 				show_type ^= REVERSED;
 				continue;
 			}
+			if (!strcmp(arg, "--symbolic")) {
+				symbolic = 1;
+				continue;
+			}
 			if (!strcmp(arg, "--all")) {
 				for_each_ref(show_reference);
 				continue;
@@ -209,8 +215,8 @@ int main(int argc, char **argv)
 					if (no_revs)
 						continue;
 					def = NULL;
-					show_rev(NORMAL, end);
-					show_rev(REVERSED, sha1);
+					show_rev(NORMAL, end, n);
+					show_rev(REVERSED, sha1, arg);
 					continue;
 				}
 			}
@@ -220,14 +226,14 @@ int main(int argc, char **argv)
 			if (no_revs)
 				continue;
 			def = NULL;
-			show_rev(NORMAL, sha1);
+			show_rev(NORMAL, sha1, arg);
 			continue;
 		}
 		if (*arg == '^' && !get_sha1(arg+1, sha1)) {
 			if (no_revs)
 				continue;
 			def = NULL;
-			show_rev(REVERSED, sha1);
+			show_rev(REVERSED, sha1, arg+1);
 			continue;
 		}
 		show_default();

                 reply	other threads:[~2005-08-17  5:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v8xz13z74.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox