Rev 3968: (Jelmer) Use registry for revision specifiers. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Jan 28 21:57:15 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3968
revision-id: pqm at pqm.ubuntu.com-20090128215712-i4lsbqdybozsp19x
parent: pqm at pqm.ubuntu.com-20090128174048-jd8qlat97q8m0c5q
parent: jelmer at samba.org-20090128184255-bdmklkvm83ltk191
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-01-28 21:57:12 +0000
message:
(Jelmer) Use registry for revision specifiers.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
bzrlib/revisionspec.py revisionspec.py-20050907152633-17567659fd5c0ddb
------------------------------------------------------------
revno: 3966.2.3
revision-id: jelmer at samba.org-20090128184255-bdmklkvm83ltk191
parent: jelmer at samba.org-20090128184034-a05b5cs8fwdwoasd
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: bzr.dev
timestamp: Wed 2009-01-28 19:42:55 +0100
message:
Update NEWS
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
------------------------------------------------------------
revno: 3966.2.2
revision-id: jelmer at samba.org-20090128184034-a05b5cs8fwdwoasd
parent: jelmer at samba.org-20090128152813-15xt6nhb9s8e1kmp
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: bzr.dev
timestamp: Wed 2009-01-28 19:40:34 +0100
message:
Add backwards compatibility copy of SPEC_TYPES.
modified:
bzrlib/revisionspec.py revisionspec.py-20050907152633-17567659fd5c0ddb
------------------------------------------------------------
revno: 3966.2.1
revision-id: jelmer at samba.org-20090128152813-15xt6nhb9s8e1kmp
parent: pqm at pqm.ubuntu.com-20090128105451-ih99x6vzhtmfysjf
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: lazy-revspecs
timestamp: Wed 2009-01-28 16:28:13 +0100
message:
Register revision specifiers in a registry.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
bzrlib/revisionspec.py revisionspec.py-20050907152633-17567659fd5c0ddb
=== modified file 'NEWS'
--- a/NEWS 2009-01-28 14:27:39 +0000
+++ b/NEWS 2009-01-28 21:57:12 +0000
@@ -97,6 +97,11 @@
* ForeignVcsMapping.show_foreign_revid() has been moved to
ForeignVcs. (Jelmer Vernooij)
+ * Revision specifiers are now registered in
+ ``bzrlib.revisionspec.revspec_registry``, and the old list of
+ revisionspec classes (``bzrlib.revisionspec.SPEC_TYPES``) has been
+ deprecated. (Jelmer Vernooij, #321183)
+
* The progress and UI classes have changed; the main APIs remain the
same but code that provides a new UI or progress bar class may
need to be updated. (Martin Pool)
=== modified file 'bzrlib/help_topics/__init__.py'
--- a/bzrlib/help_topics/__init__.py 2009-01-20 04:03:38 +0000
+++ b/bzrlib/help_topics/__init__.py 2009-01-28 15:28:13 +0000
@@ -179,7 +179,7 @@
# The help text is indented 4 spaces - this re cleans that up below
indent_re = re.compile(r'^ ', re.MULTILINE)
- for i in bzrlib.revisionspec.SPEC_TYPES:
+ for prefix, i in bzrlib.revisionspec.revspec_registry.iteritems():
doc = i.help_txt
if doc == bzrlib.revisionspec.RevisionSpec.help_txt:
summary = "N/A"
=== modified file 'bzrlib/revisionspec.py'
--- a/bzrlib/revisionspec.py 2009-01-22 13:58:18 +0000
+++ b/bzrlib/revisionspec.py 2009-01-28 18:40:34 +0000
@@ -26,6 +26,7 @@
from bzrlib import (
errors,
osutils,
+ registry,
revision,
symbol_versioning,
trace,
@@ -114,7 +115,6 @@
# classes in this list should have a "prefix" attribute, against which
# string specs are matched
-SPEC_TYPES = []
_revno_regex = None
@@ -153,12 +153,18 @@
if spec is None:
return RevisionSpec(None, _internal=True)
- for spectype in SPEC_TYPES:
- if spec.startswith(spectype.prefix):
+ match = revspec_registry.get_prefix(spec)
+ if match is not None:
+ spectype, specsuffix = match
+ trace.mutter('Returning RevisionSpec %s for %s',
+ spectype.__name__, spec)
+ return spectype(spec, _internal=True)
+ else:
+ for spectype in SPEC_TYPES:
trace.mutter('Returning RevisionSpec %s for %s',
spectype.__name__, spec)
- return spectype(spec, _internal=True)
- else:
+ if spec.startswith(spectype.prefix):
+ return spectype(spec, _internal=True)
# RevisionSpec_revno is special cased, because it is the only
# one that directly handles plain integers
# TODO: This should not be special cased rather it should be
@@ -393,7 +399,6 @@
# Old compatibility
RevisionSpec_int = RevisionSpec_revno
-SPEC_TYPES.append(RevisionSpec_revno)
class RevisionSpec_revid(RevisionSpec):
@@ -421,7 +426,6 @@
def _as_revision_id(self, context_branch):
return osutils.safe_revision_id(self.spec, warn=False)
-SPEC_TYPES.append(RevisionSpec_revid)
class RevisionSpec_last(RevisionSpec):
@@ -473,7 +477,6 @@
revno, revision_id = self._revno_and_revision_id(context_branch, None)
return revision_id
-SPEC_TYPES.append(RevisionSpec_last)
class RevisionSpec_before(RevisionSpec):
@@ -548,7 +551,6 @@
'No parents for revision.')
return parents[0]
-SPEC_TYPES.append(RevisionSpec_before)
class RevisionSpec_tag(RevisionSpec):
@@ -570,7 +572,6 @@
def _as_revision_id(self, context_branch):
return context_branch.tags.lookup_tag(self.spec)
-SPEC_TYPES.append(RevisionSpec_tag)
class _RevListToTimestamps(object):
@@ -677,7 +678,6 @@
else:
return RevisionInfo(branch, rev + 1)
-SPEC_TYPES.append(RevisionSpec_date)
class RevisionSpec_ancestor(RevisionSpec):
@@ -745,7 +745,6 @@
branch.unlock()
-SPEC_TYPES.append(RevisionSpec_ancestor)
class RevisionSpec_branch(RevisionSpec):
@@ -794,7 +793,6 @@
raise errors.NoCommits(other_branch)
return other_branch.repository.revision_tree(last_revision)
-SPEC_TYPES.append(RevisionSpec_branch)
class RevisionSpec_submit(RevisionSpec_ancestor):
@@ -839,4 +837,19 @@
self._get_submit_location(context_branch))
-SPEC_TYPES.append(RevisionSpec_submit)
+revspec_registry = registry.Registry()
+def _register_revspec(revspec):
+ revspec_registry.register(revspec.prefix, revspec)
+
+_register_revspec(RevisionSpec_revno)
+_register_revspec(RevisionSpec_revid)
+_register_revspec(RevisionSpec_last)
+_register_revspec(RevisionSpec_before)
+_register_revspec(RevisionSpec_tag)
+_register_revspec(RevisionSpec_date)
+_register_revspec(RevisionSpec_ancestor)
+_register_revspec(RevisionSpec_branch)
+_register_revspec(RevisionSpec_submit)
+
+SPEC_TYPES = symbol_versioning.deprecated_list(
+ symbol_versioning.deprecated_in((1, 12, 0)), "SPEC_TYPES", [])
More information about the bazaar-commits
mailing list