Chris@1563: #!/bin/bash Chris@1563: # Chris@1563: # Convert an Hg repo with subrepos into a new repo in which the Chris@1563: # subrepo contents are included in the main repo. The history of the Chris@1563: # original and its subrepos is retained. Chris@1563: # Chris@1563: # Note that this script invokes itself, in order to handle nested Chris@1563: # subrepos. Chris@1563: # Chris@1563: # While this does work, I'm not convinced it's entirely a good Chris@1563: # idea. The history ends up a bit of a mess, and if it's a preliminary Chris@1563: # to converting to git (which is one obvious reason to do this), the Chris@1563: # history ends up even messier after that conversion. Chris@1563: Chris@1563: set -ex Chris@1563: Chris@1563: repo="$1" Chris@1563: target="$2" Chris@1563: target_subdir="$3" Chris@1563: revision="$4" Chris@1563: Chris@1563: if [ -z "$repo" ] || [ -z "$target" ]; then Chris@1563: echo "usage: $0 [ ]" Chris@1563: exit 2 Chris@1563: fi Chris@1563: Chris@1563: set -u Chris@1563: Chris@1563: myname="$0" Chris@1563: mydir=$(dirname "$myname") Chris@1563: Chris@1563: reponame=$(basename "$repo") Chris@1563: tmpdir="/tmp/flatten_$$" Chris@1563: mkdir -p "$tmpdir" Chris@1563: trap "rm -rf ${tmpdir}" 0 Chris@1563: Chris@1563: filemap="$tmpdir/filemap" Chris@1563: tmprepo="$tmpdir/tmprepo" Chris@1563: subtmp="$tmpdir/subtmp" Chris@1563: Chris@1563: if [ -n "$revision" ]; then Chris@1563: hg clone -r "$revision" "$repo" "$tmprepo" Chris@1563: else Chris@1563: hg clone "$repo" "$tmprepo" Chris@1563: fi Chris@1563: Chris@1563: read_sub() { Chris@1563: if [ -f "$tmprepo/.hgsub" ]; then Chris@1563: cat "$tmprepo/.hgsub" | sed 's/ *= */,/' Chris@1563: fi Chris@1563: } Chris@1563: Chris@1563: ( echo "exclude .hgsub" Chris@1563: echo "exclude .hgsubstate" Chris@1563: read_sub | while IFS=, read dir uri; do Chris@1563: echo "exclude $dir" Chris@1563: done Chris@1563: if [ -n "$target_subdir" ]; then Chris@1563: echo "rename . $target_subdir" Chris@1563: fi Chris@1563: ) > "$filemap" Chris@1563: Chris@1563: hg convert --filemap "$filemap" "$tmprepo" "$target" Chris@1563: ( cd "$target" Chris@1563: hg update Chris@1563: ) Chris@1563: Chris@1563: read_sub | while IFS=, read dir uri; do Chris@1563: rm -rf "$subtmp" Chris@1563: revision=$(grep ' '"$dir"'$' "$tmprepo/.hgsubstate" | awk '{ print $1; }') Chris@1563: if [ -n "$target_subdir" ]; then Chris@1563: "$myname" "$tmprepo/$dir" "$subtmp" "$target_subdir/$dir" "$revision" Chris@1563: else Chris@1563: "$myname" "$tmprepo/$dir" "$subtmp" "$dir" "$revision" Chris@1563: fi Chris@1563: ( cd "$target" Chris@1563: hg pull -f "$subtmp" && Chris@1563: hg merge --tool internal:local && Chris@1563: hg commit -m "Merge former subrepo $dir" Chris@1563: ) Chris@1563: done Chris@1563: