To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / extra / soundsoftware / flatten.sh @ 1570:ae2f71010562

History | View | Annotate | Download (1.9 KB)

1 1563:171c31a5cca4 Chris
#!/bin/bash
2
#
3
# Convert an Hg repo with subrepos into a new repo in which the
4
# subrepo contents are included in the main repo. The history of the
5
# original and its subrepos is retained.
6
#
7
# Note that this script invokes itself, in order to handle nested
8
# subrepos.
9
#
10
# While this does work, I'm not convinced it's entirely a good
11
# idea. The history ends up a bit of a mess, and if it's a preliminary
12
# to converting to git (which is one obvious reason to do this), the
13
# history ends up even messier after that conversion.
14
15
set -ex
16
17
repo="$1"
18
target="$2"
19
target_subdir="$3"
20
revision="$4"
21
22
if [ -z "$repo" ] || [ -z "$target" ]; then
23
    echo "usage: $0 <repo-url> <target-dir> [<target-subdir> <revision>]"
24
    exit 2
25
fi
26
27
set -u
28
29
myname="$0"
30
mydir=$(dirname "$myname")
31
32
reponame=$(basename "$repo")
33
tmpdir="/tmp/flatten_$$"
34
mkdir -p "$tmpdir"
35
trap "rm -rf ${tmpdir}" 0
36
37
filemap="$tmpdir/filemap"
38
tmprepo="$tmpdir/tmprepo"
39
subtmp="$tmpdir/subtmp"
40
41
if [ -n "$revision" ]; then
42
    hg clone -r "$revision" "$repo" "$tmprepo"
43
else
44
    hg clone "$repo" "$tmprepo"
45
fi
46
47
read_sub() {
48
    if [ -f "$tmprepo/.hgsub" ]; then
49
	cat "$tmprepo/.hgsub" | sed 's/ *= */,/'
50
    fi
51
}
52
53
(   echo "exclude .hgsub"
54
    echo "exclude .hgsubstate"
55
    read_sub | while IFS=, read dir uri; do
56
	echo "exclude $dir"
57
    done
58
    if [ -n "$target_subdir" ]; then
59
	echo "rename . $target_subdir"
60
    fi
61
) > "$filemap"
62
63
hg convert --filemap "$filemap" "$tmprepo" "$target"
64
(   cd "$target"
65
    hg update
66
)
67
68
read_sub | while IFS=, read dir uri; do
69
    rm -rf "$subtmp"
70
    revision=$(grep ' '"$dir"'$' "$tmprepo/.hgsubstate" | awk '{ print $1; }')
71
    if [ -n "$target_subdir" ]; then
72
	"$myname" "$tmprepo/$dir" "$subtmp" "$target_subdir/$dir" "$revision"
73
    else
74
	"$myname" "$tmprepo/$dir" "$subtmp" "$dir" "$revision"
75
    fi
76
    (   cd "$target"
77
	hg pull -f "$subtmp" &&
78
	    hg merge --tool internal:local &&
79
	    hg commit -m "Merge former subrepo $dir"
80
    )
81
done