chiark / gitweb /
devscripts (2.10.69+squeeze4) stable-security; urgency=high
[devscripts.git] / scripts / svnpath.pl
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 svnpath - output svn url with support for tags and branches
6
7 =head1 SYNOPSIS
8
9 svnpath
10
11 svnpath tags
12
13 svnpath branches
14
15 svnpath trunk
16
17 =head1 DESCRIPTION
18
19 svnpath is intended to be run in a subversion working copy.
20
21 In its simplest usage, svnpath with no parameters outputs the svn url for
22 the repository associated with the working copy.
23
24 If a parameter is given, svnpath attempts to instead output the url that
25 would be used for the tags, branches, or trunk. This will only work if it's
26 run in the top-level directory that is subject to tagging or branching.
27
28 For example, if you want to tag what's checked into subversion as version
29 1.0, you could use a command like this:
30
31   svn cp $(svnpath) $(svnpath tags)/1.0
32
33 That's much easier than using svn info to look up the repository url and
34 manually modifying it to derive the url to use for the tag, and typing in
35 something like this:
36
37   svn cp svn+ssh://my.server.example/svn/project/trunk svn+ssh://my.server.example/svn/project/tags/1.0
38
39 svnpath uses a simple heuristic to convert between the trunk, tags, and
40 branches paths. It replaces the first occurrence of "trunk", "tags", or
41 "branches" with the name of what you're looking for. This will work ok for
42 most typical subversion repository layouts.
43
44 If you have an atypical layout and it does not work, you can add a
45 ~/.svnpath file. This file is perl code, which can modify the path in $url.
46 For example, the author uses this file:
47
48  #!/usr/bin/perl
49  # svnpath personal override file
50
51  # For d-i I sometimes work from a full d-i tree branch. Remove that from
52  # the path to get regular tags or branches directories.
53  $url=~s!d-i/(rc|beta)[0-9]+/!!;
54  $url=~s!d-i/sarge/!!;
55  1
56
57 =cut
58
59 $ENV{LANG}="C";
60
61 my $wanted=shift;
62 my $path=shift;
63
64 if (length $path) {
65         chdir $path || die "$path: unreadable\n";
66 }
67
68 our $url;
69 if (-d ".svn") {
70         # Get the svn url of the current directory.
71         $url = `svn info .| grep -i ^URL: | cut -d ' ' -f 2`;
72 }
73 else {
74         # Try svk instead.
75         $url = `svk info .| grep -i '^Depot Path:' | cut -d ' ' -f 3`;
76 }
77
78 if (! length $url) {
79         die "cannot get url";
80 }
81
82 if (length $wanted) {
83         # Now jut substitute into it.
84         $url=~s!/(?:trunk|branches|tags)($|/)!/$wanted$1!;
85
86         if (-e "$ENV{HOME}/.svnpath") {
87                 require "$ENV{HOME}/.svnpath";
88         }
89 }
90
91 print $url;
92
93 =head1 LICENSE
94
95 GPL version 2 or later
96
97 =head1 AUTHOR
98
99 Joey Hess <joey@kitenet.net>
100
101 =cut