git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Charles Bailey <charles@hashpling.org>
Cc: "David Aguilar" <davvid@gmail.com>,
	git@vger.kernel.org, "Thomas Rast" <trast@student.ethz.ch>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Magnus Bäck" <magnus.back@sonyericsson.com>,
	"Avery Pennarun" <apenwarr@gmail.com>
Subject: Re: [PATCH] mergetool: Remove explicit references to /dev/tty
Date: Fri, 20 Aug 2010 07:27:25 -0500	[thread overview]
Message-ID: <20100820122724.GS10407@burratino> (raw)
In-Reply-To: <1282303049-11201-1-git-send-email-charles@hashpling.org>

Charles Bailey wrote:

> mergetool used /dev/tty to switch back to receiving input from the user
> via inside a block with a redirected stdin.
> 
> This harms testability, so change mergetool to save its original stdin
> to an alternative fd in this block and restore it for those sub-commands
> that need the original stdin.

Sounds good.

> +++ b/git-mergetool--lib.sh
> @@ -35,7 +35,7 @@ check_unchanged () {
>  		while true; do
>  			echo "$MERGED seems unchanged."
>  			printf "Was the merge successful? [y/n] "
> -			read answer < /dev/tty
> +			read answer

Part of the run_merge_tool codepath.  The only place this is called
with TOOL_MODE=merge is by merge_file which has stdin redirected,
so this should be safe.  Good.

> +++ b/git-mergetool.sh
> @@ -292,14 +292,15 @@ if test $# -eq 0 ; then
>      printf "Merging:\n"
>      printf "$files\n"
>  
> -    files_to_merge |
> +    # Save original stdin to fd 3
> +    files_to_merge 3<&0 |

I would think this should work, but it doesn't feel idiomatic.  Why
not save stdin a little earlier, so the reader does not have to track
down whether it has been redirected?

The test quietly passes for me with dash but fails with ksh:

 /home/jrn/src/git4/git-mergetool: line 303: 3: cannot open [Bad file descriptor]

With the patch below on top, it passes with dash and ksh.
---
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 84edf7d..2e82522 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -275,10 +275,13 @@ files_to_merge() {
     fi
 }
 
 
 if test $# -eq 0 ; then
     cd_to_toplevel
 
+    # Save original stdin
+    exec 3<&0
+
     if test -e "$GIT_DIR/MERGE_RR"
     then
 	rerere=true
@@ -292,8 +294,7 @@ if test $# -eq 0 ; then
     printf "Merging:\n"
     printf "$files\n"
 
-    # Save original stdin to fd 3
-    files_to_merge 3<&0 |
+    files_to_merge |
     while IFS= read i
     do
 	if test $last_status -ne 0; then
-- 

  reply	other threads:[~2010-08-20 12:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-12 21:28 Status of conflicted files resolved with rerere Magnus Bäck
2010-08-12 21:36 ` Avery Pennarun
2010-08-13 17:19   ` Jay Soffian
2010-08-15  2:24   ` David Aguilar
2010-08-15  6:59     ` Junio C Hamano
2010-08-15 16:00       ` Magnus Bäck
2010-08-17  9:22       ` [PATCH] mergetool: Skip autoresolved paths David Aguilar
2010-08-19 10:02         ` Thomas Rast
2010-08-20  3:52           ` David Aguilar
2010-08-20  9:57             ` Charles Bailey
2010-08-20 10:09               ` Jonathan Nieder
2010-08-20 11:17             ` [PATCH] mergetool: Remove explicit references to /dev/tty Charles Bailey
2010-08-20 12:27               ` Jonathan Nieder [this message]
2010-08-20 13:50                 ` Charles Bailey
2010-08-20 14:19                   ` Jonathan Nieder
2010-08-20 15:25                 ` [PATCH v2] " Charles Bailey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100820122724.GS10407@burratino \
    --to=jrnieder@gmail.com \
    --cc=apenwarr@gmail.com \
    --cc=charles@hashpling.org \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=magnus.back@sonyericsson.com \
    --cc=trast@student.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).