threads / patch / 17405

v2, 2 partsgit-am: minor cleanups

Subject: [PATCH v2 2/2] git-am: minor cleanups

## tl;dr

8 messages between Jan 28, 2009 and Jan 28, 2009. Diffs are folded; open one to read it.

replies: 7people: 3as markdown or json

Jay Soffian· Jan 28, 2009, 03:27 UTC · lore

[PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin

When git am is called w/o arguments, w/o a patch on stdin and the user hits ctrl-c, it leaves behind a partially populated $dotest directory. After this commit, it emits usage when called w/o arguments and w/o a patch on stdin.

Also ensure that $dotest is cleaned up if user manages to interupt mailsplit while it is processing input, but not if mailsplit exits non-zero due to error.

Noticed by Sverre Rabbelier
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
Change from v1: don't remove $dotest if mailsplit exits non-zero
 git-am.sh |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
Show changes to git-am.sh +5 −2
diff --git a/git-am.sh b/git-am.sh
index b1c05c9..65285a0 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -254,10 +254,13 @@ else
 		done
 		shift
 	fi
-	git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" ||  {
-		rm -fr "$dotest"
+	test $# = 0 && test -t 0 && usage
+	trap 'rm -fr "$dotest"' 0
+	git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
+		trap - 0
 		exit 1
 	}
+	trap - 0
 
 	# -s, -u, -k, --whitespace, -3, -C and -p flags are kept
 	# for the resuming session after a patch failure.
-- 
1.6.1.224.gb56c
Jay Soffian· Jan 28, 2009, 03:27 UTC · re: Jay Soffian · lore

Update usage statement to remove a no-longer supported option, and to hide two options (one a no-op, one internal) unless --help-all is used.

Use "test -t 0" instead of deprecated "tty -s" to detect when stdin is a terminal. (test -t 0 is used elsewhere in git-am and in other git shell scripts, tty -s is not.)

Use "test ..." instead of "[ ... ]" and "die <msg>" instead of "echo <msg>
>&2; exit 1" to be consistent with rest of script.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
Added SoB, otherwise no change from v1.
 git-am.sh |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
Show changes to git-am.sh +4 −8
diff --git a/git-am.sh b/git-am.sh
index 65285a0..9653a98 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -8,9 +8,8 @@ OPTIONS_SPEC="\
 git am [options] [<mbox>|<Maildir>...]
 git am [options] (--resolved | --skip | --abort)
 --
-d,dotest=       (removed -- do not use)
 i,interactive   run interactively
-b,binary        (historical option -- no-op)
+b,binary*       (historical option -- no-op)
 3,3way          allow fall back on 3way merging if needed
 s,signoff       add a Signed-off-by line to the commit message
 u,utf8          recode into utf8 (default)
@@ -24,7 +23,7 @@ resolvemsg=     override error message when patch failure occurs
 r,resolved      to be used after a patch failure
 skip            skip the current patch
 abort           restore the original branch and abort the patching operation.
-rebasing        (internal use for git-rebase)"
+rebasing*       (internal use for git-rebase)"
 
 . git-sh-setup
 prefix=$(git rev-parse --show-prefix)
@@ -204,7 +203,7 @@ then
 		# unreliable -- stdin could be /dev/null for example
 		# and the caller did not intend to feed us a patch but
 		# wanted to continue unattended.
-		tty -s
+		test -t 0
 		;;
 	*)
 		false
@@ -283,10 +282,7 @@ fi
 case "$resolved" in
 '')
 	files=$(git diff-index --cached --name-only HEAD --) || exit
-	if [ "$files" ]; then
-	   echo "Dirty index: cannot apply patches (dirty: $files)" >&2
-	   exit 1
-	fi
+	test "$files" && die "Dirty index: cannot apply patches (dirty: $files)"
 esac
 
 if test "$(cat "$dotest/utf8")" = t
-- 
1.6.1.224.gb56c
Junio C Hamano· Jan 28, 2009, 04:18 UTC · re: Jay Soffian · lore

Re: [PATCH v2 2/2] git-am: minor cleanups

Jay Soffian <jaysoffian@gmail.com> writes:
> Use "test -t 0" instead of deprecated "tty -s" to detect when stdin is a
> terminal.
Who deprecated it?
Other changes looked sensible, though.
Jay Soffian· Jan 28, 2009, 14:26 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 2/2] git-am: minor cleanups

On Tue, Jan 27, 2009 at 11:18 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
> Jay Soffian <jaysoffian@gmail.com> writes:
>
>> Use "test -t 0" instead of deprecated "tty -s" to detect when stdin is a
>> terminal.
>
> Who deprecated it?

I believe it's IEEE Std 1003.2-1992 / POSIX.2. I found the initial reference in the BSD/OS X man page[1], but google also found me other references [2,3]. Also, elsewhere git uses "test -t 0", not "tty -s".

[1] http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man1/tty.1.html
    (The -s option is deprecated in favor of the ``test -t 0'' command.)
[2] http://docs.sun.com/app/docs/doc/816-5165/tty-1?a=view
    (Portable applications should use test -t.)
[3] http://opengroup.org/onlinepubs/007908799/xcu/tty.html
    (Portable applications should use test -t 0.)
j.
Junio C Hamano· Jan 28, 2009, 04:17 UTC · re: Jay Soffian · lore

Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin

Jay Soffian <jaysoffian@gmail.com> writes:
> +	test $# = 0 && test -t 0 && usage
Sorry to be dense.  Why isn't your patch the above single liner?
Sverre Rabbelier· Jan 28, 2009, 10:32 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin

Heya,
On Wed, Jan 28, 2009 at 05:17, Junio C Hamano <gitster@pobox.com> wrote:
> Jay Soffian <jaysoffian@gmail.com> writes:
>> +     test $# = 0 && test -t 0 && usage
Awesome! Thanks for looking into this :).
> Sorry to be dense.  Why isn't your patch the above single liner?
I hope you two work this out soon so it gets into maint.
-- 
Cheers,

Sverre Rabbelier
Jay Soffian· Jan 28, 2009, 14:28 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin

On Tue, Jan 27, 2009 at 11:17 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
> Jay Soffian <jaysoffian@gmail.com> writes:
>
>> +     test $# = 0 && test -t 0 && usage
>
> Sorry to be dense.  Why isn't your patch the above single liner?
>

"Also ensure that $dotest is cleaned up if user manages to interupt mailsplit while it is processing input, but not if mailsplit exits non-zero due to error."

j.
Junio C Hamano· Jan 28, 2009, 18:10 UTC · re: Jay Soffian · lore

Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin

Jay Soffian <jaysoffian@gmail.com> writes:
Show 11 quoted lines
> On Tue, Jan 27, 2009 at 11:17 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Jay Soffian <jaysoffian@gmail.com> writes:
>>
>>> +     test $# = 0 && test -t 0 && usage
>>
>> Sorry to be dense.  Why isn't your patch the above single liner?
>>
>
> "Also ensure that $dotest is cleaned up if user manages to interupt mailsplit
> while it is processing input, but not if mailsplit exits non-zero due to
> error."

My point was why "Also" needs to be in the same commit. Aren't they separate issues?

← back to recent threads