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

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

 



On Thu, Dec 02, 2010 at 09:55:03AM -0800, Junio C Hamano wrote:

> Perhaps we need to also fix "git name-rev master^" which currently does
> not try to reduce "master~1" to "master^".

This patch does it:

diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index c946a82..417bae5 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -142,8 +142,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;
 	}

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^

Somehow the visual appearance of "^2^" ends up being more confusing to
me than ~1^2~1, I guess because in the latter there is a regular set of
modifier-number pairs.

But I admit that is just my subjective opinion.

-Peff
--
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]