blob: 1fcbd347fa4230c7dfa11531ccb5b2b4d892edca [file] [log] [blame]
#!/bin/sh
# Usage:
# Meta/amlook <mbox (for single message from MUA) or
# Meta/amlook id1 id2... (from the command line)
# Meta/amlook --gc
MASTER=master
find_commit () {
in= commits=
if test -z "$commits"
then
# I know I know there should be "notes grep" command...
commits=$(
git grep -l -e "$1" notes/amlog |
sed -e 's|^notes/amlog:||' -e 's|/||g'
)
fi
if test -z "$commits"
then
commits=$(sed -ne "s|^\([0-9a-f]\{40\}\) $1|\1|p" .git/am.log)
fi
if test -z "$commits"
then
echo "Never applied"
return
fi
echo "$commits"
found=$(
echo "$commits" |
while read commit
do
git branch --with $commit
done | sed -e 's|^..||' |
sort -u |
tr '\012' ' '
)
if test -z "$found"
then
echo "Not merged ($commits)"
return
fi
case " $found " in
*' maint '*) in=maint ;;
*" $MASTER "*) in=$MASTER ;;
*' next '*) in=next ;;
esac
if test -n "$in"
then
echo "Found in $in"
else
echo "Found in $found"
fi
}
garbage_collect () {
cutoff_days=${1-"180"} &&
git notes --ref amlog list |
sed -e 's/.* //' |
xargs -n 1 git show -s --format="%ci %H" 2>/dev/null |
perl -e '
my @time = localtime(time() - $ARGV[0] * 24 * 3600);
my $cutoff = sprintf("%04d-%02d-%02d 00:00:00",
$time[5]+1900, $time[4]+1, $time[3]);
while (<STDIN>) {
if ($_ le $cutoff) {
s/.* //;
print;
}
}
' "$cutoff_days" >..gcinput
: <<\INVALID
: (
GIT_INDEX_FILE=/tmp/amlook.$$.tmp &&
export GIT_INDEX_FILE &&
rm -f "$GIT_INDEX_FILE" &&
git read-tree refs/notes/amlog &&
xargs git rm -f &&
T=$(git write-tree) &&
C=$(echo Prune amlog | git commit-tree $T -p refs/notes/amlog) &&
git update-ref -m "Prune amlog" refs/notes/amlog $C
)
INVALID
}
if test $# = 0
then
msg=$(sed -ne '
/^[ ]/{
# Append continuation line
H
x
s/\n//
x
n
}
# Hold this new line, and look at what is in the hold space
x
# Is it the Message-ID line? If so, spit out and finish.
/^[Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]:[ ]*/{
s///p
q
}
# Otherwise, check if this new line is empty
x
# Is it? Then we are done with the header
/^$/b end
# Otherwise we need to hold onto this header line
x
# And start the next cycle
b
: end
q
') &&
find_commit "$msg"
elif test "$1" = "--gc"
then
shift
garbage_collect "$@"
elif test "$1" == "--squash"
then
L=notes/amlog &&
git notes --ref=$L prune &&
C=$(echo amlog | git commit-tree refs/$L^{tree}) &&
git update-ref refs/$L $C
else
for msg
do
find_commit "$msg"
done
fi