tools/rgit2hg.sh
author unc0rr
Wed, 08 Apr 2015 23:39:18 +0300
branchqmlfrontend
changeset 10888 a04e04aaf599
parent 10649 d83897fed816
child 11519 5d804405964d
permissions -rwxr-xr-x
Ammo schemes list, almost works
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10649
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     1
#!/bin/sh
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     2
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     3
#HW_HG=
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     4
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     5
if [ -z "$1" ]; then
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     6
    echo 'You have to supply at least one hedgewars git revision as parameter!' >&2
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     7
    exit
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     8
fi
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
     9
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    10
if [ -z "$HW_HG" ]; then 
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    11
    HW_HG="$PWD"
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    12
fi
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    13
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    14
if [ ! -d "$HW_HG/.hg" ]; then
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    15
    echo 'You have to set HW_HG (inside script or env) to a repo clone OR call this script from inside the repository!' >&2
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    16
    exit
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    17
fi
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    18
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    19
while [ ! -z "$1" ]; do
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    20
    echo
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    21
    echo
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    22
    echo '---------------------------------------------------------------'
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    23
    echo "$1"
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    24
    echo '---------------------------------------------------------------'
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    25
    url="https://github.com/hedgewars/hw/commit/$1"
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    26
    echo "Checking $url ..."
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    27
    echo
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    28
    page=$(wget -q -O- "$url")
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    29
    author=$(echo "$page" | sed -rn 's/^.*"author-name">(<[^>]*>)*([^ <]*).*/\2/ p')
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    30
    if [ -z "$author" ]; then
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    31
        echo 'Couldn'\''t find author! Skipping '"$1"' ...' >&2
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    32
        shift
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    33
        continue
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    34
    fi
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    35
    echo 'Found author: '"$author"
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    36
    date=$(echo "$page" | sed -rn 's/^.*<time datetime="([^T]+)T([^Z]+).*/\1 \2 +0000/ p')
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    37
    if [ -z "$date" ]; then
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    38
        echo 'Couldn'\''t find date! Skipping '"$1"' ...' >&2
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    39
        shift
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    40
        continue
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    41
    fi
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    42
    echo 'Found date:   '"$date"
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    43
    echo
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    44
    echo 'Checking mercurial log for matches ...'
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    45
    echo
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    46
    result=$(hg log -R "$HW_HG" -u "$author" -d "$date" -v -l1)
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    47
    if [ -z "$result" ]; then
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    48
        echo 'No match :('
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    49
        shift
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    50
        continue
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    51
    fi
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    52
    rev=$(echo "$result" | sed 's/^.*://;q')
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    53
    echo 'Found match: r'"$rev"
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    54
    echo 'Link:        https://code.google.com/p/hedgewars/source/detail?r='"$rev"
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    55
    echo
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    56
    echo "$result"
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    57
    # proceed to next parameter
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    58
    shift
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    59
done
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    60
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    61
echo
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    62