Created
October 22, 2015 07:07
-
-
Save kenguest/026d23bfbb991b2b3b6d to your computer and use it in GitHub Desktop.
Determine changeset url for mercurial repo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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