Control: tags -1 patch On Sat, 2013-02-02 at 13:22 +0800, Paul Wise wrote:
> There is a missing "\n" after each command output. Solved that in the attached patch. > Not sure if the hook running thing should use it. The current code prints hook output in non-quiet mode so I think that my patch should also print hook output in quiet mode, implemented that. -- bye, pabs http://wiki.debian.org/PaulWise
From 31f39bd0f2b41b763fe2c27e6c0441e9e7d711cd Mon Sep 17 00:00:00 2001 From: Paul Wise <p...@debian.org> Date: Sat, 2 Feb 2013 13:41:58 +0800 Subject: [PATCH 2/2] Make quiet mode show output if there is some. Closes: #694031 --- debian/changelog | 4 ++++ debian/control | 2 +- mr | 57 ++++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1c93976..80e813a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,13 @@ mr (1.14) UNRELEASED; urgency=low + [ Joey Hess ] * Added a fetch command. Closes: #480580 * status: Now includes information about unpushed changes, for git, git-svn, hg, and bzr. Closes: #693021 + [ Paul Wise ] + * Make quiet mode show output if there is some. Closes: #694031 + -- Joey Hess <jo...@debian.org> Sun, 11 Nov 2012 11:33:05 -0400 mr (1.13) unstable; urgency=low 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 7cce39f..69d1326 100755 --- a/mr +++ b/mr @@ -692,6 +692,32 @@ sub fulldir { return $subdir =~ /^\// ? $subdir : $topdir.$subdir; } +sub terminal_friendly_spawn { + my $actionmsg = shift; + my $sh = shift; + my $output = ""; + if (eval{use IO::Pty::Easy;1;} eq 1) { + my $pty = IO::Pty::Easy->new; + $pty->spawn($sh); + while ($pty->is_active) { + my $data = $pty->read(0); + $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 ($output) { + print "$actionmsg\n" if $actionmsg; + print $output; + } + return ($ret, $output ? 1 : 0); +} + sub action { my ($action, $dir, $topdir, $subdir, $force_checkout) = @_; my $fulldir=fulldir($topdir, $subdir); @@ -790,17 +816,12 @@ 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 ($quiet) { - my $output = qx/$sh 2>&1/; - my $ret = $?; - if ($ret != 0) { - print "$actionmsg\n"; - print STDERR $output; - } - return $ret; + return terminal_friendly_spawn($actionmsg, $sh); + } else { system($sh); @@ -838,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) { @@ -852,7 +873,7 @@ sub action { return $ret if $ret != OK; } - return OK; + return (OK, $out || $hook_out); } } } @@ -862,15 +883,10 @@ 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 ($quiet) { - my $output = qx/$sh 2>&1/; - my $ret = $?; - if ($ret != 0) { - print STDERR $output; - } - return $ret; + return terminal_friendly_spawn(undef, $sh); } else { system($sh); @@ -890,7 +906,7 @@ sub hook { } } - return OK; + return (OK, $out); } # run actions on multiple repos, in parallel @@ -966,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) { @@ -978,7 +995,7 @@ sub record { system((getpwuid($<))[8], "-i"); } push @failed, $dir; - print "\n" unless $quiet; + print "\n"; } elsif ($ret == SKIPPED) { push @skipped, $dir; -- 1.8.1.1
signature.asc
Description: This is a digitally signed message part