added "fileurl", bug fixed "svn-clone"
[xrzperl.git] / svn-clone
blob0da2b2b158b043c9f7b7d3df2df0310ac7a5574d
1 #!/usr/bin/perl -w
2 # $Id$
3 use strict;
4 require v5.10.0;
5 our $VERSION = 'v0.1';
7 BEGIN
9 our $PROGRAM_DIR = $ENV{XR_PERL_SOURCE_DIR};
10 unless($PROGRAM_DIR) {
11 $PROGRAM_DIR = $0;
12 $PROGRAM_DIR =~ s/[^\/\\]+$//;
13 $PROGRAM_DIR =~ s/\/+$//;
14 $PROGRAM_DIR = "." unless($PROGRAM_DIR);
16 unshift @INC,
17 map "$PROGRAM_DIR/$_",qw{modules lib ../modules ..lib};
20 my %OPTS;
21 my @OPTIONS = qw/help|h|? version|ver edit-me manual|man/;
23 if(@ARGV)
25 require Getopt::Long;
26 require MyPlace::Usage;
27 Getopt::Long::GetOptions(\%OPTS,@OPTIONS);
28 MyPlace::Usage::Process(\%OPTS,$VERSION);
30 else
32 require MyPlace::Usage;
33 MyPlace::Usage::PrintHelp();
34 exit 0;
37 sub run {
38 my $exit = system(@_);
39 die("fatal error: $! while executing [",join(" ",@_),"]\n") if($exit);
40 return 1;
43 my $SOURCE = shift;
44 my $DEST = shift;
45 my $source_user = shift;
46 my $sync_user = shift;
47 use Cwd qw/getcwd/;
48 my $is_localsource = 1;
49 my $is_localdest = 1;
51 my $cwd = getcwd;
52 if(!$DEST) {
53 $DEST = $cwd;
55 elsif($DEST =~ m/:\/\//) {
56 $is_localdest = undef;
58 elsif($DEST =~ m/\//) {
60 else {
61 $DEST = $cwd . '/' . $DEST;
63 if($SOURCE =~ m/:\/\//) {
64 $is_localsource = undef;
66 elsif($SOURCE =~ m/\//) {
68 else {
69 $SOURCE = $cwd . '/' . $SOURCE;
72 my $SOURCE_URL = $is_localsource ? 'file://' . $SOURCE : $SOURCE;
73 my $DEST_URL;
74 if($is_localdest) {
75 $DEST_URL = 'file://' . $DEST;
76 if(! -d $DEST) {
77 print STDERR "creating local repository $DEST...\n";
78 run(qw/svnadmin create/,$DEST);
79 my $hook = "$DEST/hooks/pre-revprop-change";
80 print STDERR "creating pre-revprop-change hook in $DEST...\n";
81 open FO,'>',$hook or die("fatal error\n");
82 print FO "#!/bin/sh\nexit 0\n";
83 close FO;
84 run(qw/chmod a+x/,$hook);
87 else {
88 $DEST_URL = $DEST;
91 my @svnsync;
92 if($source_user and $sync_user) {
93 @svnsync = ('svnsync','--source-username',$source_user,'--sync-username',$sync_user);
95 elsif($source_user) {
96 @svnsync = ('svnsync','--username',$source_user);
98 else {
99 @svnsync = ('svnsync');
101 print STDERR "initializing svnsync...\n";
102 print STDERR "from\t$SOURCE_URL\n";
103 print STDERR "to \t$DEST_URL\n";
104 run(@svnsync,'init',$DEST_URL,$SOURCE_URL);
105 print STDERR "start syncing...\n";
106 run(@svnsync,'sync',$DEST_URL);
107 exit 0;
111 __END__
113 =pod
115 =head1 NAME
117 svn-clone - clone subversion repository
119 =head1 SYNOPSIS
121 svn-clone [options] <SOURCE_REPO> [DEST_REPO]
123 =head1 OPTIONS
125 =over 12
127 =item B<--version>
129 Print version infomation.
131 =item B<-h>,B<--help>
133 Print a brief help message and exits.
135 =item B<--manual>,B<--man>
137 View application manual
139 =item B<--edit-me>
141 Invoke 'editor' against the source
143 =back
145 =head1 DESCRIPTION
147 ___DESC___
149 =head1 CHANGELOG
151 2010-11-19 03:13 xiaoranzzz <xiaoranzzz@myplace.hell>
153 * file created.
155 =head1 AUTHOR
157 xiaoranzzz <xiaoranzzz@myplace.hell>
159 =cut
161 # vim:filetype=perl