1
# Copyright (C) 2005 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
93
94
return '<bzrlib.revisionspec.RevisionInfo object %s, %s for %r>' % (
94
95
self.revno, self.rev_id, self.branch)
98
def from_revision_id(branch, revision_id, revs):
99
"""Construct a RevisionInfo given just the id.
101
Use this if you don't know or care what the revno is.
104
revno = revs.index(revision_id) + 1
107
return RevisionInfo(branch, revno, revision_id)
97
110
# classes in this list should have a "prefix" attribute, against which
98
111
# string specs are matched
367
380
prefix = 'revid:'
369
382
def _match_on(self, branch, revs):
371
revno = revs.index(self.spec) + 1
374
return RevisionInfo(branch, revno, self.spec)
383
# self.spec comes straight from parsing the command line arguments,
384
# so we expect it to be a Unicode string. Switch it to the internal
386
revision_id = osutils.safe_revision_id(self.spec, warn=False)
387
return RevisionInfo.from_revision_id(branch, revision_id, revs)
376
389
SPEC_TYPES.append(RevisionSpec_revid)
467
480
class RevisionSpec_tag(RevisionSpec):
468
"""To be implemented."""
470
help_txt = """To be implemented."""
481
"""Select a revision identified by tag name"""
483
help_txt = """Selects a revision identified by a tag name.
485
Tags are stored in the branch and created by the 'tag' command.
474
490
def _match_on(self, branch, revs):
475
raise errors.InvalidRevisionSpec(self.user_spec, branch,
476
'tag: namespace registered,'
477
' but not implemented')
491
# Can raise tags not supported, NoSuchTag, etc
492
return RevisionInfo.from_revision_id(branch,
493
branch.tags.lookup_tag(self.spec),
479
496
SPEC_TYPES.append(RevisionSpec_tag)
606
623
prefix = 'ancestor:'
608
625
def _match_on(self, branch, revs):
626
trace.mutter('matching ancestor: on: %s, %s', self.spec, branch)
627
return self._find_revision_info(branch, self.spec)
630
def _find_revision_info(branch, other_location):
609
631
from bzrlib.branch import Branch
611
trace.mutter('matching ancestor: on: %s, %s', self.spec, branch)
612
other_branch = Branch.open(self.spec)
633
other_branch = Branch.open(other_location)
613
634
revision_a = branch.last_revision()
614
635
revision_b = other_branch.last_revision()
615
636
for r, b in ((revision_a, branch), (revision_b, other_branch)):
655
677
return RevisionInfo(branch, revno, revision_b)
657
679
SPEC_TYPES.append(RevisionSpec_branch)
682
class RevisionSpec_submit(RevisionSpec_ancestor):
683
"""Selects a common ancestor with a submit branch."""
685
help_txt = """Selects a common ancestor with the submit branch.
687
Diffing against this shows all the changes that were made in this branch,
688
and is a good predictor of what merge will do. The submit branch is
689
used by the bundle and merge directive comands. If no submit branch
690
is specified, the parent branch is used instead.
692
The common ancestor is the last revision that existed in both
693
branches. Usually this is the branch point, but it could also be
694
a revision that was merged.
697
$ bzr diff -r submit:
702
def _match_on(self, branch, revs):
703
trace.mutter('matching ancestor: on: %s, %s', self.spec, branch)
704
submit_location = branch.get_submit_branch()
705
location_type = 'submit branch'
706
if submit_location is None:
707
submit_location = branch.get_parent()
708
location_type = 'parent branch'
709
if submit_location is None:
710
raise errors.NoSubmitBranch(branch)
711
trace.note('Using %s %s', location_type, submit_location)
712
return self._find_revision_info(branch, submit_location)
715
SPEC_TYPES.append(RevisionSpec_submit)