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

[PATCH 4/5] name-rev: strip trailing ^0 in when --name-only

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jun 18, 2013, 17:13 UTC
Message-ID
<1371575608-9980-5-git-send-email-artagnon@gmail.com>
In-Reply-To
<1371575608-9980-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 | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 524d790..4b17209 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -160,7 +160,15 @@ 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.1.456.gb7f4cb6.dirty
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 5 of 6 in “Fix describe --contains --all”
  1. 0/5 Fix describe --contains --allRamkumar Ramachandra, Jun 18, 2013
  2. 1/5 prompt: clean up describe logicRamkumar Ramachandra, Jun 18, 2013
  3. 2/5 prompt: do not double-discriminate detached HEADRamkumar Ramachandra, Jun 18, 2013
  4. 3/5 name-rev: fix assumption about --name-only usageRamkumar Ramachandra, Jun 18, 2013
  5. 4/5 name-rev: strip trailing ^0 in when --name-onlyRamkumar Ramachandra, Jun 18, 2013
  6. 5/5 name-rev doc: rewrite --stdin paragraphRamkumar Ramachandra, Jun 18, 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.