-
Notifications
You must be signed in to change notification settings - Fork 1
/
revspec.py
104 lines (87 loc) · 3.74 KB
/
revspec.py
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
# Copyright (C) 2007-2009 Jelmer Vernooij <jelmer@samba.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Custom revision specifier for Subversion."""
from __future__ import absolute_import
from breezy import version_info as breezy_version
from breezy.errors import (
InvalidRevisionId,
NoSuchRevision,
)
try:
from breezy.revisionspec import InvalidRevisionSpec
except ImportError: # brz < 3.2
from breezy.errors import InvalidRevisionSpec
from breezy.revisionspec import (
RevisionSpec,
RevisionInfo,
)
from . import lazy_check_versions
from .mapping import mapping_registry
class RevisionSpec_svn(RevisionSpec):
"""Selects a revision using a Subversion revision number."""
help_txt = """Selects a revision using a Subversion revision number (revno).
Subversion revision numbers are per-repository whereas Bazaar revision
numbers are per-branch. This revision specifier allows specifying
a Subversion revision number.
"""
prefix = 'svn:'
def _get_revnum(self):
loc = self.spec.find(':')
return int(self.spec[loc+1:])
def _create_revinfo(self, branch, revid):
if breezy_version < (2, 5):
history = branch.revision_history()
return RevisionInfo.from_revision_id(branch, revid, history)
else:
return RevisionInfo.from_revision_id(branch, revid)
def _match_on_foreign(self, branch):
ret = set()
try:
revnum = self._get_revnum()
except ValueError:
raise InvalidRevisionSpec(self.user_spec, branch)
with branch.lock_read():
graph = branch.repository.get_graph()
for revid, _ in graph.iter_ancestry([branch.last_revision()]):
try:
(found_uuid, found_branch_path, found_revnum), found_mapping = \
mapping_registry.parse_revision_id(revid)
if found_revnum == revnum:
return self._create_revinfo(branch, revid)
ret.add(revid)
except InvalidRevisionId:
continue
raise InvalidRevisionSpec(self.user_spec, branch)
def _match_on_native(self, branch):
try:
if breezy_version < (2, 5):
return RevisionInfo.from_revision_id(branch,
branch.generate_revision_id(self._get_revnum()),
branch.revision_history())
else:
return RevisionInfo.from_revision_id(branch,
branch.generate_revision_id(self._get_revnum()))
except ValueError:
raise InvalidRevisionSpec(self.user_spec, branch)
except NoSuchRevision:
raise InvalidRevisionSpec(self.user_spec, branch)
def _match_on(self, branch, revs):
lazy_check_versions()
uuid = getattr(branch.repository, 'uuid', None)
if uuid is not None:
return self._match_on_native(branch)
return self._match_on_foreign(branch)
def needs_branch(self):
return True
def get_branch(self):
return None