3 # git-fetch-q-progress.sh - fetch with progress but not ref noise
4 # Copyright (C) 2017,2018 Kyle J. McKay. All rights reserved.
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 git rev-parse
--git-dir >/dev
/null ||
exit
26 #line 27 "git-fetch-q-progress.sh"
31 my $flags = fcntl(STDIN, F_GETFL, 0);
32 defined($flags) or die "fcntl failed: $!";
33 fcntl(STDIN, F_SETFL, $flags | O_NONBLOCK) or die "fcntl failed: $!";
37 sub flush_last { print($last) and $last = undef if defined($last); }
38 my ($total, $creates, $deletes, $forces) = (0,0,0,0);
41 my $msg = $total . " ref";
42 $msg .= "s" unless $total == 1;
45 $msg .= ", " . $creates . " creation";
46 $msg .= "s" unless $creates == 1;
49 $msg .= ", " . $deletes . " deletion";
50 $msg .= "s" unless $deletes == 1;
53 $msg .= ", " . $forces . " forced update";
54 $msg .= "s" unless $forces == 1;
58 $total = $creates = $deletes = $forces = 0;
62 if ($_[0] =~ /^ ([*=!tX +-]) /) {
63 ++$total unless $1 eq "!" || $1 eq "=" || $1 eq "X";
71 $sawref = 1, $last = undef if !$sawref;
72 } elsif ($_[0] =~ /^error:/) {
77 $sawref=0, flush_results if $sawref;
82 my ($rin, $win, $ein);
84 vec($rin, fileno(STDIN), 1) = 1;
86 select($rin, $win, $ein, undef);
87 $cnt = read(STDIN, $data, 1024, length($data));
88 my $idx = rindex($data, "\r");
92 print substr($data, 0, $idx);
93 substr($data, 0, $idx) = "";
95 while (($idx = index($data, "\n")) >= 0) {
97 handle_line(substr($data, 0, $idx));
98 substr($data, 0, $idx) = "";
102 $data eq "" or print $data;
107 read -r ec
<<EOT || :
109 exec 4>&3 3>&1 1>&4 4>&-
110 { ec=0 && git fetch --progress "$@" 3>&- || ec=$?; echo $ec >&3; } 2>&1 |
111 { export PERLPROG && perl -e 'eval $ENV{PERLPROG}'; } >&2