-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-since
executable file
·134 lines (113 loc) · 2.51 KB
/
new-since
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
#!/bin/sh
#==============================================================================
# new-since
# File ID: 26ffabea-02a3-11e7-a69b-db5caa6d21d3
#
# Display number of new repositories since the last update.
#
# Author: Øyvind A. Holm <[email protected]>
# License: GNU General Public License version 2 or later.
#==============================================================================
progname=new-since
VERSION=0.1.0
db=repos.sqlite
opt_help=0
opt_quiet=0
opt_verbose=0
while test -n "$1"; do
case "$1" in
-h|--help) opt_help=1; shift ;;
-q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
-v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
--version) echo $progname $VERSION; exit 0 ;;
--) shift; break ;;
*)
if printf '%s\n' "$1" | grep -q ^-; then
echo "$progname: $1: Unknown option" >&2
exit 1
else
break
fi
break ;;
esac
done
opt_verbose=$(($opt_verbose - $opt_quiet))
if test "$opt_help" = "1"; then
test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
cat <<END
Display number of new repositories since the last update.
Usage: $progname [options]
Options:
-h, --help
Show this help.
-q, --quiet
Be more quiet. Can be repeated to increase silence.
-v, --verbose
Increase level of verbosity. Can be repeated.
--version
Print version information.
END
exit 0
fi
date_to_jday() {
echo "SELECT julianday('$1');" | sqlite3
}
first() {
echo -n "
SELECT $1 FROM repos
ORDER BY date DESC
LIMIT 2;
" | sqlite3 $db | tail -1
}
latest() {
echo -n "
SELECT $1 FROM repos
ORDER BY date DESC
LIMIT 1;
" | sqlite3 $db
}
insnew() {
local name="$1"
echo "
INSERT INTO tmp
VALUES (
'$name',
$(latest $name) - $(first $name)
);
"
}
totals() {
echo "
SELECT name, val FROM tmp ORDER BY val DESC, name;
SELECT '----------', '------';
SELECT 'Total', sum(val) FROM tmp;
"
}
make $db >/dev/null || exit
now=$(echo "
SELECT date FROM repos
ORDER BY date DESC
LIMIT 1;
" | sqlite3 $db)
jnow=$(date_to_jday "$now")
prev=$(echo "
SELECT date FROM repos
ORDER BY date DESC
LIMIT 2;
" | sqlite3 $db | tail -1)
jprev=$(date_to_jday "$prev")
jperiod=$(echo "SELECT $jnow-$jprev;" | sqlite3)
printf '\nNew repos between\n%s UTC\n%s UTC\n(%.04f days):\n\n' \
"$prev" "$now" "$jperiod"
echo "
.width 10 -6 -9
CREATE TEMPORARY TABLE tmp (name TEXT, val INTEGER);
$(insnew bazaar)
$(insnew cvs)
$(insnew git)
$(insnew mercurial)
$(insnew subversion)
$(totals)
" | sqlite3 -column repos.sqlite
echo
# vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :