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

Re: [PATCH] git-reset.txt: Use commit~1 notation over commit^

From
Jeff King <peff@peff.net>
Date
Dec 2, 2010, 19:05 UTC
Message-ID
<20101202190553.GB20225@sigill.intra.peff.net>
In-Reply-To
<7vvd3cqa44.fsf@alter.siamese.dyndns.org>
On Thu, Dec 02, 2010 at 10:54:03AM -0800, Junio C Hamano wrote:
Show 14 quoted lines
> > but I am not sure the results are always more readable. I think "foo^"
> > is perhaps nicer than "foo~1". But in more complex examples, I kind of
> > think the ~1 is easier to read. E.g.:
> >
> >   # old
> >   $ git name-rev 9904fadf
> >   9904fadf tags/v1.7.3-rc2~1^2~1
> >
> >   # new
> >   $ git name-rev 9904fadf
> >   9904fadf tags/v1.7.3-rc2~1^2^
> 
> Curious.  Why does the "first take the first parent of rc2" is left as-is,
> while "then lastly take its parent" does get shortened?

Because my patch is crappy and I didn't spend more than 30 seconds testing it? :)

It needs a similar change elsewhere, so the full patch should be:
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index c946a82..03d7bce 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -64,9 +64,15 @@ copy_data:
 
 			if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
 				len -= 2;
-			if (generation > 0)
-				sprintf(new_name, "%.*s~%d^%d", len, tip_name,
+			if (generation > 0) {
+				int w = sprintf(new_name, "%.*s", len, tip_name);
+				if (generation == 1)
+					sprintf(new_name + w, "^^%d",
+						parent_number);
+				else
+					sprintf(new_name + w, "~%d^%d",
 						generation, parent_number);
+			}
 			else
 				sprintf(new_name, "%.*s^%d", len, tip_name,
 						parent_number);
@@ -142,8 +148,12 @@ static const char *get_rev_name(const struct object *o)
 		int len = strlen(n->tip_name);
 		if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
 			len -= 2;
-		snprintf(buffer, sizeof(buffer), "%.*s~%d", len, n->tip_name,
-				n->generation);
+		if (n->generation == 1)
+			snprintf(buffer, sizeof(buffer), "%.*s^", len,
+				 n->tip_name);
+		else
+			snprintf(buffer, sizeof(buffer), "%.*s~%d", len,
+				 n->tip_name, n->generation);
 
 		return buffer;
 	}

However, IMHO that looks even worse:

  $ git name-rev 9904fadf
  9904fadf tags/v1.7.3-rc2^^2^

-Peff
Previous: Junio C HamanoNext: Miles Bader
Message 22 of 23 in “git-reset.txt: Use commit~1 notation over commit^”
  1. git-reset.txt: Use commit~1 notation over commit^jari.aalto@cante.net, Dec 1, 2010
  2. Drew NorthupDec 1, 2010
  3. Jari AaltoDec 1, 2010
  4. Kevin BallardDec 1, 2010
  5. Jari AaltoDec 1, 2010
  6. Kevin BallardDec 1, 2010
  7. Junio C HamanoDec 1, 2010
  8. Jari AaltoDec 1, 2010
  9. Andreas SchwabDec 2, 2010
  10. Jari AaltoDec 2, 2010
  11. Santi BéjarDec 1, 2010
  12. Jari AaltoDec 2, 2010
  13. Miles BaderDec 2, 2010
  14. Jari AaltoDec 2, 2010
  15. Drew NorthupDec 2, 2010
  16. Miles BaderDec 2, 2010
  17. jariDec 2, 2010
  18. Andreas SchwabDec 2, 2010
  19. Junio C HamanoDec 2, 2010
  20. Jeff KingDec 2, 2010
  21. Junio C HamanoDec 2, 2010
  22. Jeff KingDec 2, 2010
  23. Miles BaderDec 2, 2010

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.