-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvn-mirror
executable file
·106 lines (84 loc) · 2.02 KB
/
svn-mirror
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
# svn-mirror --- Keep local mirror of remote svn server
# Created: 2010-03-03
# Public domain
# $Id: svn-mirror,v 1.1 2011/01/18 04:02:21 friedman Exp $
# Commentary:
# Code:
get_dst_url()
{
set : ${1%/}; shift # remove any trailing /
case $1 in
/* ) echo file://$1 ;;
'' ) echo file://`pwd` ;;
* ) echo file://`cd "$1" && pwd` ;;
esac
}
get_src_url()
{
svnlook propget --revprop -r0 "$1" svn:sync-from-url
}
set_src_url()
{
local dst_url=`get_dst_url "$1"`
local old_src_url=`get_src_url "$1"`
case $2 in
$old_src_url )
echo Source URL unchanged from $old_src_url
return 0 ;;
esac
if svn propset --revprop -r0 svn:sync-from-url "$2" "$dst_url"; then
echo "Old URL: $old_src_url"
echo "New URL: $2"
fi
}
svn_setup()
{
local dst_dir=$1
local src_url=$2
svnadmin create "$dst_dir"
echo '#!/bin/sh' > "$dst_dir/hooks/pre-revprop-change"
chmod a+x "$dst_dir/hooks/pre-revprop-change"
local dst_url=`get_dst_url "$dst_dir"`
svnsync init "$dst_url" "$src_url"
}
svn_sync()
{
local dst_url=`get_dst_url "$1"`
svnsync sync "$dst_url"
}
usage()
{
progname=${0##*/}
{
case $# in
0 ) : ;;
* ) echo "$progname: $*"; echo ;;
esac
echo "Usage: $progname [path to local repository] {remote svn url}"
echo
echo If the local repository is already present, the url is not required
echo and the local repository will just be brought up to date.
} 1>&2
exit 1
}
main()
{
case $# in
1|2 ) : ;;
* ) usage ;;
esac
local dst_dir=$1
local src_url=$2
if [ ! -d "$dst_dir/db" ]; then
case $src_url in
'' ) usage "Need to specify URL to mirror." ;;
esac
svn_setup "$dst_dir" "$src_url"
elif [ -n "$src_url" ]; then
set_src_url "$dst_dir" "$src_url"
fi
svn_sync "$dst_dir"
}
main "$@"
# eof