3 print_usage () { cat <<'END'
5 to move repository directory, cd to anywhere and
6 cvs-repomove --move local-repo module hostname remote-repo
7 cvs-repomove --move src-hostname src-repo module dst-hostname dst-repo
8 to adjust CVS/Root afterwards, in each working directory
9 cvs-repomove automatically update **/CVS/Root
13 # We do things in the following order:
15 # 0. Check things @/..moving-to none/..moved-to
16 # 1. Rename src repo to prevent commits etc. ..moving-to none/..moved-to
17 # 2. Make temporary copy at destination ..moving-to ..tmp
18 # 3. Install temporary copy at destination ..moving-to @
19 # 4. Move aside src repo ..moved-to @
21 fail () { echo >&2 "error: $1"; exit 8; }
22 bad_usage () { echo >&2 "bad usage: $1"; print_usage >&2; exit 12; }
26 while [ $# -gt 0 ]; do
29 --help) print_usage; exit 0 ;;
31 -*) bad_usage "unknown option $1" ;;
42 "moving a module with \`..' in its name is not supported" ;;
44 "moving a subdirectory is not supported" ;;
46 "moving a module whose name starts with \`-' is not supported" ;;
52 /*|.*|-*) fail "bad hostname $dsthost" ;;
56 check_remote_path () {
58 *[^0-9a-zA-Z/._+,-]*) fail \
59 "pathname may not contain metacharacters, sorry" ;;
65 check_hostname "$srchost"
66 check_hostname "$dsthost"
67 check_remote_path "$srcrepo/$module"
68 check_remote_path "$dstrepo/$module"
72 *) bad_usage "destination repo path must be absolute" ;;
75 printf "moving module %s from %s:%s to %s:%s\n" \
76 "$module" "$srchost" "$srcrepo" "$dsthost" "$dstrepo"
78 mn "checking existing repository"
79 "$CVS_RSH" "$srchost" bash -ec "'
80 ls -d -- $srcrepo/CVSROOT >/dev/null
83 dstrepotrans="$(printf "%s" "$dstrepo" | tr / :)"
84 movingto="moving-to-$dsthost:$dstrepotrans"
85 resume="$("$CVS_RSH" "$srchost" bash -ec "'
86 if test -d $srcrepo/$module..$movingto; then
87 echo >&2 \" resuming previous attempt at a move\"
89 if test -d $srcrepo/$module; then
90 echo >&2 \"but $srcrepo/$module exists too\"
95 ls -d -- $srcrepo/$module >/dev/null
98 previously=\"$(ls -d -- $srcrepo/$module..moved-to-* 2>/dev/null)\"
100 if [ \"x\$previously\" != x ]; then
101 echo >&2 \" btw, module was once before moved away from here\"
102 mv -- \"\$previously\" \
103 \"\${previously/..moved-to-/..previously-\$(date +%s)-moved-to-}\"
108 mn "checking dst repository"
109 "$CVS_RSH" "$dsthost" bash -ec "'
111 ls -d CVSROOT >/dev/null
112 if test -d $dstrepo/$module; then
113 echo >&2 module already exists in destination repo
116 for f in $module..*; do
119 echo \" btw, module was previously at destn repo\"
121 \"\${f/..moved-to-/..previously-\$(date +%s)-moved-to-}\"
125 echo \" nb: possibly-stale temp/partial copy \$f\"
130 echo >&2 \"error: found unexpected subdir \$f\"
138 "$CVS_RSH" "$srchost" bash -ec "'
139 mv -- $srcrepo/$module $srcrepo/$module..$movingto
143 mn "transferring repo data"
144 tmpid="tmp-$(uname -n).$(date +%s)"
145 "$CVS_RSH" "$srchost" bash -ec "'
146 tar -c -C $srcrepo/$module..$movingto -f - .
147 '" | "$CVS_RSH" "$dsthost" bash -ec "'
149 mkdir $module..$tmpid
151 tar --no-same-owner -xf -
153 test "${PIPESTATUS[*]}" = "0 0"
155 mn "confirming move at destination repo"
156 "$CVS_RSH" "$dsthost" bash -ec "'
158 mv $module..$tmpid $module
161 mn "confirming move at source repo"
162 "$CVS_RSH" "$srchost" bash -ec "'
163 mv -- $srcrepo/$module..$movingto \
164 $srcrepo/$module..moved-to-$dsthost:$dstrepotrans
166 echo "module moved successfully"
169 compute_fqdn_data () {
170 fqdn_data="$(adnshost -s - "$1" 2>/dev/null || true)"
174 module="$(cat CVS/Repository)"
175 oldroot="$(cat CVS/Root)"
178 printf "checking/updating repo for %s\n" "$module"
179 compute_fqdn_data "$(uname -n)"
180 our_fqdn_data="$fqdn_data"
183 mn "chasing geese at $goose"
186 remotehost="${goose%%:*}"
188 check_hostname "$remotehost"
189 check_remote_path "$path/$module"
191 compute_fqdn_data "$remotehost"
192 if [ "x$fqdn_data" = "x$our_fqdn_data" -a \
193 "x$fqdn_data" != x ]; then
199 fail "unknown remote repository string $goose"
206 fail "unknown repository string $goose"
211 if test -d $module; then echo good; exit 0; fi
212 if ls -d $module..moved-to-* 2>/dev/null; then exit 0; fi
216 new_goose_info="$("$CVS_RSH" "$remotehost" \
217 bash -ec "'$check'")"
219 new_goose_info="$( bash -ec "$check")"
221 case "$new_goose_info" in
226 echo >&2 "trail went cold at $goose"
230 goose="$(printf "%s" \
231 "${new_goose_info#*..moved-to-}" | \
232 tr : / | sed -e 's,/,:,')"
236 if [ "x$goose" = "x$oldroot" ]; then
237 echo 'repo has not moved - nothing to do'
240 mn "found new repo, adjusting working tree"
241 cvs-adjustroot "$oldroot" "$goose"
242 echo 'working tree adjustment completed'
247 srchost="$(hostname -f)"; srcrepo="$1"
249 dsthost="$3"; dstrepo="$4"
250 elif [ $# = 5 ]; then
251 srchost="$1"; srcrepo="$2"
253 dsthost="$4"; dstrepo="$5"
255 bad_usage "--move needs hostname(s) and paths"
259 [ "$#" = 0 ] || bad_usage "without --move, give no arguments"