I split the patch up into three patches: Always print a new line after failed commands. Pass a fake terminal to subcommands when mr is run in a terminal Make quiet mode show output if there is some. Closes: #694031
This latest attached patchset also fixes the behaviour with mr -j4 -q, which is useful when running mr status and you have a fast disk. Please apply at least the first two patches, I understand if you don't want to change the meaning of the -q option though. I definitely want a way to make mr status only print something when there is output from the VCS commands, please let me know how you would like this to work so that I can adapt the current patch to it. -- bye, pabs http://wiki.debian.org/PaulWise
From 40054f9d277a191558fe0fcd06ff1c98cb7e9636 Mon Sep 17 00:00:00 2001 From: Paul Wise <[email protected]> Date: Wed, 20 Feb 2013 11:25:55 +0800 Subject: [PATCH 1/3] Always print a new line after failed commands. --- mr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mr b/mr index 7f147cc..691bc52 100755 --- a/mr +++ b/mr @@ -978,7 +978,7 @@ sub record { system((getpwuid($<))[8], "-i"); } push @failed, $dir; - print "\n" unless $quiet; + print "\n"; } elsif ($ret == SKIPPED) { push @skipped, $dir; -- 1.8.2.rc0
From 607ed9ac709e4541053a0f977cbcfe3f1cd4d8c2 Mon Sep 17 00:00:00 2001 From: Paul Wise <[email protected]> Date: Wed, 20 Feb 2013 12:03:38 +0800 Subject: [PATCH 2/3] Pass a fake terminal to subcommands when mr is run in a terminal --- debian/changelog | 6 ++++++ debian/control | 2 +- mr | 47 ++++++++++++++++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6f318e2..accd7f1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +mr (1.15) unstable; urgency=low + + * Pass a fake terminal to subcommands when mr is run in a terminal + + -- Paul Wise <[email protected]> Thu, 14 Feb 2013 14:54:00 +0800 + mr (1.14) unstable; urgency=low * Added a fetch command. Closes: #480580 diff --git a/debian/control b/debian/control index 7189dc4..2700380 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,7 @@ Architecture: all Section: vcs Depends: ${misc:Depends} Suggests: subversion, git-core | git (>= 1:1.7), cvs, bzr, mercurial, darcs, fossil, vcsh, liburi-perl, curl -Recommends: libwww-perl, libhtml-parser-perl, perl +Recommends: libwww-perl, libio-pty-easy-perl, libhtml-parser-perl, perl Description: Multiple Repository management tool The mr(1) command can checkout, update, or perform other actions on a set of repositories as if they were one combined respository. It diff --git a/mr b/mr index 691bc52..38d964c 100755 --- a/mr +++ b/mr @@ -549,6 +549,7 @@ my $no_chdir=0; my $jobs=1; my $trust_all=0; my $directory=getcwd(); +my $terminal=-t STDOUT && eval{use IO::Pty::Easy;1;} eq 1; my $HOME_MR_CONFIG = "$ENV{HOME}/.mrconfig"; $ENV{MR_CONFIG}=find_mrconfig(); @@ -692,6 +693,33 @@ sub fulldir { return $subdir =~ /^\// ? $subdir : $topdir.$subdir; } +sub terminal_friendly_spawn { + my $actionmsg = shift; + my $sh = shift; + my $quiet = shift; + my $output = ""; + if ($terminal) { + my $pty = IO::Pty::Easy->new; + $pty->spawn($sh); + while ($pty->is_active) { + my $data = $pty->read(); + $output .= $data if defined $data; + } + $pty->close; + } else { + $output = qx/$sh 2>&1/; + } + my $ret = $?; + if ($ret != 0) { + print "$actionmsg\n" if $actionmsg; + print STDERR $output; + } elsif (!$quiet && $output) { + print "$actionmsg\n" if $actionmsg; + print $output; + } + return $ret; +} + sub action { my ($action, $dir, $topdir, $subdir, $force_checkout) = @_; my $fulldir=fulldir($topdir, $subdir); @@ -793,14 +821,8 @@ sub action { my $ret=runsh $action, $topdir, $subdir, $command, \@ARGV, sub { my $sh=shift; - if ($quiet) { - my $output = qx/$sh 2>&1/; - my $ret = $?; - if ($ret != 0) { - print "$actionmsg\n"; - print STDERR $output; - } - return $ret; + if (!$jobs || $jobs > 1 || $quiet) { + return terminal_friendly_spawn($actionmsg, $sh, $quiet); } else { system($sh); @@ -864,13 +886,8 @@ sub hook { return OK unless defined $command; my $ret=runsh $hook, $topdir, $subdir, $command, [], sub { my $sh=shift; - if ($quiet) { - my $output = qx/$sh 2>&1/; - my $ret = $?; - if ($ret != 0) { - print STDERR $output; - } - return $ret; + if (!$jobs || $jobs > 1 || $quiet) { + return terminal_friendly_spawn(undef, $sh, $quiet); } else { system($sh); -- 1.8.2.rc0
From 68a0f8198be01317edcaf7c278e752f356e981ef Mon Sep 17 00:00:00 2001 From: Paul Wise <[email protected]> Date: Wed, 20 Feb 2013 12:06:42 +0800 Subject: [PATCH 3/3] Make quiet mode show output if there is some. Closes: #694031 --- debian/changelog | 1 + mr | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/debian/changelog b/debian/changelog index accd7f1..54b9516 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ mr (1.15) unstable; urgency=low + * Make quiet mode show output if there is some. Closes: #694031 * Pass a fake terminal to subcommands when mr is run in a terminal -- Paul Wise <[email protected]> Thu, 14 Feb 2013 14:54:00 +0800 diff --git a/mr b/mr index 38d964c..3bb800d 100755 --- a/mr +++ b/mr @@ -240,9 +240,8 @@ Be verbose. =item --quiet -Be quiet. This suppresses mr's usual output, as well as any output from -commands that are run (including stderr output). If a command fails, -the output will be shown. +Be quiet. This suppresses mr's usual output. If a command fails or there is any +output then the usual output will be shown. =item -k @@ -713,11 +712,11 @@ sub terminal_friendly_spawn { if ($ret != 0) { print "$actionmsg\n" if $actionmsg; print STDERR $output; - } elsif (!$quiet && $output) { + } elsif ($output) { print "$actionmsg\n" if $actionmsg; print $output; } - return $ret; + return ($ret, $output ? 1 : 0); } sub action { @@ -818,7 +817,7 @@ sub action { my $hookret=hook("pre_$action", $topdir, $subdir); return $hookret if $hookret != OK; - my $ret=runsh $action, $topdir, $subdir, + my ($ret, $out)=runsh $action, $topdir, $subdir, $command, \@ARGV, sub { my $sh=shift; if (!$jobs || $jobs > 1 || $quiet) { @@ -860,7 +859,7 @@ sub action { return FAILED; } - my $ret=hook("post_$action", $topdir, $subdir); + my ($ret, $hook_out)=hook("post_$action", $topdir, $subdir); return $ret if $ret != OK; if ($is_checkout || $is_update) { @@ -874,7 +873,7 @@ sub action { return $ret if $ret != OK; } - return OK; + return (OK, $out || $hook_out); } } } @@ -884,7 +883,7 @@ sub hook { my $command=$config{$topdir}{$subdir}{$hook}; return OK unless defined $command; - my $ret=runsh $hook, $topdir, $subdir, $command, [], sub { + my ($ret,$out)=runsh $hook, $topdir, $subdir, $command, [], sub { my $sh=shift; if (!$jobs || $jobs > 1 || $quiet) { return terminal_friendly_spawn(undef, $sh, $quiet); @@ -907,7 +906,7 @@ sub hook { } } - return OK; + return (OK, $out); } # run actions on multiple repos, in parallel @@ -935,7 +934,7 @@ sub mrs { close CHILD_STDERR; close $outfh; close $errfh; - exit action($action, @$repo); + exit +(action($action, @$repo))[0]; } close CHILD_STDOUT; close CHILD_STDERR; @@ -966,7 +965,7 @@ sub mrs { waitpid($active[$i][0], 0); print STDOUT $out[$i][0]; print STDERR $out[$i][1]; - record($active[$i][1], $? >> 8); + record($active[$i][1], $? >> 8, $out[$i][0] || $out[$i][1]); splice(@fhs, $i, 1); splice(@active, $i, 1); splice(@out, $i, 1); @@ -983,10 +982,11 @@ sub mrs { sub record { my $dir=shift()->[0]; my $ret=shift; + my $out=shift; if ($ret == OK) { push @ok, $dir; - print "\n" unless $quiet; + print "\n" unless $quiet && !$out; } elsif ($ret == FAILED) { if ($interactive) { -- 1.8.2.rc0
signature.asc
Description: This is a digitally signed message part

