git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] name-rev: strip trailing ^0 in when --name-only

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jul 7, 2013, 12:43 UTC
Message-ID
<1373200996-9753-3-git-send-email-artagnon@gmail.com>
In-Reply-To
<1373200996-9753-1-git-send-email-artagnon@gmail.com>

236157 (Teach git-describe how to run name-rev, 2007-05-21) introduced `git name-rev --name-only`, with the intent of using it to implement `git describe --contains`. According to the message, one of the primary objectives of --name-only was to make the output of name-rev match that of describe.

  $ git describe --contains --all master
  master
  $ git describe --contains --all master~1
  master~1
  $ git describe --contains --all v1.8.3~1
  v1.8.3~1
  $ git describe --contains --all v1.8.3
  v1.8.3^0

The last invocation unnecessarily prints a trailing "^0" (--stdin does not suffer from this defect). Fix this.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/name-rev.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 37207a9..8ba5d72 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -186,7 +186,14 @@ static void show_name(const struct object *obj,
 	if (!name_only)
 		printf("%s ", caller_name ? caller_name : sha1_to_hex(sha1));
 	name = get_rev_name(obj);
-	if (name)
+
+	if (name && name_only) {
+		/* strip possible trailing ^0 from name */
+		int len = strlen(name);
+		if (len > 2 && !strcmp(name + len - 2, "^0"))
+			len -= 2;
+		printf("%.*s\n", len, name);
+	} else if (name)
 		printf("%s\n", name);
 	else if (allow_undefined)
 		printf("undefined\n");
-- 
1.8.3.2.737.gcbc076a.dirty
Previous: Ramkumar RamachandraNext: Junio C Hamano
Message 5 of 10 in “Iron output of describe --contains --all”
  1. 0/3 Iron output of describe --contains --allRamkumar Ramachandra, Jul 7, 2013
  2. 1/3 name-rev: fix assumption about --name-only usageRamkumar Ramachandra, Jul 7, 2013
  3. Junio C HamanoJul 7, 2013
  4. Ramkumar RamachandraJul 8, 2013
  5. 2/3 name-rev: strip trailing ^0 in when --name-onlyRamkumar Ramachandra, Jul 7, 2013
  6. Junio C HamanoJul 7, 2013
  7. Junio C HamanoJul 7, 2013
  8. Ramkumar RamachandraJul 8, 2013
  9. 3/3 name-rev doc: rewrite --stdin paragraphRamkumar Ramachandra, Jul 7, 2013
  10. Junio C HamanoJul 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.