~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-30 00:55:00 UTC
  • mto: (3815.2.5 prepare-1.9)
  • mto: This revision was merged to the branch mainline in revision 3811.
  • Revision ID: john@arbash-meinel.com-20081030005500-r5cej1cxflqhs3io
Switch so that we are using a simple timestamp as the first action.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
import re
 
19
 
 
20
from bzrlib.lazy_import import lazy_import
 
21
lazy_import(globals(), """
18
22
import bisect
19
23
import datetime
20
 
import re
 
24
""")
21
25
 
22
26
from bzrlib import (
23
27
    errors,
25
29
    revision,
26
30
    symbol_versioning,
27
31
    trace,
28
 
    tsort,
29
32
    )
30
33
 
31
34
 
137
140
    prefix = None
138
141
    wants_revision_history = True
139
142
 
140
 
    def __new__(cls, spec, _internal=False):
141
 
        if _internal:
142
 
            return object.__new__(cls, spec, _internal=_internal)
143
 
 
144
 
        symbol_versioning.warn('Creating a RevisionSpec directly has'
145
 
                               ' been deprecated in version 0.11. Use'
146
 
                               ' RevisionSpec.from_string()'
147
 
                               ' instead.',
148
 
                               DeprecationWarning, stacklevel=2)
149
 
        return RevisionSpec.from_string(spec)
150
 
 
151
143
    @staticmethod
152
144
    def from_string(spec):
153
145
        """Parse a revision spec string into a RevisionSpec object.
252
244
        """
253
245
        return self.in_history(context_branch).rev_id
254
246
 
 
247
    def as_tree(self, context_branch):
 
248
        """Return the tree object for this revisions spec.
 
249
 
 
250
        Some revision specs require a context_branch to be able to determine
 
251
        the revision id and access the repository. Not all specs will make
 
252
        use of it.
 
253
        """
 
254
        return self._as_tree(context_branch)
 
255
 
 
256
    def _as_tree(self, context_branch):
 
257
        """Implementation of as_tree().
 
258
 
 
259
        Classes should override this function to provide appropriate
 
260
        functionality. The default is to just call '.as_revision_id()'
 
261
        and get the revision tree from context_branch's repository.
 
262
        """
 
263
        revision_id = self.as_revision_id(context_branch)
 
264
        return context_branch.repository.revision_tree(revision_id)
 
265
 
255
266
    def __repr__(self):
256
267
        # this is mostly for helping with testing
257
268
        return '<%s %s>' % (self.__class__.__name__,
286
297
    than the branch's history, the first revision is returned.
287
298
    Examples::
288
299
 
289
 
      revno:1                   -> return the first revision
 
300
      revno:1                   -> return the first revision of this branch
290
301
      revno:3:/path/to/branch   -> return the 3rd revision of
291
302
                                   the branch '/path/to/branch'
292
303
      revno:-1                  -> The last revision in a branch.
475
486
 
476
487
    help_txt = """Selects the parent of the revision specified.
477
488
 
478
 
    Supply any revision spec to return the parent of that revision.
 
489
    Supply any revision spec to return the parent of that revision.  This is
 
490
    mostly useful when inspecting revisions that are not in the revision history
 
491
    of a branch.
 
492
 
479
493
    It is an error to request the parent of the null revision (before:0).
480
 
    This is mostly useful when inspecting revisions that are not in the
481
 
    revision history of a branch.
482
494
 
483
495
    Examples::
484
496
 
485
497
      before:1913    -> Return the parent of revno 1913 (revno 1912)
486
498
      before:revid:aaaa@bbbb-1234567890  -> return the parent of revision
487
499
                                            aaaa@bbbb-1234567890
488
 
      bzr diff -r before:revid:aaaa..revid:aaaa
489
 
            -> Find the changes between revision 'aaaa' and its parent.
490
 
               (what changes did 'aaaa' introduce)
 
500
      bzr diff -r before:1913..1913
 
501
            -> Find the changes between revision 1913 and its parent (1912).
 
502
               (What changes did revision 1913 introduce).
 
503
               This is equivalent to:  bzr diff -c 1913
491
504
    """
492
505
 
493
506
    prefix = 'before:'
522
535
        base_revspec = RevisionSpec.from_string(self.spec)
523
536
        base_revision_id = base_revspec.as_revision_id(context_branch)
524
537
        if base_revision_id == revision.NULL_REVISION:
525
 
            raise errors.InvalidRevisionSpec(self.user_spec, branch,
 
538
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
526
539
                                         'cannot go before the null: revision')
527
540
        context_repo = context_branch.repository
528
541
        context_repo.lock_read()
596
609
 
597
610
    One way to display all the changes since yesterday would be::
598
611
 
599
 
        bzr log -r date:yesterday..-1
 
612
        bzr log -r date:yesterday..
600
613
 
601
614
    Examples::
602
615
 
777
790
            raise errors.NoCommits(other_branch)
778
791
        return last_revision
779
792
 
 
793
    def _as_tree(self, context_branch):
 
794
        from bzrlib.branch import Branch
 
795
        other_branch = Branch.open(self.spec)
 
796
        last_revision = other_branch.last_revision()
 
797
        last_revision = revision.ensure_null(last_revision)
 
798
        if last_revision == revision.NULL_REVISION:
 
799
            raise errors.NoCommits(other_branch)
 
800
        return other_branch.repository.revision_tree(last_revision)
 
801
 
780
802
SPEC_TYPES.append(RevisionSpec_branch)
781
803
 
782
804
 
787
809
 
788
810
    Diffing against this shows all the changes that were made in this branch,
789
811
    and is a good predictor of what merge will do.  The submit branch is
790
 
    used by the bundle and merge directive comands.  If no submit branch
 
812
    used by the bundle and merge directive commands.  If no submit branch
791
813
    is specified, the parent branch is used instead.
792
814
 
793
815
    The common ancestor is the last revision that existed in both