~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Lalo Martins
  • Date: 2005-09-07 10:37:16 UTC
  • mto: (1185.1.5)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: lalo@exoweb.net-20050907103716-2fc576c35c2df5f5
cleaning up and refactoring the branch module.

Special attention to import styles (we had all four of them!)  Martin
has standardized on "from bzrlib.foo import bar", so let's stick to it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
     sha_file, appendpath, file_kind
26
26
 
27
27
from bzrlib.errors import BzrError, InvalidRevisionNumber, InvalidRevisionId, \
28
 
     DivergedBranches
29
 
import bzrlib.errors
 
28
     DivergedBranches, NotBranchError
30
29
from bzrlib.textui import show_status
31
30
from bzrlib.revision import Revision
32
31
from bzrlib.delta import compare_trees
50
49
 
51
50
def find_branch(f, **args):
52
51
    if f and (f.startswith('http://') or f.startswith('https://')):
53
 
        import remotebranch 
54
 
        return remotebranch.RemoteBranch(f, **args)
 
52
        from bzrlib.remotebranch import RemoteBranch
 
53
        return RemoteBranch(f, **args)
55
54
    else:
56
55
        return Branch(f, **args)
57
56
 
58
57
 
59
58
def find_cached_branch(f, cache_root, **args):
60
 
    from remotebranch import RemoteBranch
 
59
    from bzrlib.remotebranch import RemoteBranch
61
60
    br = find_branch(f, **args)
62
61
    def cacheify(br, store_name):
63
 
        from meta_store import CachedStore
 
62
        from bzrlib.meta_store import CachedStore
64
63
        cache_path = os.path.join(cache_root, store_name)
65
64
        os.mkdir(cache_path)
66
65
        new_store = CachedStore(getattr(br, store_name), cache_path)
95
94
        if tail:
96
95
            s.insert(0, tail)
97
96
    else:
98
 
        from errors import NotBranchError
99
97
        raise NotBranchError("path %r is not within branch %r" % (rp, base))
100
98
 
101
99
    return os.sep.join(s)
129
127
        head, tail = os.path.split(f)
130
128
        if head == f:
131
129
            # reached the root, whatever that may be
132
 
            raise bzrlib.errors.NotBranchError('%s is not in a branch' % orig_f)
 
130
            raise NotBranchError('%s is not in a branch' % orig_f)
133
131
        f = head
134
132
 
135
133
 
188
186
        else:
189
187
            self.base = os.path.realpath(base)
190
188
            if not isdir(self.controlfilename('.')):
191
 
                from errors import NotBranchError
192
189
                raise NotBranchError("not a bzr branch: %s" % quotefn(base),
193
190
                                     ['use "bzr init" to initialize a new working tree',
194
191
                                      'current bzr can only operate from top-of-tree'])
208
205
 
209
206
    def __del__(self):
210
207
        if self._lock_mode or self._lock:
211
 
            from warnings import warn
 
208
            from bzrlib.warnings import warn
212
209
            warn("branch %r was not explicitly unlocked" % self)
213
210
            self._lock.unlock()
214
211
 
216
213
    def lock_write(self):
217
214
        if self._lock_mode:
218
215
            if self._lock_mode != 'w':
219
 
                from errors import LockError
 
216
                from bzrlib.errors import LockError
220
217
                raise LockError("can't upgrade to a write lock from %r" %
221
218
                                self._lock_mode)
222
219
            self._lock_count += 1
242
239
                        
243
240
    def unlock(self):
244
241
        if not self._lock_mode:
245
 
            from errors import LockError
 
242
            from bzrlib.errors import LockError
246
243
            raise LockError('branch %r is not locked' % (self))
247
244
 
248
245
        if self._lock_count > 1:
689
686
 
690
687
    def common_ancestor(self, other, self_revno=None, other_revno=None):
691
688
        """
692
 
        >>> import commit
 
689
        >>> from bzrlib.commit import commit
693
690
        >>> sb = ScratchBranch(files=['foo', 'foo~'])
694
691
        >>> sb.common_ancestor(sb) == (None, None)
695
692
        True
696
 
        >>> commit.commit(sb, "Committing first revision", verbose=False)
 
693
        >>> commit(sb, "Committing first revision", verbose=False)
697
694
        >>> sb.common_ancestor(sb)[0]
698
695
        1
699
696
        >>> clone = sb.clone()
700
 
        >>> commit.commit(sb, "Committing second revision", verbose=False)
 
697
        >>> commit(sb, "Committing second revision", verbose=False)
701
698
        >>> sb.common_ancestor(sb)[0]
702
699
        2
703
700
        >>> sb.common_ancestor(clone)[0]
704
701
        1
705
 
        >>> commit.commit(clone, "Committing divergent second revision", 
 
702
        >>> commit(clone, "Committing divergent second revision", 
706
703
        ...               verbose=False)
707
704
        >>> sb.common_ancestor(clone)[0]
708
705
        1
1088
1085
 
1089
1086
    def working_tree(self):
1090
1087
        """Return a `Tree` for the working copy."""
1091
 
        from workingtree import WorkingTree
 
1088
        from bzrlib.workingtree import WorkingTree
1092
1089
        return WorkingTree(self.base, self.read_working_inventory())
1093
1090
 
1094
1091
 
1505
1502
        The name of a local directory that exists but is empty.
1506
1503
    """
1507
1504
    from bzrlib.merge import merge
1508
 
    from bzrlib.branch import Branch
1509
1505
 
1510
1506
    assert isinstance(branch_from, Branch)
1511
1507
    assert isinstance(to_location, basestring)