~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-28 07:08:42 UTC
  • mfrom: (2380 +trunk)
  • mto: (2018.5.146 hpss)
  • mto: This revision was merged to the branch mainline in revision 2414.
  • Revision ID: andrew.bennetts@canonical.com-20070328070842-r843houy668oxb9o
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
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
21
21
 
22
22
from bzrlib import (
23
23
    errors,
 
24
    osutils,
24
25
    revision,
25
26
    symbol_versioning,
26
27
    trace,
93
94
        return '<bzrlib.revisionspec.RevisionInfo object %s, %s for %r>' % (
94
95
            self.revno, self.rev_id, self.branch)
95
96
 
 
97
    @staticmethod
 
98
    def from_revision_id(branch, revision_id, revs):
 
99
        """Construct a RevisionInfo given just the id.
 
100
 
 
101
        Use this if you don't know or care what the revno is.
 
102
        """
 
103
        try:
 
104
            revno = revs.index(revision_id) + 1
 
105
        except ValueError:
 
106
            revno = None
 
107
        return RevisionInfo(branch, revno, revision_id)
 
108
 
96
109
 
97
110
# classes in this list should have a "prefix" attribute, against which
98
111
# string specs are matched
367
380
    prefix = 'revid:'
368
381
 
369
382
    def _match_on(self, branch, revs):
370
 
        try:
371
 
            revno = revs.index(self.spec) + 1
372
 
        except ValueError:
373
 
            revno = None
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
 
385
        # representation.
 
386
        revision_id = osutils.safe_revision_id(self.spec, warn=False)
 
387
        return RevisionInfo.from_revision_id(branch, revision_id, revs)
375
388
 
376
389
SPEC_TYPES.append(RevisionSpec_revid)
377
390
 
465
478
 
466
479
 
467
480
class RevisionSpec_tag(RevisionSpec):
468
 
    """To be implemented."""
469
 
 
470
 
    help_txt = """To be implemented."""
 
481
    """Select a revision identified by tag name"""
 
482
 
 
483
    help_txt = """Selects a revision identified by a tag name.
 
484
 
 
485
    Tags are stored in the branch and created by the 'tag' command.
 
486
    """
471
487
 
472
488
    prefix = 'tag:'
473
489
 
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),
 
494
            revs)
478
495
 
479
496
SPEC_TYPES.append(RevisionSpec_tag)
480
497
 
606
623
    prefix = 'ancestor:'
607
624
 
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)
 
628
 
 
629
    @staticmethod
 
630
    def _find_revision_info(branch, other_location):
609
631
        from bzrlib.branch import Branch
610
632
 
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)):
624
645
        except errors.NoSuchRevision:
625
646
            revno = None
626
647
        return RevisionInfo(branch, revno, rev_id)
627
 
        
 
648
 
 
649
 
628
650
SPEC_TYPES.append(RevisionSpec_ancestor)
629
651
 
630
652
 
655
677
        return RevisionInfo(branch, revno, revision_b)
656
678
        
657
679
SPEC_TYPES.append(RevisionSpec_branch)
 
680
 
 
681
 
 
682
class RevisionSpec_submit(RevisionSpec_ancestor):
 
683
    """Selects a common ancestor with a submit branch."""
 
684
 
 
685
    help_txt = """Selects a common ancestor with the submit branch.
 
686
 
 
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.
 
691
 
 
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.
 
695
 
 
696
    examples:
 
697
      $ bzr diff -r submit:
 
698
    """
 
699
 
 
700
    prefix = 'submit:'
 
701
 
 
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)
 
713
 
 
714
 
 
715
SPEC_TYPES.append(RevisionSpec_submit)