-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_logs.sh
More file actions
executable file
·166 lines (146 loc) · 4.89 KB
/
join_logs.sh
File metadata and controls
executable file
·166 lines (146 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/sh
#-
# Copyright (c) 2013-2019 Devin Teske <dteske@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
############################################################ IDENT(1)
#
# $Title: Test program to merge git log histories $
# $DruidBSD: /cvsroot/druidbsd/git_logjoin/join_logs.sh,v 1.2 2017/06/21 02:39:56 devinteske Exp $
# $FrauBSD: //github.com/FrauBSD/git_logjoin/join_logs.sh 2019-05-16 19:50:51 -0700 freebsdfrau $
# $FreeBSD$
#
############################################################ CONFIGURATION
#
# Directory to look for logs in
#
LOGDIR=logs
#
# Remote host where `git log' is performed
# NB: Unset or empty to use local directories on this host
#
REMOTE_HOST=
#
# List of git logfiles to join
# NOTE: Format is local_repos_dir:local_log_file
#
LOGS="
$HOME/src/fraubsd/pkgcenter:$LOGDIR/pkgcenter.log
" # END-QUOTE
#
# File(s) to save output(s) to
#
OUTPUT=../fraubsd.log
#
# Should we use sysutils/pv to monitor the progress? (recommended)
# Set to the NULL string to disable the use of pv(1).
#
USE_PV=YES
############################################################ GLOBALS
# NB: Only used if REMOTE_HOST is set and non-NULL
SSH_OPT="-A -oStrictHostKeyChecking=no"
GIT_LOG_OPT="
--pretty=format:user:%aN%n%ct
--reverse --raw --encoding=UTF-8
--no-renames
" # END-QUOTE
GET_LOG='
repos="$1"
shift 1 # repos
cd "$repos" && git pull > /dev/null && git log "$@"
' # END-QUOTE
############################################################ FUNCTIONS
have() { type "$@" > /dev/null 2>&1; }
get_log()
{
local repos
( eval "$GET_LOG" )
}
############################################################ MAIN
#
# Make sure we have git_logjoin
#
if [ ! -e git_logjoin ]; then
echo ">>> Building git_logjoin utility..."
make || exit 1
fi
#
# First make sure we have each log
#
mkdir -p "$LOGDIR" || exit 1
for log in $LOGS; do
logfile="${log#*:}"
[ -e "$logfile" ] && continue
# Download the log history
repos="${log%%:*}"
echo ">>> Downloading \`$repos' History to \`$logfile'..."
if [ "$USE_PV" ] && have pv; then
if [ "$REMOTE_HOST" ]; then
echo "$GET_LOG" | ssh $SSH_OPT $REMOTE_HOST \
sh /dev/stdin "$repos" $GIT_LOG_OPT |
pv > "$logfile"
else
get_log "$repos" $GIT_LOG_OPT | pv > "$logfile"
fi
else
[ "$USE_PV" ] && echo "NOTE: If you install sysutils/pv" \
"you'll get a lot more feedback!"
if [ "$REMOTE_HOST" ]; then
echo "$GET_LOG" | ssh $SSH_OPT $REMOTE_HOST \
sh /dev/stdin "$repos" $GIT_LOG_OPT
else
get_log "$repos" $GIT_LOG_OPT > "$logfile"
fi
fi
[ $? -eq 0 ] || exit 1
done
#
# Combine the logfiles into a single output
#
echo ">>> Combining logfiles into \`$OUTPUT':"
if [ "$USE_PV" ] && have pv; then
# Get a list of sizes so we can tell pv how many bytes to expect
bytes=0
for log in $LOGS; do
logfile="${log#*:}"
# Subtract 52 bytes for non-duplicated data
[ $bytes -ne 0 ] && bytes=$(( $bytes - 52 ))
case "${UNAME_s:=$( uname -s )}" in
Linux) bytes=$(( $bytes + $( stat -c%s "$logfile" ) )) ;;
*) bytes=$(( $bytes + $( stat -f%z "$logfile" ) ))
esac
done
# Combine the logs using pv(1) to monitor the flow of data
# NOTE: pv(1) provides us with its own running/total time
echo "NOTE: Percentage expected to be slightly over 100% given changes"
./git_logjoin $LOGS | pv -s $bytes > "$OUTPUT"
else
[ "$USE_PV" ] && echo "NOTE: If you install sysutils/pv" \
"you'll get a lot more feedback!"
# Combine the logs (this may take a while and not give any feedback)
time ./git_logjoin $LOGS > "$OUTPUT"
fi
################################################################################
# END
################################################################################