Meta/genMaintNotes.perl: drop the chrome
[alt-git.git] / amlook
blob809386b97a549c6d3da21babc9d101e36e942bd2
1 #!/bin/sh
2 # Usage:
3 # Meta/amlook <mbox (for single message from MUA) or
4 # Meta/amlook id1 id2... (from the command line)
5 # Meta/amlook --gc
7 find_commit () {
8 in=
9 commits=$(sed -ne "s|^\([0-9a-f]\{40\}\) $1|\1|p" .git/am.log)
10 if test -z "$commits"
11 then
12 # I know I know there should be "notes grep" command...
13 commits=$(
14 git grep -l -e "$1" notes/amlog |
15 sed -e 's|^notes/amlog:||' -e 's|/||g'
18 if test -z "$commits"
19 then
20 echo "Never applied"
21 return
23 found=$(
24 echo "$commits" |
25 while read commit
27 git branch --with $commit
28 done | sed -e 's|^..||' |
29 sort -u |
30 tr '\012' ' '
32 if test -z "$found"
33 then
34 echo "Not merged ($commits)"
35 return
37 case " $found " in
38 *' maint '*) in=maint ;;
39 *' master '*) in=master ;;
40 *' next '*) in=next ;;
41 esac
42 if test -n "$in"
43 then
44 echo "Found in $in"
45 else
46 echo "Found in $found"
50 garbage_collect () {
51 cutoff_days=${1-"180"} &&
52 git notes --ref amlog list |
53 sed -e 's/.* //' |
54 xargs -n 1 git show -s --format="%ci %H" 2>/dev/null |
55 perl -e '
56 my @time = localtime(time() - $ARGV[0] * 24 * 3600);
57 my $cutoff = sprintf("%04d-%02d-%02d 00:00:00",
58 $time[5]+1900, $time[4]+1, $time[3]);
59 while (<STDIN>) {
60 if ($_ le $cutoff) {
61 s/.* //;
62 print;
65 ' "$cutoff_days" >..gcinput
67 : <<\INVALID
68 : (
69 GIT_INDEX_FILE=/tmp/amlook.$$.tmp &&
70 export GIT_INDEX_FILE &&
71 rm -f "$GIT_INDEX_FILE" &&
72 git read-tree refs/notes/amlog &&
73 xargs git rm -f &&
74 T=$(git write-tree) &&
75 C=$(echo Prune amlog | git commit-tree $T -p refs/notes/amlog) &&
76 git update-ref -m "Prune amlog" refs/notes/amlog $C
78 INVALID
81 if test $# = 0
82 then
83 msg=$(sed -ne '
84 /^[ ]/{
85 # Append continuation line
88 s/\n//
92 # Hold this new line, and look at what is in the hold space
94 # Is it the Message-ID line? If so, spit out and finish.
95 /^[Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]:[ ]*/{
96 s///p
99 # Otherwise, check if this new line is empty
101 # Is it? Then we are done with the header
102 /^$/b end
103 # Otherwise we need to hold onto this header line
105 # And start the next cycle
107 : end
109 ') &&
110 find_commit "$msg"
111 elif test "$1" = "--gc"
112 then
113 shift
114 garbage_collect "$@"
115 else
116 for msg
118 find_commit "$msg"
119 done