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

[PATCH v5 0/5] Better ref summary alignment in "git fetch"

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jul 1, 2016, 16:03 UTC
Message-ID
<20160701160331.29252-1-pclouds@gmail.com>
In-Reply-To
<20160626055810.26960-1-pclouds@gmail.com>

v5 changes the substitute symbol from '$' to '*' in compact mode and makes sure long lines in compact mode will not make the remote ref column too big (it's far from perfect but I think it's still good to do).

I'm not sure if we should bring back "{ -> origin/}foo" format. I can do it if someone still wants it.

Interdiff
diff --git a/Documentation/git-fetch.txt b/Documentation/git-fetch.txt
index 61e8885..9e42169 100644
--- a/Documentation/git-fetch.txt
+++ b/Documentation/git-fetch.txt
@@ -116,10 +116,10 @@ representing the status of a single ref. Each line is of the form:
 The status of up-to-date refs is shown only if the --verbose option is
 used.
 
-In compact output mode, if either entire `<from>` or `<to>` is found
-in the other string, it will be substituted with `$` in the other
-string. or example, `master -> origin/master` becomes
-`master -> origin/$`.
+In compact output mode, specified with configuration variable
+fetch.output, if either entire `<from>` or `<to>` is found in the
+other string, it will be substituted with `*` in the other string. For
+example, `master -> origin/master` becomes `master -> origin/*`.
 
 flag::
 	A single character indicating the status of the ref:
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 9d9f4e8..0a2eed1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -455,7 +455,7 @@ static int compact_format;
 
 static void adjust_refcol_width(const struct ref *ref)
 {
-	int max, rlen, llen;
+	int max, rlen, llen, len;
 
 	/* uptodate lines are only shown on high verbosity level */
 	if (!verbosity && !oidcmp(&ref->peer_ref->old_oid, &ref->old_oid))
@@ -464,16 +464,6 @@ static void adjust_refcol_width(const struct ref *ref)
 	max    = term_columns();
 	rlen   = utf8_strwidth(prettify_refname(ref->name));
 
-	if (compact_format) {
-		/*
-		 * Not precise calculation because '$' can appear in
-		 * ref->name and reduce actual length.
-		 */
-		if (refcol_width < rlen)
-			refcol_width = rlen;
-		return;
-	}
-
 	llen   = utf8_strwidth(prettify_refname(ref->peer_ref->name));
 
 	/*
@@ -482,9 +472,19 @@ static void adjust_refcol_width(const struct ref *ref)
 	 * anyway because we don't know if the error explanation part
 	 * will be printed in update_local_ref)
 	 */
-	if (21 /* flag and summary */ + rlen + 4 /* -> */ + llen >= max)
+	if (compact_format) {
+		llen = 0;
+		max = max * 2 / 3;
+	}
+	len = 21 /* flag and summary */ + rlen + 4 /* -> */ + llen;
+	if (len >= max)
 		return;
 
+	/*
+	 * Not precise calculation for compact mode because '*' can
+	 * appear on the left hand side of '->' and shrink the column
+	 * back.
+	 */
 	if (refcol_width < rlen)
 		refcol_width = rlen;
 }
@@ -519,7 +519,9 @@ static void print_remote_to_local(struct strbuf *display,
 	strbuf_addf(display, "%-*s -> %s", refcol_width, remote, local);
 }
 
-static int dollarize(struct strbuf *haystack, const char *needle)
+static int find_and_replace(struct strbuf *haystack,
+			    const char *needle,
+			    const char *placeholder)
 {
 	const char *p = strstr(haystack->buf, needle);
 	int plen, nlen;
@@ -535,7 +537,8 @@ static int dollarize(struct strbuf *haystack, const char *needle)
 	if (plen > nlen && p[nlen] != '/')
 		return 0;
 
-	strbuf_splice(haystack, p - haystack->buf, nlen, "$", 1);
+	strbuf_splice(haystack, p - haystack->buf, nlen,
+		      placeholder, strlen(placeholder));
 	return 1;
 }
 
@@ -546,15 +549,15 @@ static void print_compact(struct strbuf *display,
 	struct strbuf l = STRBUF_INIT;
 
 	if (!strcmp(remote, local)) {
-		strbuf_addf(display, "%-*s -> $", refcol_width, remote);
+		strbuf_addf(display, "%-*s -> *", refcol_width, remote);
 		return;
 	}
 
 	strbuf_addstr(&r, remote);
 	strbuf_addstr(&l, local);
 
-	if (!dollarize(&r, local))
-		dollarize(&l, remote);
+	if (!find_and_replace(&r, local, "*"))
+		find_and_replace(&l, remote, "*");
 	print_remote_to_local(display, r.buf, l.buf);
 
 	strbuf_release(&r);
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 3a92718..6032776 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -712,8 +712,8 @@ test_expect_success 'fetch compact output' '
 			grep -e "->" | cut -c 22- >../actual
 	) &&
 	cat >expect <<-\EOF &&
-	master     -> origin/$
-	extraaa    -> $
+	master     -> origin/*
+	extraaa    -> *
 	EOF
 	test_cmp expect actual
 '

Nguyễn Thái Ngọc Duy (5):
  git-fetch.txt: document fetch output
  fetch: refactor ref update status formatting code
  fetch: change flag code for displaying tag update and deleted ref
  fetch: align all "remote -> local" output
  fetch: reduce duplicate in ref update status lines with placeholder

 Documentation/config.txt    |   5 ++
 Documentation/git-fetch.txt |  51 ++++++++++++
 builtin/fetch.c             | 197 +++++++++++++++++++++++++++++++++++---------
 t/t5510-fetch.sh            |  30 +++++++
 4 files changed, 243 insertions(+), 40 deletions(-)
-- 
2.8.2.531.gd073806
Previous: Jeff KingNext: Nguyễn Thái Ngọc Duy
Message 62 of 71 in “Better ref summary alignment in "git fetch"”
  1. 0/2 Better ref summary alignment in "git fetch"Nguyễn Thái Ngọc Duy, May 22, 2016
  2. 1/2 fetch: better alignment in ref summaryNguyễn Thái Ngọc Duy, May 22, 2016
  3. Junio C HamanoMay 23, 2016
  4. Duy NguyenMay 23, 2016
  5. Marc BranchaudMay 26, 2016
  6. Jeff KingMay 26, 2016
  7. Junio C HamanoMay 26, 2016
  8. Marc BranchaudMay 26, 2016
  9. Junio C HamanoMay 26, 2016
  10. Marc BranchaudMay 26, 2016
  11. Jeff KingMay 26, 2016
  12. Duy NguyenJun 2, 2016
  13. Junio C HamanoJun 2, 2016
  14. 2/2 fetch: reduce ref column size when there are enough short ref namesNguyễn Thái Ngọc Duy, May 22, 2016
  15. 0/3 Better ref summary alignment in "git fetch"Nguyễn Thái Ngọc Duy, Jun 3, 2016
  16. 1/3 git-fetch.txt: document fetch outputNguyễn Thái Ngọc Duy, Jun 3, 2016
  17. Marc BranchaudJun 3, 2016
  18. Jeff KingJun 3, 2016
  19. 2/3 fetch: refactor ref update status formatting codeNguyễn Thái Ngọc Duy, Jun 3, 2016
  20. Junio C HamanoJun 3, 2016
  21. 3/3 fetch: reduce duplicate in ref update status linesNguyễn Thái Ngọc Duy, Jun 3, 2016
  22. Marc BranchaudJun 3, 2016
  23. Junio C HamanoJun 3, 2016
  24. Marc BranchaudJun 3, 2016
  25. Junio C HamanoJun 3, 2016
  26. Duy NguyenJun 4, 2016
  27. Duy NguyenJun 4, 2016
  28. Junio C HamanoJun 4, 2016
  29. Duy NguyenJun 5, 2016
  30. Junio C HamanoJun 3, 2016
  31. Duy NguyenJun 3, 2016
  32. Jeff KingJun 3, 2016
  33. Duy NguyenJun 3, 2016
  34. Junio C HamanoJun 4, 2016
  35. Jeff KingJun 3, 2016
  36. Junio C HamanoJun 3, 2016
  37. 0/6 Better ref summary alignment in "git fetch"Nguyễn Thái Ngọc Duy, Jun 5, 2016
  38. 1/6 git-fetch.txt: document fetch outputNguyễn Thái Ngọc Duy, Jun 5, 2016
  39. Marc BranchaudJun 6, 2016
  40. 2/6 fetch: refactor ref update status formatting codeNguyễn Thái Ngọc Duy, Jun 5, 2016
  41. 3/6 fetch: change flag code for displaying tag update and deleted refNguyễn Thái Ngọc Duy, Jun 5, 2016
  42. 4/6 fetch: align all "remote -> local" outputNguyễn Thái Ngọc Duy, Jun 5, 2016
  43. 5/6 fetch: reduce duplicate in ref update status lines with { -> }Nguyễn Thái Ngọc Duy, Jun 5, 2016
  44. 6/6 fetch: reduce duplicate in ref update status lines with placeholderNguyễn Thái Ngọc Duy, Jun 5, 2016
  45. 0/5 Better ref summary alignment in "git fetch"Nguyễn Thái Ngọc Duy, Jun 26, 2016
  46. 1/5 git-fetch.txt: document fetch outputNguyễn Thái Ngọc Duy, Jun 26, 2016
  47. Jakub NarębskiJul 4, 2016
  48. Duy NguyenJul 4, 2016
  49. Jakub NarębskiJul 4, 2016
  50. Duy NguyenJul 4, 2016
  51. 2/5 fetch: refactor ref update status formatting codeNguyễn Thái Ngọc Duy, Jun 26, 2016
  52. 3/5 fetch: change flag code for displaying tag update and deleted refNguyễn Thái Ngọc Duy, Jun 26, 2016
  53. 4/5 fetch: align all "remote -> local" outputNguyễn Thái Ngọc Duy, Jun 26, 2016
  54. 5/5 fetch: reduce duplicate in ref update status lines with placeholderNguyễn Thái Ngọc Duy, Jun 26, 2016
  55. Eric SunshineJun 27, 2016
  56. Duy NguyenJun 27, 2016
  57. Junio C HamanoJun 27, 2016
  58. Jeff KingJun 27, 2016
  59. Duy NguyenJun 27, 2016
  60. Duy NguyenJun 30, 2016
  61. Jeff KingJul 1, 2016
  62. 0/5 Better ref summary alignment in "git fetch"Nguyễn Thái Ngọc Duy, Jul 1, 2016
  63. 1/5 git-fetch.txt: document fetch outputNguyễn Thái Ngọc Duy, Jul 1, 2016
  64. 2/5 fetch: refactor ref update status formatting codeNguyễn Thái Ngọc Duy, Jul 1, 2016
  65. 5/5 fetch: reduce duplicate in ref update status lines with placeholderNguyễn Thái Ngọc Duy, Jul 1, 2016
  66. 3/5 fetch: change flag code for displaying tag update and deleted refNguyễn Thái Ngọc Duy, Jul 1, 2016
  67. 4/5 fetch: align all "remote -> local" outputNguyễn Thái Ngọc Duy, Jul 1, 2016
  68. Junio C HamanoJul 1, 2016
  69. Duy NguyenJul 2, 2016
  70. Marc BranchaudJul 4, 2016
  71. Duy NguyenJul 4, 2016

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.