]> git.madduck.net Git - code/myrepos.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Pass a fake terminal to subcommands when mr is run in a terminal.
authorPaul Wise <pabs@debian.org>
Wed, 20 Feb 2013 04:03:38 +0000 (12:03 +0800)
committerJoey Hess <joey@kitenet.net>
Sun, 31 Aug 2014 20:23:56 +0000 (13:23 -0700)
This is needed so that programs that print color to terminals
but not to pipes continue to do so when mr redirects output
to a variable before printing it or not printing it.

debian/control
mr

index 8548be6046035b893d4b2ada76035a05665664ef..25185393208b901735f2581ab2ba84aa1d772b9c 100644 (file)
@@ -14,7 +14,7 @@ Depends: ${misc:Depends}
 Suggests: subversion, git-core | git (>= 1:1.7), cvs, bzr, mercurial, darcs, fossil, vcsh, liburi-perl, curl, ack-grep
 Provides: mr
 Replaces: mr
 Suggests: subversion, git-core | git (>= 1:1.7), cvs, bzr, mercurial, darcs, fossil, vcsh, liburi-perl, curl, ack-grep
 Provides: mr
 Replaces: mr
-Recommends: libwww-perl, libhtml-parser-perl, perl
+Recommends: libwww-perl, libhtml-parser-perl, libio-pty-easy-perl, perl
 Description: tool to manage all your version control repos
  The mr(1) command can checkout, update, or perform other actions on
  a set of repositories as if they were one combined respository. It
 Description: tool to manage all your version control repos
  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 afac24dd28f80fbb7efd8e344f42349b5cc66afb..9bcc1ea8c03d66c0c5302af5b2b779ba338dcdb9 100755 (executable)
--- a/mr
+++ b/mr
@@ -578,6 +578,7 @@ my $no_chdir=0;
 my $jobs=1;
 my $trust_all=0;
 my $directory=getcwd();
 my $jobs=1;
 my $trust_all=0;
 my $directory=getcwd();
+my $terminal=-t STDOUT && eval{require IO::Pty::Easy;IO::Pty::Easy->import();1;} eq 1;
 
 my $HOME_MR_CONFIG = "$ENV{HOME}/.mrconfig";
 $ENV{MR_CONFIG}=find_mrconfig();
 
 my $HOME_MR_CONFIG = "$ENV{HOME}/.mrconfig";
 $ENV{MR_CONFIG}=find_mrconfig();
@@ -721,6 +722,33 @@ sub fulldir {
        return $subdir =~ /^\// ? $subdir : $topdir.$subdir;
 }
 
        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 ($quiet && $ret != 0) {
+               print "$actionmsg\n" if $actionmsg;
+               print STDERR $output;
+       } elsif (!$quiet) {
+               print "$actionmsg\n" if $actionmsg;
+               print $output;
+       }
+       return $ret;
+}
+
 sub action {
        my ($action, $dir, $topdir, $subdir, $force_checkout) = @_;
        my $fulldir=fulldir($topdir, $subdir);
 sub action {
        my ($action, $dir, $topdir, $subdir, $force_checkout) = @_;
        my $fulldir=fulldir($topdir, $subdir);
@@ -822,14 +850,8 @@ sub action {
                my $ret=runsh $action, $topdir, $subdir,
                        $command, \@ARGV, sub {
                                my $sh=shift;
                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);
                                }
                                else {
                                        system($sh);
@@ -893,13 +915,8 @@ sub hook {
        return OK unless defined $command;
        my $ret=runsh $hook, $topdir, $subdir, $command, [], sub {
                        my $sh=shift;
        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);
                        }
                        else {
                                system($sh);