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

[TopGit PATCH] tg-patch: use pretty_tree

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
Oct 4, 2010, 20:09 UTC
Message-ID
<1286222981-28358-1-git-send-email-bert.wesarg@googlemail.com>
In-Reply-To
<1286216867-14701-1-git-send-email-bert.wesarg@googlemail.com>
This applies the same treatment to tg-patch like tg-files got in v2.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 tg-patch.sh |   56 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/tg-patch.sh b/tg-patch.sh
index 7bafdfe..0ebef7a 100644
--- a/tg-patch.sh
+++ b/tg-patch.sh
@@ -4,11 +4,8 @@
 # GPLv2
 
 name=
-
 topic=
-diff_opts=
-diff_committed_only=yes	# will be unset for index/worktree
-
+topic_for_pretty_tree=
 
 ## Parse options
 
@@ -16,12 +13,13 @@ while [ -n "$1" ]; do
 	arg="$1"; shift
 	case "$arg" in
 	-i)
+		[ -z "$topic" ] || die "-i and -w are mutually exclusive"
 		topic='(i)'
-		diff_opts="$diff_opts --cached";
-		diff_committed_only=;;
+		topic_for_pretty_tree=-i;;
 	-w)
+		[ -z "$topic" ] || die "-i and -w are mutually exclusive"
 		topic='(w)'
-		diff_committed_only=;;
+		topic_for_pretty_tree=-w;;
 	-*)
 		echo "Usage: tg [...] patch [-i | -w] [NAME]" >&2
 		exit 1;;
@@ -32,7 +30,7 @@ while [ -n "$1" ]; do
 done
 
 
-[ -n "$name"  -a  -z "$diff_committed_only" ]  &&
+[ -n "$name" -a -n "$topic" ] &&
 	die "-i/-w are mutually exclusive with NAME"
 
 [ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
@@ -46,22 +44,32 @@ base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)"
 
 setup_pager
 
-cat_file "$topic:.topmsg"
-echo
-[ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
-
-# Evil obnoxious hack to work around the lack of git diff --exclude
-git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)"
-git diff --name-only $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- |
-	fgrep -vx ".topdeps" |
-	fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
-if [ -s "$git_is_stupid" ]; then
-	cd "$root_dir"
-	cat "$git_is_stupid" | xargs git diff -a --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
-else
-	echo "No changes."
-fi
-rm "$git_is_stupid"
+# put out the commit message
+# and put an empty line out, if the last one in the message was not an empty line
+# and put out "---" if the commit message does not have one yet
+cat_file "$topic:.topmsg" |
+	awk '
+/^---/ {
+    has_3dash=1;
+}
+       {
+    need_empty = 1;
+    if ($0 == "")
+        need_empty = 0;
+    print;
+}
+END    {
+    if (need_empty)
+        print "";
+    if (!has_3dash)
+        print "---";
+}
+'
+
+b_tree=$(pretty_tree "$name" -b)
+t_tree=$(pretty_tree "$name" $topic_for_pretty_tree)
+
+git diff-tree -p --stat -r $b_tree $t_tree
 
 echo '-- '
 echo "tg: ($base_rev..) $name (depends on: $(cat_file "$topic:.topdeps" | paste -s -d' '))"
-- 
tg: (c9ca19b..) bw/tg-patch-pretty_tree (depends on: bw/files)
Previous: Bert WesargNext: Bert Wesarg
Message 20 of 39 in “planning a new topgit release”
  1. Uwe Kleine-KönigOct 3, 2010
  2. Bert WesargOct 3, 2010
  3. 1/6 Let tg-update take a branch parameterBert Wesarg, Oct 3, 2010
  4. 2/6 tg-remote: use default remote if non is givenBert Wesarg, Oct 3, 2010
  5. 3/6 tg-files: list files changed by the topic branchBert Wesarg, Oct 3, 2010
  6. 4/6 tg-prev/tg-next: commands to explore dependenciesBert Wesarg, Oct 3, 2010
  7. 5/6 put die() messages to stderrBert Wesarg, Oct 3, 2010
  8. 6/6 tg-log: short cut to git logBert Wesarg, Oct 3, 2010
  9. Uwe Kleine-KönigOct 3, 2010
  10. Bert WesargOct 4, 2010
  11. Uwe Kleine-KönigOct 3, 2010
  12. Bert WesargOct 4, 2010
  13. Uwe Kleine-KönigOct 4, 2010
  14. Bert WesargOct 4, 2010
  15. Uwe Kleine-KönigOct 4, 2010
  16. tg-files: list files changed by the topic branchBert Wesarg, Oct 4, 2010
  17. Uwe Kleine-KönigOct 4, 2010
  18. Bert WesargOct 4, 2010
  19. tg-files: list files changed by the topic branchBert Wesarg, Oct 4, 2010
  20. tg-patch: use pretty_treeBert Wesarg, Oct 4, 2010
  21. Bert WesargOct 4, 2010
  22. Uwe Kleine-KönigOct 5, 2010
  23. Bert WesargOct 5, 2010
  24. tg-patch: use pretty_treeBert Wesarg, Oct 5, 2010
  25. Uwe Kleine-KönigOct 5, 2010
  26. Bert WesargOct 5, 2010
  27. Uwe Kleine-KönigOct 5, 2010
  28. tg-files: list files changed by the topic branchBert Wesarg, Oct 5, 2010
  29. Štěpán NěmecOct 5, 2010
  30. Bert WesargOct 6, 2010
  31. Uwe Kleine-KönigOct 3, 2010
  32. Ævar Arnfjörð BjarmasonOct 4, 2010
  33. Uwe Kleine-KönigOct 4, 2010
  34. Uwe Kleine-KönigOct 3, 2010
  35. Bert WesargOct 4, 2010
  36. tg-log: move note from tg base to tg logBert Wesarg, Oct 4, 2010
  37. Štěpán NěmecOct 4, 2010
  38. Bert WesargOct 4, 2010
  39. Uwe Kleine-KönigOct 4, 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.