Skip to content

Instantly share code, notes, and snippets.

@rsc
Last active September 24, 2015 11:27
Show Gist options
  • Save rsc/740498 to your computer and use it in GitHub Desktop.
Save rsc/740498 to your computer and use it in GitHub Desktop.
script for pushing and popping CLs
#!/bin/sh
set -e
root=$(hg root)
if [ $# = 0 ]; then
for i in $(ls $root/.hg/codereview/cl.* 2>/dev/null)
do
n=$(echo $i | sed 's/.*cl.//')
desc=$(sed -n '/^Description:/,$p' $i | sed -n 2p)
echo +$n' '$desc
done
for i in $(ls $root/.hg/codereview/clpush.* 2>/dev/null)
do
n=$(echo $i | sed 's/.*clpush.//')
desc=$(sed -n '/^Description:/,$p' $i | sed -n 2p)
echo -$n' '$desc
done
exit 0
fi
for i
do
case "$i" in
-*)
n=$(echo $i | sed 's/^-//')
if [ ! -f $root/.hg/codereview/cl.$n ]; then
echo '$n: cl not active' 1>&2
exit 2
fi
newfiles=$(hg status -n -a @$n)
cp $root/.hg/codereview/cl.$n $root/.hg/codereview/clpush.$n
hg diff --git @$n >$root/.hg/codereview/cldiff.$n
hg revert @$n
if [ "$newfiles" != "" ]; then
rm -f $newfiles
fi
rm $root/.hg/codereview/cl.$n
;;
+*)
n=$(echo $i | sed 's/^+//')
if [ ! -f $root/.hg/codereview/clpush.$n -o ! -f $root/.hg/codereview/cldiff.$n ]; then
echo '$n: cl not pushed' 1>&2
exit 2
fi
hg patch -f --no-commit $root/.hg/codereview/cldiff.$n
mv $root/.hg/codereview/clpush.$n $root/.hg/codereview/cl.$n
rm $root/.hg/codereview/cldiff.$n
;;
*)
echo 'unknown operation:' "$i" 1>&2
exit 2
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment