-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlore
executable file
·262 lines (241 loc) · 7.99 KB
/
lore
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
#
# lore.kernel.org commit-or-search to Mutt reader
#
# Copyright (c) 2023 Vitaly Chikunov <[email protected]>
# SPDX-License-Identifier: GPL-2.0-only
set -euf -o pipefail
dedup=y
search=patchid
unset mode force_mode tags qprefix
muttrc=(-F muttrc)
curlopts=()
sort=threads
sort_aux=last-date
if type -p neomutt >/dev/null; then
reader=neomutt
else
reader=mutt
fi
show_help() {
[ $# -eq 0 ] || echo 2>^1 "Error: argument required"
cat >&2 <<"EOF"
Usage: lore [options] [commitish or query]
Default search is by patchid of referenced commitish (full threads).
If argument contains ':' it's same as --query specified (no threads).
-s, --subject search by commitish's subject line (no threads).
-q, --query raw search questy with below query language (no threads).
-t, --thread (force) return full threads (it's belong to).
-r, --results (force) return of matched results only (no threads).
-T, --tags Add -by tags for neomutt (works very slwoly.)
--reverse Reverse sort order.
Query language:
It supports typical AND, OR, NOT, '+', '-' queries present
in other search engines.
We also support search prefixes to limit the scope of the
search to certain fields.
Prefixes supported in this installation include:
s: match within Subject e.g. s:"a quick brown fox"
d: match date-time range, git "approxidate" formats supported
Open-ended ranges such as `d:last.week..' and
`d:..2.days.ago' are supported
b: match within message body, including text attachments
nq: match non-quoted text within message body
q: match quoted text within message body
n: match filename of attachment(s)
t: match within the To header
c: match within the Cc header
f: match within the From header
a: match within the To, Cc, and From headers
tc: match within the To and Cc headers
l: match contents of the List-Id header
bs: match within the Subject and body
dfn: match FILENAME from diff
dfa: match diff removed (-) lines
dfb: match diff added (+) lines
dfhh: match diff hunk header context (usually a FUNCTION name)
dfctx: match diff context lines
dfpre: match pre-image git blob ID
dfpost: match post-image git blob ID
dfblob: match either pre or post-image git blob ID
patchid: match `git patch-id --stable' output
rt: match received time, like `d:' if sender's clock was correct
Most prefixes are probabilistic, meaning they support stemming
and wildcards ('*'). Ranges (such as 'd:') and boolean prefixes
do not support stemming or wildcards.
EOF
exit ${1-0}
}
for opt; do
shift
case "$opt" in
--reader=*) reader=${opt#*=} ;;
--raw) unset dedup ;;
-s | --subject | --subj) search=subject ;;
-q | --query) search=query ;;
-f | --file) qprefix=dfn: ;;
-F | --fun*) qprefix=dfhh: ;;
-t | --thr*) force_mode="x=full+threads" ;;
-r | --res*) force_mode="z=results+only" ;;
-T | --tags) tags=y ;;
-h | --help) show_help ;;
--insecure) curlopts+=(--insecure) ;;
--no-muttrc) muttrc=() ;;
--rev*) sort=reverse-threads ;;
-*) echo "unknown option: $opt"; exit 1 ;;
*) set -- "$@" "$opt" ;;
esac
done
[ $# -ne 0 ] || show_help 1
commit=${1:?committish}
if [[ "$*" =~ : ]]; then
search=query
elif [ -v qprefix ]; then
search=query
else
for dir in . \
"$HOME/linux/torvalds" \
"$HOME/src/linux" \
"$HOME/linux" \
"$HOME/src/kernel-image" \
"$HOME/src/qemu"
do
cd "$dir" 2>/dev/null || continue
git cat-file -e "$commit^{commit}" 2>/dev/null && break
done
fi
commit_info() {
author=$( git log --format=%an -n1 "$commit" --)
aemail=$( git log --format=%ae -n1 "$commit" --)
committer=$( git log --format=%cn -n1 "$commit" --)
commemail=$( git log --format=%ce -n1 "$commit" --)
subjfn=$( git log --format=%f -n1 "$commit" --)
subj=$( git log --format=%s -n1 "$commit" --)
subjre=${subj//[^[:alnum:]]/.}
}
case "$search" in
patchid)
commit_info
patchid=$(git --no-pager show "$commit" -- | git patch-id --stable)
patchid=${patchid% *}
if [ -z "$patchid" ]; then
objtype=$(git cat-file -t "$commit")
git cat-file -t "$commit^2" >/dev/null 2>&1 && objtype="merge commit"
echo >&2 "No patch-id for a $objtype."
exit 1
fi
query="patchid:$patchid"
mode="x=full+threads"
;;
subject)
commit_info
query="s:${subj// /+}"
query="s:$(perl -MURI::Escape -e 'print uri_escape($ARGV[0])' "$subj")"
query=${query//%20/+}
mode="z=results+only"
;;
query)
unset committer
query="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0])' "$*")"
query=${qprefix-}${query//%20/+}
mode="z=results+only"
subjfn=${query//[^[:alnum:]]/_}
subjre=${*#*:}
subjre=${subjre//[^[:alnum:]]/.}
;;
esac
[ -v force_mode ] && mode=$force_mode
tmp=$(mktemp -d --tmpdir lore.XXXXXXXXXX)
cd "$tmp"
echo "+ cd $tmp"
(set -x; curl "${curlopts[@]}" -sS -L -f "https://lore.kernel.org/all/?q=$query&x=m" -d "$mode" -o mbox.gz)
gzip -d mbox.gz
mbox="$subjfn"
if [ -v dedup ] && type -p formail >/dev/null; then
formail -D 16384 idcache -s < mbox > "$mbox"
else
mv -- mbox "$mbox"
fi
cat > muttrc <<EOF
set from="$(git config user.email)"
set realname="$(git config user.name)"
set reverse_name
set reverse_realname
set edit_headers
set editor=$EDITOR
set help=no
set envelope_from=yes
alternative_order text/plain text/enriched text/html
ignore *
unignore from date subject to cc message-id resent-from
EOF
if [ -v tags ]; then
cat >> muttrc <<-EOF
# Note: index-format-hook slows down scrolling considerably
index-format-hook resol "~b^fixes:" Fixes
index-format-hook resol "~b^signed-off-by:" PATCH
index-format-hook resol "~b^acked-by:" Ack
index-format-hook resol "~b^reviewed-by:" Review
index-format-hook resol "~b^tested-by:" Tested
set index_format="%4C %Z %[%d/%b/%y %H:%M] %-15.15n %-6@resol@ (%4l%?X?+%X&?) %H %s"
EOF
else
cat >> muttrc <<-EOF
set index_format="%4C %Z %[%d/%b/%y %H:%M] %-15.15n (%4l%?X?+%X&?) %H %s"
set index_format="%4C %Z %[%Y-%m-%d %H:%M] %-15.15n (%4l%?X?+%X&?) %H %s"
EOF
fi
cat >> muttrc <<-EOF
set sort=$sort
set sort_aux=$sort_aux
color index_flags cyan default ~N
color index_date blue default "~d <1y"
color index_date cyan default "~d <1m"
color index_date green default "~d <1w"
color index_date yellow default "~d <1d"
color hdrdefault brightblack black
color header yellow black ^(From):
color header cyan black ^(Subject):
color header green black ^(To|Cc):
color header white black ^(Date):
color header magenta black ^(X-Label|X-Maintainer|X-Reviewer):
color signature blue black
color error brightred black
color status brightwhite blue
color tree magenta black
color tilde brightblack black
color message cyan black
color markers cyan black
color attachment brightgreen black
color search black red
color quoted brightblue black
color quoted1 yellow black
color quoted2 red black
color quoted3 green black
color quoted4 cyan black
color quoted5 blue black
color quoted6 yellow black
color quoted7 red black
color quoted8 green black
color quoted9 cyan black
color body green default "^diff \-.*"
color body green default "^index [a-f0-9].*"
color body green default "^\-\-\- .*"
color body green default "^[\+]{3} .*"
color body cyan default "^[\+][^\+]+.*"
color body red default "^\-[^\-]+.*"
color body brightblue default "^@@ .*"
color index_subject brightyellow default "~s '$subjre'"
EOF
if [ -v committer ]; then
cat >> muttrc <<-EOF
color index_author brightgreen default "~f '$committer'"
color index_author brightgreen default "~f '$commemail'"
color index_author brightyellow default "~f '$author'"
color index_author brightyellow default "~f '$aemail'"
EOF
fi
$reader "${muttrc[@]}" -f $mbox
echo >&2 cd $tmp
exit 1
rm -rf "$tmp"