166
172
spectype.__name__, spec)
167
173
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)
174
175
# Otherwise treat it as a DWIM, build the RevisionSpec object and
175
176
# wait for _match_on to be called.
176
177
return RevisionSpec_dwim(spec, _internal=True)
447
class RevisionSpec_revid(RevisionSpec):
448
class RevisionIDSpec(RevisionSpec):
450
def _match_on(self, branch, revs):
451
revision_id = self.as_revision_id(branch)
452
return RevisionInfo.from_revision_id(branch, revision_id, revs)
455
class RevisionSpec_revid(RevisionIDSpec):
448
456
"""Selects a revision using the revision id."""
450
458
help_txt = """Selects a revision using the revision id.
460
468
prefix = 'revid:'
462
def _match_on(self, branch, revs):
470
def _as_revision_id(self, context_branch):
463
471
# self.spec comes straight from parsing the command line arguments,
464
472
# so we expect it to be a Unicode string. Switch it to the internal
465
473
# 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):
470
474
return osutils.safe_revision_id(self.spec, warn=False)
813
817
revision_b = other_branch.last_revision()
814
818
if revision_b in (None, revision.NULL_REVISION):
815
819
raise errors.NoCommits(other_branch)
816
# pull in the remote revisions so we can diff
817
branch.fetch(other_branch, revision_b)
821
branch = other_branch
824
# pull in the remote revisions so we can diff
825
branch.fetch(other_branch, revision_b)
826
except errors.ReadOnlyError:
827
branch = other_branch
819
829
revno = branch.revision_id_to_revno(revision_b)
820
830
except errors.NoSuchRevision:
884
900
self._get_submit_location(context_branch))
903
class RevisionSpec_annotate(RevisionIDSpec):
907
help_txt = """Select the revision that last modified the specified line.
909
Select the revision that last modified the specified line. Line is
910
specified as path:number. Path is a relative path to the file. Numbers
911
start at 1, and are relative to the current version, not the last-
912
committed version of the file.
915
def _raise_invalid(self, numstring, context_branch):
916
raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
917
'No such line: %s' % numstring)
919
def _as_revision_id(self, context_branch):
920
path, numstring = self.spec.rsplit(':', 1)
922
index = int(numstring) - 1
924
self._raise_invalid(numstring, context_branch)
925
tree, file_path = workingtree.WorkingTree.open_containing(path)
928
file_id = tree.path2id(file_path)
930
raise errors.InvalidRevisionSpec(self.user_spec,
931
context_branch, "File '%s' is not versioned." %
933
revision_ids = [r for (r, l) in tree.annotate_iter(file_id)]
937
revision_id = revision_ids[index]
939
self._raise_invalid(numstring, context_branch)
940
if revision_id == revision.CURRENT_REVISION:
941
raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
942
'Line %s has not been committed.' % numstring)
946
class RevisionSpec_mainline(RevisionIDSpec):
948
help_txt = """Select mainline revision that merged the specified revision.
950
Select the revision that merged the specified revision into mainline.
955
def _as_revision_id(self, context_branch):
956
revspec = RevisionSpec.from_string(self.spec)
957
if revspec.get_branch() is None:
958
spec_branch = context_branch
960
spec_branch = _mod_branch.Branch.open(revspec.get_branch())
961
revision_id = revspec.as_revision_id(spec_branch)
962
graph = context_branch.repository.get_graph()
963
result = graph.find_lefthand_merger(revision_id,
964
context_branch.last_revision())
966
raise errors.InvalidRevisionSpec(self.user_spec, context_branch)
887
970
# The order in which we want to DWIM a revision spec without any prefix.
888
971
# revno is always tried first and isn't listed here, this is used by
889
972
# RevisionSpec_dwim._match_on
908
991
_register_revspec(RevisionSpec_ancestor)
909
992
_register_revspec(RevisionSpec_branch)
910
993
_register_revspec(RevisionSpec_submit)
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", [])
994
_register_revspec(RevisionSpec_annotate)
995
_register_revspec(RevisionSpec_mainline)