indextext.html: update notice about ssh host key change
[girocco/readme.git] / jobd / git-fetch-q-progress.sh
blob5267a81d828e94acb91151082aea534eded7312f
1 #!/bin/sh
3 # git-fetch-q-progress.sh - fetch with progress but not ref noise
4 # Copyright (C) 2017,2018,2020 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.
20 # Version 1.0.2
22 set -e
23 : "${GIT_BIN:=git}"
24 eval "$GIT_BIN"' rev-parse --git-dir >/dev/null' || exit
25 PERLPROG='
26 #!perl
27 #line 28 "git-fetch-q-progress.sh"
28 use strict;
29 use warnings;
30 use Fcntl;
31 $| = 1;
32 my $flags = fcntl(STDIN, F_GETFL, 0);
33 defined($flags) or die "fcntl failed: $!";
34 fcntl(STDIN, F_SETFL, $flags | O_NONBLOCK) or die "fcntl failed: $!";
35 my $data = "";
36 my $cnt;
37 my $last = undef;
38 sub flush_last { print($last) and $last = undef if defined($last); }
39 my ($total, $creates, $deletes, $forces) = (0,0,0,0);
40 sub flush_results {
41 if ($total) {
42 my $msg = $total . " ref";
43 $msg .= "s" unless $total == 1;
44 $msg .= " affected";
45 if ($creates) {
46 $msg .= ", " . $creates . " creation";
47 $msg .= "s" unless $creates == 1;
49 if ($deletes) {
50 $msg .= ", " . $deletes . " deletion";
51 $msg .= "s" unless $deletes == 1;
53 if ($forces) {
54 $msg .= ", " . $forces . " forced update";
55 $msg .= "s" unless $forces == 1;
57 print $msg, "\n";
59 $total = $creates = $deletes = $forces = 0;
61 my $sawref;
62 sub handle_line {
63 if ($_[0] =~ /^ ([*=!tX +-]) /) {
64 ++$total unless $1 eq "!" || $1 eq "=" || $1 eq "X";
65 if ($1 eq "-") {
66 ++$deletes;
67 } elsif ($1 eq "*") {
68 ++$creates;
69 } elsif ($1 eq "+") {
70 ++$forces;
72 $sawref = 1, $last = undef if !$sawref;
73 } elsif ($_[0] =~ /^error:/) {
74 flush_last;
75 print STDERR $_[0];
76 } else {
77 flush_last;
78 $sawref=0, flush_results if $sawref;
79 $last = $_[0];
82 do {
83 my ($rin, $win, $ein);
84 $rin = $win = "";
85 vec($rin, fileno(STDIN), 1) = 1;
86 $ein = $rin;
87 select($rin, $win, $ein, undef);
88 $cnt = read(STDIN, $data, 1024, length($data));
89 my $idx = rindex($data, "\r");
90 if ($idx >= 0) {
91 ++$idx;
92 flush_last;
93 print substr($data, 0, $idx);
94 substr($data, 0, $idx) = "";
96 while (($idx = index($data, "\n")) >= 0) {
97 ++$idx;
98 handle_line(substr($data, 0, $idx));
99 substr($data, 0, $idx) = "";
101 } while $cnt;
102 flush_last;
103 $data eq "" or print $data;
104 flush_results
106 exec 3>&1
108 read -r ec <<EOT || :
110 exec 4>&3 3>&1 1>&4 4>&-
111 { ec=0 && eval "$GIT_BIN"' fetch --progress "$@" 3>&-' || ec=$?; echo $ec >&3; } 2>&1 |
112 { export PERLPROG && perl -e 'eval $ENV{PERLPROG}'; } >&2
115 exec 3>&-
116 exit ${ec:-1}