# [PATCH] git-svn: delay term initialization

3 messages from 2014-09-14 to 2014-09-15. Participants: Eric Wong, Junio C Hamano.
Thread: https://gitlist.dev/t/37558

## Eric Wong, 2014-09-14 08:04

Subject: [PATCH] git-svn: delay term initialization
Message-ID: <1410681849-3107-1-git-send-email-normalperson@yhbt.net>
URL: https://gitlist.dev/e/1410681849-3107-1-git-send-email-normalperson%40yhbt.net

```
On my Debian 7 system, this gives annoying warnings when the output
of "git svn" commands are redirected:

    Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work.
    The COLUMNS and LINES environment variables didn't work. The
    resize program didn't work.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 Also, manually tested to ensure dcommit --interactive works.

 git-svn.perl | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 40565cd..ce0d7e1 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -306,13 +306,16 @@ sub readline {
 }
 package main;
 
-my $term = eval {
-	$ENV{"GIT_SVN_NOTTY"}
-		? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
-		: new Term::ReadLine 'git-svn';
-};
-if ($@) {
-	$term = new FakeTerm "$@: going non-interactive";
+my $term;
+sub term_init {
+	$term = eval {
+		$ENV{"GIT_SVN_NOTTY"}
+			? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
+			: new Term::ReadLine 'git-svn';
+	};
+	if ($@) {
+		$term = new FakeTerm "$@: going non-interactive";
+	}
 }
 
 my $cmd;
@@ -424,6 +427,7 @@ sub ask {
 	my $default = $arg{default};
 	my $resp;
 	my $i = 0;
+	term_init() unless $term;
 
 	if ( !( defined($term->IN)
             && defined( fileno($term->IN) )
-- 
EW

```

## Eric Wong, 2014-09-14 08:07

Subject: Re: [PATCH] git-svn: delay term initialization
Message-ID: <20140914080730.GA6089@dcvr.yhbt.net>
URL: https://gitlist.dev/e/20140914080730.GA6089%40dcvr.yhbt.net
In-Reply-To: <1410681849-3107-1-git-send-email-normalperson@yhbt.net>

```
Eric Wong <normalperson@yhbt.net> wrote:
> On my Debian 7 system, this gives annoying warnings when the output

s/gives/fixes/

```

## Junio C Hamano, 2014-09-15 18:00

Subject: Re: [PATCH] git-svn: delay term initialization
Message-ID: <xmqqbnqg932f.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqbnqg932f.fsf%40gitster.dls.corp.google.com
In-Reply-To: <1410681849-3107-1-git-send-email-normalperson@yhbt.net>

```
Eric Wong <normalperson@yhbt.net> writes:

> On my Debian 7 system, this gives annoying warnings when the output
> of "git svn" commands are redirected:
>
>     Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work.
>     The COLUMNS and LINES environment variables didn't work. The
>     resize program didn't work.
>
> Signed-off-by: Eric Wong <normalperson@yhbt.net>
> ---
>  Also, manually tested to ensure dcommit --interactive works.

Makes sense.

>
>  git-svn.perl | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/git-svn.perl b/git-svn.perl
> index 40565cd..ce0d7e1 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -306,13 +306,16 @@ sub readline {
>  }
>  package main;
>  
> -my $term = eval {
> -	$ENV{"GIT_SVN_NOTTY"}
> -		? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
> -		: new Term::ReadLine 'git-svn';
> -};
> -if ($@) {
> -	$term = new FakeTerm "$@: going non-interactive";
> +my $term;
> +sub term_init {
> +	$term = eval {
> +		$ENV{"GIT_SVN_NOTTY"}
> +			? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
> +			: new Term::ReadLine 'git-svn';
> +	};
> +	if ($@) {
> +		$term = new FakeTerm "$@: going non-interactive";
> +	}
>  }
>  
>  my $cmd;
> @@ -424,6 +427,7 @@ sub ask {
>  	my $default = $arg{default};
>  	my $resp;
>  	my $i = 0;
> +	term_init() unless $term;
>  
>  	if ( !( defined($term->IN)
>              && defined( fileno($term->IN) )

```
