~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-07-29 22:47:55 UTC
  • Revision ID: mbp@sourcefrog.net-20050729224755-00dd53f95d62b05b
- add Branch.get_revision_delta

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 sys, os
 
18
import sys
 
19
import os
19
20
 
20
21
import bzrlib
21
 
 
22
22
from bzrlib.trace import mutter, note
23
 
from bzrlib.osutils import isdir, quotefn, compact_date, rand_bytes, splitpath, \
 
23
from bzrlib.osutils import isdir, quotefn, compact_date, rand_bytes, \
 
24
     splitpath, \
24
25
     sha_file, appendpath, file_kind
25
 
from bzrlib.errors import BzrError
 
26
from bzrlib.errors import BzrError, InvalidRevisionNumber, InvalidRevisionId
26
27
from bzrlib.textui import show_status
 
28
from bzrlib.revision import Revision
 
29
from bzrlib.xml import unpack_xml
 
30
 
27
31
        
28
32
BZR_BRANCH_FORMAT = "Bazaar-NG branch, format 0.0.4\n"
29
33
## TODO: Maybe include checks for common corruption of newlines, etc?
30
34
 
31
35
 
 
36
# TODO: Some operations like log might retrieve the same revisions
 
37
# repeatedly to calculate deltas.  We could perhaps have a weakref
 
38
# cache in memory to make this faster.
 
39
 
32
40
 
33
41
def find_branch(f, **args):
34
42
    if f and (f.startswith('http://') or f.startswith('https://')):
584
592
 
585
593
    def get_revision(self, revision_id):
586
594
        """Return the Revision object for a named revision"""
587
 
        from bzrlib.revision import Revision
588
 
        from bzrlib.xml import unpack_xml
589
 
 
590
595
        self.lock_read()
591
596
        try:
592
597
            if not revision_id or not isinstance(revision_id, basestring):
593
 
                raise ValueError('invalid revision-id: %r' % revision_id)
 
598
                raise InvalidRevisionId(revision_id)
594
599
            r = unpack_xml(Revision, self.revision_store[revision_id])
595
600
        finally:
596
601
            self.unlock()
597
602
            
598
603
        assert r.revision_id == revision_id
599
604
        return r
 
605
 
 
606
 
 
607
    def get_revision_delta(self, revno):
 
608
        """Return the delta for one revision.
 
609
 
 
610
        The delta is relative to its mainline predecessor, or the
 
611
        empty tree for revision 1.
 
612
        """
 
613
        assert isinstance(revno, int)
 
614
        rh = self.revision_history()
 
615
        if revno <= 0 or revno >= len(rh):
 
616
            raise InvalidRevisionNumber(revno)
 
617
 
 
618
        new_tree = self.revision_tree(rh[revno])
 
619
        if revno == 0:
 
620
            old_tree = EmptyTree()
 
621
        else:
 
622
            old_tree = self.revision_tree(rh[revno-1])
 
623
 
 
624
        return compare_trees(old_tree, new_tree)
 
625
 
600
626
        
601
627
 
602
628
    def get_revision_sha1(self, revision_id):