167
166
spectype.__name__, spec)
168
167
return spectype(spec, _internal=True)
169
for spectype in SPEC_TYPES:
170
if spec.startswith(spectype.prefix):
171
trace.mutter('Returning RevisionSpec %s for %s',
172
spectype.__name__, spec)
173
return spectype(spec, _internal=True)
170
174
# Otherwise treat it as a DWIM, build the RevisionSpec object and
171
175
# wait for _match_on to be called.
172
176
return RevisionSpec_dwim(spec, _internal=True)
313
312
"""Run the lookup and see what we can get."""
315
314
# First, see if it's a revno
316
if self._revno_regex.match(self.spec) is not None:
316
if _revno_regex is None:
317
_revno_regex = re.compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
318
if _revno_regex.match(self.spec) is not None:
318
320
return self._try_spectype(RevisionSpec_revno, branch)
319
321
except RevisionSpec_revno.dwim_catchable_exceptions:
322
324
# Next see what has been registered
323
for objgetter in self._possible_revspecs:
324
rs_class = objgetter.get_obj()
326
return self._try_spectype(rs_class, branch)
327
except rs_class.dwim_catchable_exceptions:
330
# Try the old (deprecated) dwim list:
331
325
for rs_class in dwim_revspecs:
333
327
return self._try_spectype(rs_class, branch)
339
333
# really relevant.
340
334
raise errors.InvalidRevisionSpec(self.spec, branch)
343
def append_possible_revspec(cls, revspec):
344
"""Append a possible DWIM revspec.
346
:param revspec: Revision spec to try.
348
cls._possible_revspecs.append(registry._ObjectGetter(revspec))
351
def append_possible_lazy_revspec(cls, module_name, member_name):
352
"""Append a possible lazily loaded DWIM revspec.
354
:param module_name: Name of the module with the revspec
355
:param member_name: Name of the revspec within the module
357
cls._possible_revspecs.append(
358
registry._LazyObjectGetter(module_name, member_name))
361
337
class RevisionSpec_revno(RevisionSpec):
362
338
"""Selects a revision using a number."""
491
460
prefix = 'revid:'
493
def _as_revision_id(self, context_branch):
462
def _match_on(self, branch, revs):
494
463
# self.spec comes straight from parsing the command line arguments,
495
464
# so we expect it to be a Unicode string. Switch it to the internal
496
465
# representation.
466
revision_id = osutils.safe_revision_id(self.spec, warn=False)
467
return RevisionInfo.from_revision_id(branch, revision_id, revs)
469
def _as_revision_id(self, context_branch):
497
470
return osutils.safe_revision_id(self.spec, warn=False)
840
813
revision_b = other_branch.last_revision()
841
814
if revision_b in (None, revision.NULL_REVISION):
842
815
raise errors.NoCommits(other_branch)
844
branch = other_branch
847
# pull in the remote revisions so we can diff
848
branch.fetch(other_branch, revision_b)
849
except errors.ReadOnlyError:
850
branch = other_branch
816
# pull in the remote revisions so we can diff
817
branch.fetch(other_branch, revision_b)
852
819
revno = branch.revision_id_to_revno(revision_b)
853
820
except errors.NoSuchRevision:
923
884
self._get_submit_location(context_branch))
926
class RevisionSpec_annotate(RevisionIDSpec):
930
help_txt = """Select the revision that last modified the specified line.
932
Select the revision that last modified the specified line. Line is
933
specified as path:number. Path is a relative path to the file. Numbers
934
start at 1, and are relative to the current version, not the last-
935
committed version of the file.
938
def _raise_invalid(self, numstring, context_branch):
939
raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
940
'No such line: %s' % numstring)
942
def _as_revision_id(self, context_branch):
943
path, numstring = self.spec.rsplit(':', 1)
945
index = int(numstring) - 1
947
self._raise_invalid(numstring, context_branch)
948
tree, file_path = workingtree.WorkingTree.open_containing(path)
951
file_id = tree.path2id(file_path)
953
raise errors.InvalidRevisionSpec(self.user_spec,
954
context_branch, "File '%s' is not versioned." %
956
revision_ids = [r for (r, l) in tree.annotate_iter(file_id)]
960
revision_id = revision_ids[index]
962
self._raise_invalid(numstring, context_branch)
963
if revision_id == revision.CURRENT_REVISION:
964
raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
965
'Line %s has not been committed.' % numstring)
969
class RevisionSpec_mainline(RevisionIDSpec):
971
help_txt = """Select mainline revision that merged the specified revision.
973
Select the revision that merged the specified revision into mainline.
978
def _as_revision_id(self, context_branch):
979
revspec = RevisionSpec.from_string(self.spec)
980
if revspec.get_branch() is None:
981
spec_branch = context_branch
983
spec_branch = _mod_branch.Branch.open(revspec.get_branch())
984
revision_id = revspec.as_revision_id(spec_branch)
985
graph = context_branch.repository.get_graph()
986
result = graph.find_lefthand_merger(revision_id,
987
context_branch.last_revision())
989
raise errors.InvalidRevisionSpec(self.user_spec, context_branch)
993
887
# The order in which we want to DWIM a revision spec without any prefix.
994
888
# revno is always tried first and isn't listed here, this is used by
995
889
# RevisionSpec_dwim._match_on
996
dwim_revspecs = symbol_versioning.deprecated_list(
997
symbol_versioning.deprecated_in((2, 4, 0)), "dwim_revspecs", [])
891
RevisionSpec_tag, # Let's try for a tag
892
RevisionSpec_revid, # Maybe it's a revid?
893
RevisionSpec_date, # Perhaps a date?
894
RevisionSpec_branch, # OK, last try, maybe it's a branch
999
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_tag)
1000
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_revid)
1001
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_date)
1002
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_branch)
1004
898
revspec_registry = registry.Registry()
1005
899
def _register_revspec(revspec):
1014
908
_register_revspec(RevisionSpec_ancestor)
1015
909
_register_revspec(RevisionSpec_branch)
1016
910
_register_revspec(RevisionSpec_submit)
1017
_register_revspec(RevisionSpec_annotate)
1018
_register_revspec(RevisionSpec_mainline)
912
# classes in this list should have a "prefix" attribute, against which
913
# string specs are matched
914
SPEC_TYPES = symbol_versioning.deprecated_list(
915
symbol_versioning.deprecated_in((1, 12, 0)), "SPEC_TYPES", [])