tools/rgit2hg.sh
author alfadur <mail@none>
Sat, 08 Apr 2023 16:45:55 +0300
changeset 15949 668c88b31dd6
parent 11517 b3ee79e8e3b9
permissions -rwxr-xr-x
workaround for FPC 3.2.2 linking bug
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")
11514
5d804405964d fix script for resolving git commit id to hg commit id (github page format changed; hw hg repo location too)
sheepluva
parents: 10649
diff changeset
    29
    author=$(echo "$page" | sed -rn '1,/"user-mention"/{s/^.*"user-mention"( *[^>]*)?> *([^ <]*).*$/\2/ p}')
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
    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
11517
b3ee79e8e3b9 find hg revision even if github author name is not the same as hg author (kodabb vs koda)
sheepluva
parents: 11514
diff changeset
    48
        echo 'No match with this author'\''s name. It might differ, so let'\''s try using date only ...'
b3ee79e8e3b9 find hg revision even if github author name is not the same as hg author (kodabb vs koda)
sheepluva
parents: 11514
diff changeset
    49
        echo
b3ee79e8e3b9 find hg revision even if github author name is not the same as hg author (kodabb vs koda)
sheepluva
parents: 11514
diff changeset
    50
        result=$(hg log -R "$HW_HG" -d "$date" -v)
b3ee79e8e3b9 find hg revision even if github author name is not the same as hg author (kodabb vs koda)
sheepluva
parents: 11514
diff changeset
    51
    fi
b3ee79e8e3b9 find hg revision even if github author name is not the same as hg author (kodabb vs koda)
sheepluva
parents: 11514
diff changeset
    52
    if [ -z "$result" ]; then
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
    53
        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
    54
        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
    55
        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
    56
    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
    57
    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
    58
    echo 'Found match: r'"$rev"
11514
5d804405964d fix script for resolving git commit id to hg commit id (github page format changed; hw hg repo location too)
sheepluva
parents: 10649
diff changeset
    59
    echo 'Link:        http://hg.hedgewars.org/hedgewars/rev/'"$rev"
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
    60
    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
    61
    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
    62
    # 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
    63
    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
    64
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
    65
d83897fed816 small shell script that accepts hedgewars git revisions as parameters and will try to find the respective mercurial revision
sheepluva
parents:
diff changeset
    66
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
    67