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

Re: [PATCH v2 3/6] diff: diff_aligned_abbrev: remove ellipsis after abbreviated SHA-1 value

From
Ann T Ropea <bedhanger@gmx.de>
Date
Nov 13, 2017, 22:36 UTC
Message-ID
<20171113223654.27732-3-bedhanger@gmx.de>
In-Reply-To
<20171113223654.27732-1-bedhanger@gmx.de>

Neither Git nor the user are in need of this (visual) aid anymore, but we must offer a transition period.

Also, fix a typo: "abbbreviated" ---> "abbreviated".
Signed-off-by: Ann T Ropea <bedhanger@gmx.de>
---
v2: rename patch series & focus on removal of ellipses
 diff.c | 69 +++++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 39 insertions(+), 30 deletions(-)
diff --git a/diff.c b/diff.c
index 0763e89263ef..9709dc37c6d7 100644
--- a/diff.c
+++ b/diff.c
@@ -4902,41 +4902,50 @@ const char *diff_aligned_abbrev(const struct object_id *oid, int len)
 	int abblen;
 	const char *abbrev;
 
+	/* Do we want all 40 hex characters?
+	 */
 	if (len == GIT_SHA1_HEXSZ)
 		return oid_to_hex(oid);
 
-	abbrev = diff_abbrev_oid(oid, len);
-	abblen = strlen(abbrev);
-
-	/*
-	 * In well-behaved cases, where the abbbreviated result is the
-	 * same as the requested length, append three dots after the
-	 * abbreviation (hence the whole logic is limited to the case
-	 * where abblen < 37); when the actual abbreviated result is a
-	 * bit longer than the requested length, we reduce the number
-	 * of dots so that they match the well-behaved ones.  However,
-	 * if the actual abbreviation is longer than the requested
-	 * length by more than three, we give up on aligning, and add
-	 * three dots anyway, to indicate that the output is not the
-	 * full object name.  Yes, this may be suboptimal, but this
-	 * appears only in "diff --raw --abbrev" output and it is not
-	 * worth the effort to change it now.  Note that this would
-	 * likely to work fine when the automatic sizing of default
-	 * abbreviation length is used--we would be fed -1 in "len" in
-	 * that case, and will end up always appending three-dots, but
-	 * the automatic sizing is supposed to give abblen that ensures
-	 * uniqueness across all objects (statistically speaking).
+	/* An abbreviated value is fine, possibly followed by an
+	 * ellipsis.
 	 */
-	if (abblen < GIT_SHA1_HEXSZ - 3) {
-		static char hex[GIT_MAX_HEXSZ + 1];
-		if (len < abblen && abblen <= len + 2)
-			xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
-		else
-			xsnprintf(hex, sizeof(hex), "%s...", abbrev);
-		return hex;
-	}
+	if (print_sha1_ellipsis) {
+		abbrev = diff_abbrev_oid(oid, len);
+		abblen = strlen(abbrev);
+
+		/*
+		 * In well-behaved cases, where the abbreviated result is the
+		 * same as the requested length, append three dots after the
+		 * abbreviation (hence the whole logic is limited to the case
+		 * where abblen < 37); when the actual abbreviated result is a
+		 * bit longer than the requested length, we reduce the number
+		 * of dots so that they match the well-behaved ones.  However,
+		 * if the actual abbreviation is longer than the requested
+		 * length by more than three, we give up on aligning, and add
+		 * three dots anyway, to indicate that the output is not the
+		 * full object name.  Yes, this may be suboptimal, but this
+		 * appears only in "diff --raw --abbrev" output and it is not
+		 * worth the effort to change it now.  Note that this would
+		 * likely to work fine when the automatic sizing of default
+		 * abbreviation length is used--we would be fed -1 in "len" in
+		 * that case, and will end up always appending three-dots, but
+		 * the automatic sizing is supposed to give abblen that ensures
+		 * uniqueness across all objects (statistically speaking).
+		 */
+		if (abblen < GIT_SHA1_HEXSZ - 3) {
+			static char hex[GIT_MAX_HEXSZ + 1];
+			if (len < abblen && abblen <= len + 2)
+				xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
+			else
+				xsnprintf(hex, sizeof(hex), "%s...", abbrev);
+			return hex;
+		}
 
-	return oid_to_hex(oid);
+		return oid_to_hex(oid);
+	} else {
+		return diff_abbrev_oid(oid, len);
+	}
 }
 
 static void diff_flush_raw(struct diff_filepair *p, struct diff_options *opt)
-- 
2.13.6
Previous: Ann T RopeaNext: Junio C Hamano
Message 14 of 58 in “checkout: describe_detached_head: remove 3dots after committish”
  1. 1/3 checkout: describe_detached_head: remove 3dots after committishAnn T Ropea, Nov 5, 2017
  2. 2/3 Documentation: user-manual: limit potentially confusing usage of 3dots (and 2dots)Ann T Ropea, Nov 5, 2017
  3. 3/3 Documentation: revisions: add note about 3dots usages as continuation indicationsAnn T Ropea, Nov 5, 2017
  4. Junio C HamanoNov 6, 2017
  5. Junio C HamanoNov 6, 2017
  6. Philip OakleyNov 7, 2017
  7. Junio C HamanoNov 7, 2017
  8. Ann T RopeaNov 7, 2017
  9. Philip OakleyNov 7, 2017
  10. Junio C HamanoNov 8, 2017
  11. Philip OakleyNov 9, 2017
  12. Ann T RopeaNov 13, 2017
  13. Ann T RopeaNov 13, 2017
  14. Ann T RopeaNov 13, 2017
  15. Junio C HamanoNov 14, 2017
  16. Ann T RopeaNov 19, 2017
  17. Junio C HamanoNov 20, 2017
  18. Ann T RopeaNov 19, 2017
  19. Ann T RopeaNov 19, 2017
  20. Eric SunshineNov 19, 2017
  21. Ann T RopeaNov 19, 2017
  22. Eric SunshineNov 19, 2017
  23. Ann T RopeaNov 19, 2017
  24. Junio C HamanoNov 20, 2017
  25. Philip OakleyNov 20, 2017
  26. Junio C HamanoNov 22, 2017
  27. Philip OakleyNov 22, 2017
  28. Junio C HamanoNov 24, 2017
  29. Ann T RopeaNov 24, 2017
  30. Ann T RopeaNov 24, 2017
  31. Ann T RopeaNov 24, 2017
  32. Ann T RopeaNov 24, 2017
  33. Ann T RopeaNov 24, 2017
  34. Ann T RopeaNov 24, 2017
  35. Junio C HamanoNov 25, 2017
  36. Junio C HamanoNov 26, 2017
  37. Junio C HamanoNov 26, 2017
  38. Junio C HamanoNov 26, 2017
  39. Ann T RopeaDec 3, 2017
  40. Ann T RopeaDec 3, 2017
  41. Ann T RopeaDec 3, 2017
  42. Ann T RopeaDec 3, 2017
  43. Ann T RopeaDec 3, 2017
  44. Junio C HamanoDec 4, 2017
  45. Ann T RopeaDec 4, 2017
  46. Junio C HamanoDec 5, 2017
  47. Ann T RopeaDec 6, 2017
  48. Junio C HamanoDec 6, 2017
  49. Ann T RopeaDec 6, 2017
  50. Ann T RopeaDec 3, 2017
  51. Ann T RopeaDec 3, 2017
  52. Junio C HamanoDec 4, 2017
  53. Ann T RopeaNov 19, 2017
  54. Junio C HamanoNov 20, 2017
  55. Ann T RopeaNov 13, 2017
  56. Ann T RopeaNov 13, 2017
  57. Ann T RopeaNov 13, 2017
  58. Junio C HamanoNov 14, 2017

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.