aboutsummaryrefslogtreecommitdiff
path: root/server/mrrepo
diff options
context:
space:
mode:
Diffstat (limited to 'server/mrrepo')
-rwxr-xr-xserver/mrrepo102
1 files changed, 64 insertions, 38 deletions
diff --git a/server/mrrepo b/server/mrrepo
index 1bb3989..056d101 100755
--- a/server/mrrepo
+++ b/server/mrrepo
@@ -16,6 +16,13 @@
# file. This file should be placed next to and will be sourced by the mrrepo
# script (remember to adjust its permissions).
#
+# If the remote repositories mirroring is enabled (<host> argument is
+# specified), then consider all subdirectories of <path> with the .git
+# extension, except for the local repositories, old mirrored remote
+# repositories and remove them. Note that a git repository is local if it is
+# referred to in the local manifest (public) or doesn't contain the
+# git-daemon-export-ok file (private).
+#
# The manifest file line format (lines starting with # are ignored):
#
# <repository-path>[ <remote-mirror-url>]
@@ -40,7 +47,7 @@
#
# runuser -u scm -- /var/scm/mrrepo -s -v git.example.org /var/scm
#
-usage="usage: $0 [-v] [-s] <host> <path>"
+usage="usage: $0 [-v] [-s] [<host>] <path>"
owd="$(pwd)"
trap "{ cd '$owd'; exit 1; }" ERR
@@ -65,19 +72,34 @@ while [ "$#" -gt 0 ]; do
shift
;;
*)
- if [ -z "$host" ]; then
- host="$1"
- elif [ -z "$path" ]; then
- path="${1%/}"
- else
- error "$usage"
- fi
- shift
+ break; # The end of options is encountered.
;;
esac
done
-if [ -z "$host" -o -z "$path" ]; then
+# Parse the command line arguments.
+#
+if [ "$#" -lt 1 -o "$#" -gt 2 ]; then
+ error "$usage"
+fi
+
+# Host.
+#
+if [ "$#" -gt 1 ]; then
+ host="$1"
+ shift
+
+ if [ -z "$host" ]; then
+ error "$usage"
+ fi
+fi
+
+# Repositories directory.
+#
+path="${1%/}"
+shift
+
+if [ -z "$path" ]; then
error "$usage"
fi
@@ -121,8 +143,6 @@ function fetch () # <url> [<curl-options>]
curl "${curl_ops[@]}" "$@" "$u"
}
-fetch "$prot://$host/manifest" -z remote.manifest -o remote.manifest
-
function manifest_filter () # <file>
{
sed -e '/^\s*#/d;/^\s*$/d;s/\s\s*/ /g' "$1"
@@ -169,18 +189,22 @@ function push_add () # <rep> <url>
push_auth["$r"]="$u"
}
-while read l || [ -n "$l" ]; do
- r=$(manifest_field "$l" 1 'path')
- u=$(manifest_field "$l" 2)
+if [ -n "$host" ]; then
+ fetch "$prot://$host/manifest" -z remote.manifest -o remote.manifest
+
+ while read l || [ -n "$l" ]; do
+ r=$(manifest_field "$l" 1 'path')
+ u=$(manifest_field "$l" 2)
- remote+=("$r")
+ remote+=("$r")
- # If the push URL is specified then add it to auth/orig maps.
- #
- if [ -n "$u" ]; then
- push_add "$r" "$u"
- fi
-done < <(manifest_filter remote.manifest)
+ # If the push URL is specified then add it to auth/orig maps.
+ #
+ if [ -n "$u" ]; then
+ push_add "$r" "$u"
+ fi
+ done < <(manifest_filter remote.manifest)
+fi
# Find all the existing repositories (directories that end with .git) and sort
# them out into mirrored and local public. Note that local private will end up
@@ -202,7 +226,7 @@ if test -f manifest; then
for i in "${remote[@]}"; do
if [ "$i" = "$r" ]; then
- error "attempt to mirror into local public repository $r"
+ error "attempt to mirror into local public repository $r"
fi
done
@@ -217,23 +241,25 @@ if test -f manifest; then
# Everything that is not in local is mirrored (or local private).
#
- for r in "${all[@]}"; do
-
- for i in "${local[@]}"; do
- if [ "$i" = "$r" ]; then
- if [ "$verb" -ge 1 ]; then
- info "local public repository $r"
- fi
- r=
- break
+ if [ -n "$host" ]; then
+ for r in "${all[@]}"; do
+
+ for i in "${local[@]}"; do
+ if [ "$i" = "$r" ]; then
+ if [ "$verb" -ge 1 ]; then
+ info "local public repository $r"
+ fi
+ r=
+ break
+ fi
+ done
+
+ if [ -n "$r" ]; then
+ mirror+=("$r")
fi
done
-
- if [ -n "$r" ]; then
- mirror+=("$r")
- fi
- done
-else
+ fi
+elif [ -n "$host" ]; then
mirror=("${all[@]}")
fi