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 10:54:03AM -0800, Junio C Hamano wrote:

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