annotate extra/soundsoftware/flatten.sh @ 1628:9c5f8e24dadc live tip

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