Skip to content

Instantly share code, notes, and snippets.

@kenguest
Created October 22, 2015 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenguest/026d23bfbb991b2b3b6d to your computer and use it in GitHub Desktop.
Save kenguest/026d23bfbb991b2b3b6d to your computer and use it in GitHub Desktop.
Determine changeset url for mercurial repo.
#!/bin/bash
# @Revision: 0.3
x=$(pwd);
rev=$1;
if [ ! -d "$x/.hg" ] ; then
while [ "$x" != "/" ] ;
do x=$(dirname "$x");
test -e "$x/.hg" && break;
done
fi
if [ "$x" = "/" ] ; then
echo "No mercurial repository found." 1>&2;
exit
fi
cd "$x";
url=$(awk -F "=" '/default/ {print $2}' .hg/hgrc|sed -e "s/\ //g;")
if [ "$rev" = "" ] ; then
rev=$(hg tip | grep changeset | cut -d: -f3);
fi
if [ "$rev" != "" ] ; then
rev=$(echo $rev|sed -e "s/.*://")
rev="/rev/$rev";
fi
echo "$url$rev" | sed -e "s@//rev@/rev@"
# vi:set syntax=sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment