On Tue, Oct 05, 2010 at 09:04:46PM +0200, Bert Wesarg wrote: > This applies the same treatment to tg-patch like tg-files got in v2. > > Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx> > > --- > > Basing the decision whether to use the ui diff or the porcelain diff-tree > is probably very unorthodox, but also makes sense, doesn't it? Uuuuuh, I'd feel better with git diff-tree --color=auto. Why did you decide against that? > Changes: > v2: > * apply suggestions from Uwe made to tg-files here too > * the running pager decides whether we use the ui diff or the porcelain > diff-tree > > tg-patch.sh | 67 +++++++++++++++++++++++++++++++++------------------------- > 1 files changed, 38 insertions(+), 29 deletions(-) > > diff --git a/tg-patch.sh b/tg-patch.sh > index 7bafdfe..e88985a 100644 tg-patch.sh > --- a/tg-patch.sh > +++ b/tg-patch.sh > @@ -4,24 +4,18 @@ > # GPLv2 > > name= > - > topic= > -diff_opts= > -diff_committed_only=yes # will be unset for index/worktree > - > +topic_for_pretty_tree= > > ## Parse options > > while [ -n "$1" ]; do > arg="$1"; shift > case "$arg" in > - -i) > - topic='(i)' > - diff_opts="$diff_opts --cached"; > - diff_committed_only=;; > - -w) > - topic='(w)' > - diff_committed_only=;; > + -i|-w) > + [ -z "$topic" ] || die "-i and -w are mutually exclusive" > + topic="(${arg#-})" > + topic_for_pretty_tree="$arg";; > -*) > echo "Usage: tg [...] patch [-i | -w] [NAME]" >&2 > exit 1;; > @@ -32,8 +26,8 @@ while [ -n "$1" ]; do > done > > > -[ -n "$name" -a -z "$diff_committed_only" ] && > - die "-i/-w are mutually exclusive with NAME" > +[ -n "$name" -a -n "$topic" ] && > + die "$topic are mutually exclusive with NAME" > > [ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')" > base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" || > @@ -46,22 +40,37 @@ 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) > + > +# use the ui diff command when the pager is active > +diff_command=diff > +[ "x$GIT_PAGER_IN_USE" = "x1" ] || > + diff_command=diff-tree > + > +git $diff_command -p --stat $b_tree $t_tree > > echo '-- ' > echo "tg: ($base_rev..) $name (depends on: $(cat_file "$topic:.topdeps" | paste -s -d' '))" > -- > tg: (aaf1181..) bw/tg-patch-pretty_tree (depends on: bw/files) > -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | -- 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