small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
authorsheepluva
Wed, 10 Dec 2014 22:33:09 +0100
changeset 10649 d83897fed816
parent 10648 75498cfe6267
child 10650 7f23971bd9db
small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
tools/rgit2hg.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rgit2hg.sh	Wed Dec 10 22:33:09 2014 +0100
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+#HW_HG=
+
+if [ -z "$1" ]; then
+    echo 'You have to supply at least one hedgewars git revision as parameter!' >&2
+    exit
+fi
+
+if [ -z "$HW_HG" ]; then 
+    HW_HG="$PWD"
+fi
+
+if [ ! -d "$HW_HG/.hg" ]; then
+    echo 'You have to set HW_HG (inside script or env) to a repo clone OR call this script from inside the repository!' >&2
+    exit
+fi
+
+while [ ! -z "$1" ]; do
+    echo
+    echo
+    echo '---------------------------------------------------------------'
+    echo "$1"
+    echo '---------------------------------------------------------------'
+    url="https://github.com/hedgewars/hw/commit/$1"
+    echo "Checking $url ..."
+    echo
+    page=$(wget -q -O- "$url")
+    author=$(echo "$page" | sed -rn 's/^.*"author-name">(<[^>]*>)*([^ <]*).*/\2/ p')
+    if [ -z "$author" ]; then
+        echo 'Couldn'\''t find author! Skipping '"$1"' ...' >&2
+        shift
+        continue
+    fi
+    echo 'Found author: '"$author"
+    date=$(echo "$page" | sed -rn 's/^.*<time datetime="([^T]+)T([^Z]+).*/\1 \2 +0000/ p')
+    if [ -z "$date" ]; then
+        echo 'Couldn'\''t find date! Skipping '"$1"' ...' >&2
+        shift
+        continue
+    fi
+    echo 'Found date:   '"$date"
+    echo
+    echo 'Checking mercurial log for matches ...'
+    echo
+    result=$(hg log -R "$HW_HG" -u "$author" -d "$date" -v -l1)
+    if [ -z "$result" ]; then
+        echo 'No match :('
+        shift
+        continue
+    fi
+    rev=$(echo "$result" | sed 's/^.*://;q')
+    echo 'Found match: r'"$rev"
+    echo 'Link:        https://code.google.com/p/hedgewars/source/detail?r='"$rev"
+    echo
+    echo "$result"
+    # proceed to next parameter
+    shift
+done
+
+echo
+