annotate treepkg/subversion.py @ 540:f7613aaa6a4e

fix issue if baserev is not a corresponding revision number (changed since kdepim is migrated to git)
author Bjoern Ricks <bricks@intevation.de>
date Tue, 11 Jan 2011 16:04:05 +0000
parents f525825d186e
children 8b49548aa8d4
rev   line source
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
1 # Copyright (C) 2007, 2008, 2009 by Intevation GmbH
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
2 # Authors:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
3 # Bernhard Herzog <bh@intevation.de>
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
4 #
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
7
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
8 """Collection of subversion utility code"""
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
9
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
10 import os
230
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
11 import shutil
273
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
12 import re
282
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
13 import StringIO
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
14
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
15 from lxml import etree
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
16
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
17 import run
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
18 from cmdexpand import cmdexpand
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
19 from util import extract_value_for_key
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
20
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
21
269
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
22 class SubversionError(Exception):
302
020421cd3ee2 Add doc-string to SubversionError
Bernhard Herzog <bh@intevation.de>
parents: 282
diff changeset
23
020421cd3ee2 Add doc-string to SubversionError
Bernhard Herzog <bh@intevation.de>
parents: 282
diff changeset
24 """Base class for subversion specific errors raised by TreePKG"""
020421cd3ee2 Add doc-string to SubversionError
Bernhard Herzog <bh@intevation.de>
parents: 282
diff changeset
25
020421cd3ee2 Add doc-string to SubversionError
Bernhard Herzog <bh@intevation.de>
parents: 282
diff changeset
26
303
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
27 class SubversionUrlMismatchError(SubversionError):
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
28
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
29 """The repository URL does not match the URL of a working copy"""
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
30
269
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
31
262
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
32 def list_url(url):
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
33 """Runs svn list with the given url and returns files listed as a list"""
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
34 output = run.capture_output(cmdexpand("svn list $url", **locals()))
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
35 return output.splitlines()
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
36
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
37 def checkout(url, localdir, revision=None, recurse=True):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
38 """Runs svn to checkout the repository at url into the localdir"""
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
39 args = []
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
40 if revision:
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
41 args.extend(["--revision", revision])
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
42 if not recurse:
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
43 args.append("-N")
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
44 run.call(cmdexpand("svn checkout -q @args $url $localdir", **locals()))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
45
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
46 def update(localdir, revision=None, recurse=True):
79
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
47 """Runs svn update on the localdir.
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
48 The parameter revision, if given, is passed to svn as the value of
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
49 the --revision option.
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
50 """
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
51 args = []
79
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
52 if revision:
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
53 args.extend(["--revision", revision])
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
54 if not recurse:
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
55 args.append("-N")
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
56 run.call(cmdexpand("svn update -q @args $localdir", **locals()))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
57
266
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
58 def export(src, dest, revision=None, recurse=True):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
59 """Runs svn export src dest"""
266
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
60 args = []
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
61 if revision:
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
62 args.extend(["--revision", revision])
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
63 if not recurse:
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
64 args.append("-N")
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
65 run.call(cmdexpand("svn export -q @args $src $dest", **locals()))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
66
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
67 def last_changed_revision(svn_working_copy):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
68 """return the last changed revision of an SVN working copy as an int"""
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
69 # Make sure we run svn under the C locale to avoid localized
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
70 # messages
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
71 env = os.environ.copy()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
72 env["LANG"] = "C"
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
73
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
74 output = run.capture_output(cmdexpand("svn info $svn_working_copy",
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
75 **locals()),
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
76 env=env)
269
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
77 str_rev = extract_value_for_key(output.splitlines(), "Last Changed Rev:")
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
78 if str_rev is None:
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
79 raise SubversionError("Cannot determine last changed revision for %r"
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
80 % svn_working_copy)
333
cbf372f07daa Fixed revision detection by changing Subversion revision numbers
Andre Heinecke <aheinecke@intevation.de>
parents: 331
diff changeset
81 return str_rev
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
82
303
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
83 def svn_url(url_or_working_copy):
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
84 """Returns the URL used for the working copy in svn_working_copy"""
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
85 # Make sure we run svn under the C locale to avoid localized
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
86 # messages
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
87 env = os.environ.copy()
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
88 env["LANG"] = "C"
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
89
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
90 output = run.capture_output(cmdexpand("svn info $url_or_working_copy",
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
91 **locals()),
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
92 env=env)
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
93 return extract_value_for_key(output.splitlines(), "URL:")
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
94
282
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
95 def log_xml(url, base_revision):
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
96 """Return the log in XML of the repository at url from base_revision to HEAD
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
97 """
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
98 args = ["--revision", str(base_revision) + ":HEAD",
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
99 "--verbose",
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
100 "--xml"]
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
101 return run.capture_output(cmdexpand("svn log @args $url", **locals()))
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
102
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
103
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
104 def extract_tag_revisions(xml_log):
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
105 """Extracts the revisions which changed an SVN tag since its creation
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
106 This includes the revision which created the tag and all subsequent
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
107 changes. The xml_log parameter should contain the xml-Version of
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
108 the SVN log of the tag that includes at least the revision that
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
109 created the tag and all the newer revisions.
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
110 """
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
111 tree = etree.parse(StringIO.StringIO(xml_log))
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
112 tag_revisions = tree.xpath("logentry/@revision"
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
113 "[.>=../../logentry/@revision"
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
114 "[../paths/path[@copyfrom-path]]]")
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
115 return tag_revisions
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
116
f58f9adb7dc3 Add functions to get SVN logs and extract tag revisions from it. Add
Bernhard Herzog <bh@intevation.de>
parents: 273
diff changeset
117
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
118
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
119 class SvnRepository(object):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
120
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
121 """Describes a subversion repository"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
122
304
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
123 def __init__(self, url, external_subdirs=(), subset=()):
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
124 """Initialize the subversion repository description
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
125 Parameters:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
126 url -- The url of the repository
304
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
127
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
128 external_subdirs -- A list of subdirectories which are managed
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
129 by svn externals definitions
304
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
130
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
131 subset -- A sequence of (filename, recurse) pairs where
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
132 filename is a filename (usually a directory name)
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
133 relative to url and recurse should be a boolean
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
134 indicating whether checkout filename with recursion.
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
135 If recurse is False, svn checkout/export will be
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
136 called with the -N option.
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
137
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
138 The first item in subset should be for '.', which
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
139 indicates the top-level directory under url. If a
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
140 non-empty subset is given this will usually be
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
141 ('.', False) so that the top-level directory is not
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
142 checked out recursively.
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
143 """
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
144 self.url = url
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
145 self.external_subdirs = external_subdirs
304
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
146 if not subset:
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
147 # default subset is to checkout the top-level directory at
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
148 # URL recursively. Alwas having a subset makes the code
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
149 # simpler
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
150 subset = [(".", True)]
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
151 self.subset = subset
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
152
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
153 def checkout(self, localdir, revision=None):
304
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
154 """Checks out the repository into localdir.
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
155 The revision parameter should be an int and indicates the
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
156 revision to check out or it should be None to indicate that the
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
157 newest version is to be checked out.
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
158 """
304
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
159 base_url = self.url
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
160 if not base_url.endswith("/"):
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
161 base_url += "/"
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
162 subdir, recurse = self.subset[0]
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
163 checkout(base_url + subdir, os.path.join(localdir, subdir),
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
164 revision=revision, recurse=recurse)
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
165 for subdir, recurse in self.subset[1:]:
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
166 update(os.path.join(localdir, subdir), revision=revision,
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
167 recurse=recurse)
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
168 if len(self.subset) > 1 and revision is None:
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
169 # do an additional update on the whole working copy after
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
170 # creating a subset checkout so that svn info will show
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
171 # revision numbers that match the entire working copy
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
172 # (externals are handled elsewhere). The repository might
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
173 # have been changed between the initial checkout of the
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
174 # top-level directory and the updates for the
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
175 # subdirectories.
6cffb43a28ca Add a way to specify svn subset checkouts where only parts of a source
Bernhard Herzog <bh@intevation.de>
parents: 303
diff changeset
176 update(localdir, revision=revision)
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
177
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
178 def export(self, localdir, destdir):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
179 """Exports the working copy in localdir to destdir"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
180 export(localdir, destdir)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
181 for subdir in self.external_subdirs:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
182 absdir = os.path.join(destdir, subdir)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
183 if not os.path.isdir(absdir):
228
d2ddd037ddaf Fix a bug introduced by the subversion interface reorganization
Bernhard Herzog <bh@intevation.de>
parents: 224
diff changeset
184 export(os.path.join(localdir, subdir), absdir)
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
185
311
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
186 def export_tag(self, url, destdir, revision=None):
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
187 """Exports the tag at url to destdir.
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
188 Note: the implementation of this method would work for any URL
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
189 but it really is intended to only be used for URLs to tags of
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
190 the same code as represented by this object.
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
191 """
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
192 base_url = url
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
193 if not base_url.endswith("/"):
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
194 base_url += "/"
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
195 for subdir, recurse in self.subset:
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
196 export(base_url + "/" + subdir, os.path.join(destdir, subdir),
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
197 revision=revision, recurse=recurse)
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
198
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
199 def last_changed_revision(self, localdir):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
200 """Returns the last changed revision of the working copy in localdir"""
343
c0808837fc64 Last changed revision is now again correctly returned as a string
Andre Heinecke <aheinecke@intevation.de>
parents: 342
diff changeset
201 max_rev = max([int(last_changed_revision(os.path.join(localdir, d)))
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
202 for d in [localdir] + list(self.external_subdirs)])
343
c0808837fc64 Last changed revision is now again correctly returned as a string
Andre Heinecke <aheinecke@intevation.de>
parents: 342
diff changeset
203 return str(max_rev)
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
204
303
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
205 def check_working_copy(self, localdir):
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
206 """Checks whether localdir contains a checkout of the
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
207 repository. The check compares the expected URL with the one
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
208 returned by svn info executed in localdir. Raises
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
209 SubversionUrlMismatchError if the URLs do not match.
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
210 """
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
211 localurl = svn_url(localdir)
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
212 expected_url = svn_url(self.url)
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
213 if localurl != expected_url:
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
214 raise SubversionUrlMismatchError("Working copy in %r has URL %r,"
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
215 " expected %r"
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
216 % (localdir, localurl,
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
217 expected_url))
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
218
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
219
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
220 class SvnWorkingCopy(object):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
221
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
222 """Represents a checkout of a subversion repository"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
223
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
224 def __init__(self, repository, localdir, logger=None):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
225 """
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
226 Initialize the working copy.
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
227 Parameters:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
228 repository -- The SvnRepository instance describing the
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
229 repository
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
230 localdir -- The directory for the working copy
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
231 logger -- logging object to use for some info/debug messages
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
232 """
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
233 self.repository = repository
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
234 self.localdir = localdir
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
235 self.logger = logger
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
236
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
237 def log_info(self, *args):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
238 if self.logger is not None:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
239 self.logger.info(*args)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
240
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
241 def update_or_checkout(self, revision=None):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
242 """Updates the working copy or creates by checking out the repository"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
243 if os.path.exists(self.localdir):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
244 self.log_info("Updating the working copy in %r", self.localdir)
303
df01eb4dbfc5 Check the URL of a working copy when updating a track's working copy.
Bernhard Herzog <bh@intevation.de>
parents: 302
diff changeset
245 self.repository.check_working_copy(self.localdir)
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
246 update(self.localdir, revision=revision)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
247 else:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
248 self.log_info("The working copy in %r doesn't exist yet."
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
249 " Checking out from %r",
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
250 self.localdir, self.repository.url)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
251 self.repository.checkout(self.localdir, revision=revision)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
252
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
253 def export(self, destdir):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
254 """Exports the working copy to destdir"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
255 self.repository.export(self.localdir, destdir)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
256
311
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
257 def export_tag(self, url, destdir, revision=None):
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
258 """Exports the tag at url to destdir.
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
259 The URL is expected to point to the same repository as the one
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
260 used by the working copy and is intended to be used when
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
261 exporting tagged versions of the code in the working copy. It's
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
262 a method on the working copy so that the repository description
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
263 including the subset settings are used.
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
264 """
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
265 self.repository.export_tag(url, destdir, revision=revision)
d0acc0614de5 Implement tag exports in the subversion base classes.
Bernhard Herzog <bh@intevation.de>
parents: 304
diff changeset
266
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
267 def last_changed_revision(self):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
268 """Returns the last changed rev of the working copy"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
269 return self.repository.last_changed_revision(self.localdir)
230
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
270
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
271
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
272 class ManualWorkingCopy(object):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
273
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
274 """A manually managed working copy"""
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
275
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
276 def __init__(self, directory):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
277 self.directory = directory
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
278
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
279 def update_or_checkout(self, revision=None, recurse=True):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
280 """This method does nothing"""
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
281 pass
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
282
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
283 def export(self, destdir):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
284 """Copies the entire working copy to destdir"""
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
285 shutil.copytree(self.directory, destdir)
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
286
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
287 def last_changed_revision(self):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
288 """Always returns 0"""
331
e2d04687aa5a last_changed_revision of ManualWorkingCopy now always returns
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
289 return "0"
273
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
290
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
291
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
292 class TagDetector(object):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
293
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
294 """Class to automatically find SVN tags and help package them
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
295
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
296 The tags are found using three parameters:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
297 url -- The base url of the SVN tags directory to use
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
298 pattern -- A regular expression matching the subdirectories to
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
299 consider in the tag directory specified by the url
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
300 subdir -- A subdirectory of the directory matched by pattern to
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
301 export and use to determine revision number
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
302
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
303 The subdir parameter is there to cope with the kdepim enterprise
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
304 tags. The URL for a tag is of the form
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
305 .../tags/kdepim/enterprise4.0.<date>.<rev> . Each such tag has
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
306 subdirectories for kdepim, kdelibs, etc. The url and pattern are
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
307 used to match the URL for the tag, and the subdir is used to select
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
308 which part of the tag is meant.
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
309
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
310 The subdir also determines which SVN directory's revision number is
369
2ecdfa0f345a used full path (baseurl + subdir) for tag detection not only the first subdir
Bjoern Ricks <bricks@intevation.de>
parents: 343
diff changeset
311 used.
273
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
312 """
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
313
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
314 def __init__(self, url, pattern, subdir):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
315 self.url = url
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
316 self.pattern = re.compile(pattern)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
317 self.subdir = subdir
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
318
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
319 def list_tags(self):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
320 matches = []
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
321 if self.url:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
322 for tag in list_url(self.url):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
323 if self.pattern.match(tag.rstrip("/")):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
324 matches.append(tag)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
325 return sorted(matches)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
326
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
327 def newest_tag_revision(self):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
328 """Determines the newest tag revision and returns (tagurl, revno)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
329 If no tag can be found, the method returns the tuple (None, None).
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
330 """
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
331 candidates = self.list_tags()
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
332 urlrev = (None, None)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
333 if candidates:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
334 newest = candidates[-1]
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
335 urlrev = self.determine_revision(self.url + "/" + newest,
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
336 self.subdir)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
337 return urlrev
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
338
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
339 def determine_revision(self, baseurl, subdir):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
340 urlrev = (None, None)
369
2ecdfa0f345a used full path (baseurl + subdir) for tag detection not only the first subdir
Bjoern Ricks <bricks@intevation.de>
parents: 343
diff changeset
341 revision_url = baseurl + "/" + subdir
273
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
342 try:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
343 revision = last_changed_revision(revision_url)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
344 urlrev = (baseurl + "/" + subdir, revision)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
345 except SubversionError:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
346 pass
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
347 return urlrev
525
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
348
540
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
349 def log_xml(self, url):
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
350 """Return the log in XML of the repository since the copy
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
351 """
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
352 args = ["--stop-on-copy",
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
353 "--verbose",
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
354 "--xml"]
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
355 return run.capture_output(cmdexpand("svn log @args $url", **locals()))
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
356
525
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
357 def tag_pkg_parameters(self, tag_url):
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
358 # FIXME: Don't hardcore svn tag path and regex
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
359 match = re.search(r"/enterprise[^.]*\.[^.]*\."
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
360 r"(?P<date>[0-9]{8})\.(?P<baserev>[0-9]+)/",
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
361 tag_url)
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
362 if match:
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
363 date = match.group("date")
540
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
364 # baserev is time since git migration
525
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
365 baserev = match.group("baserev")
540
f7613aaa6a4e fix issue if baserev is not a corresponding revision number
Bjoern Ricks <bricks@intevation.de>
parents: 530
diff changeset
366 xml_log = self.log_xml(tag_url)
530
f525825d186e fix refactoring and remove subversion prefix
Bjoern Ricks <bricks@intevation.de>
parents: 525
diff changeset
367 revisions = extract_tag_revisions(xml_log)
525
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
368 tag_change_count = len(revisions)
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
369 return (date, tag_change_count)
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
370 else:
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
371 raise RuntimeError("Cannot determine tag parameters from %s"
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 369
diff changeset
372 % tag_url)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)