~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clone.py

  • Committer: Martin Pool
  • Date: 2006-01-13 06:31:42 UTC
  • Revision ID: mbp@sourcefrog.net-20060113063142-8e706dc1483c69e1
Bump version to 0.8pre

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
from bzrlib.branch import Branch
53
53
from bzrlib.trace import mutter, note
54
54
from bzrlib.store import copy_all
 
55
from bzrlib.errors import InvalidRevisionId
55
56
 
56
57
def copy_branch(branch_from, to_location, revision=None, basis_branch=None):
57
58
    """Copy branch_from into the existing directory to_location.
75
76
    assert isinstance(to_location, basestring)
76
77
    if basis_branch is not None:
77
78
        note("basis_branch is not supported for fast weave copy yet.")
78
 
    if not (branch_from.weave_store.listable()
79
 
            and branch_from.revision_store.listable()):
80
 
        return copy_branch_slower(branch_from, to_location, revision,
81
 
                                  basis_branch)
82
 
    history = _get_truncated_history(branch_from, revision)
83
 
    if not bzrlib.osutils.lexists(to_location):
84
 
        os.mkdir(to_location)
85
 
    branch_to = Branch.initialize(to_location)
86
 
    mutter("copy branch from %s to %s", branch_from, branch_to)
87
 
    branch_to.set_root_id(branch_from.get_root_id())
88
 
    branch_to.append_revision(*history)
89
 
    _copy_control_weaves(branch_from, branch_to)
90
 
    _copy_text_weaves(branch_from, branch_to)
91
 
    _copy_revision_store(branch_from, branch_to)
92
 
    build_working_dir(to_location)
93
 
    branch_to.set_parent(branch_from.base)
94
 
    mutter("copied")
95
 
    return branch_to
96
 
 
97
 
 
98
 
def _get_truncated_history(branch_from, revision):
 
79
    branch_from.lock_read()
 
80
    try:
 
81
        if not (branch_from.weave_store.listable()
 
82
                and branch_from.revision_store.listable()):
 
83
            return copy_branch_slower(branch_from, to_location, revision,
 
84
                                      basis_branch)
 
85
        history = _get_truncated_history(branch_from, revision)
 
86
        if not bzrlib.osutils.lexists(to_location):
 
87
            os.mkdir(to_location)
 
88
        branch_to = Branch.initialize(to_location)
 
89
        mutter("copy branch from %s to %s", branch_from, branch_to)
 
90
        branch_to.working_tree().set_root_id(branch_from.get_root_id())
 
91
        _copy_control_weaves(branch_from, branch_to)
 
92
        _copy_text_weaves(branch_from, branch_to)
 
93
        _copy_revision_store(branch_from, branch_to)
 
94
        branch_to.set_parent(branch_from.base)
 
95
        # must be done *after* history is copied across
 
96
        branch_to.append_revision(*history)
 
97
        build_working_dir(to_location)
 
98
        mutter("copied")
 
99
        return branch_to
 
100
    finally:
 
101
        branch_from.unlock()
 
102
 
 
103
 
 
104
def _get_truncated_history(branch_from, revision_id):
99
105
    history = branch_from.revision_history()
100
 
    if revision is None:
 
106
    if revision_id is None:
101
107
        return history
102
108
    try:
103
 
        idx = history.index(revision)
 
109
        idx = history.index(revision_id)
104
110
    except ValueError:
105
 
        raise InvalidRevisionId('revision {%s} is not on the mainline of %s' 
106
 
                                % (revision, branch_from))
 
111
        raise InvalidRevisionId(revision_id=revision, branch=branch_from)
107
112
    return history[:idx+1]
108
113
 
109
114
def _copy_text_weaves(branch_from, branch_to):
147
152
    mutter("copy branch from %s to %s", branch_from, br_to)
148
153
    if basis_branch is not None:
149
154
        basis_branch.push_stores(br_to)
150
 
    br_to.set_root_id(branch_from.get_root_id())
 
155
    br_to.working_tree().set_root_id(branch_from.get_root_id())
151
156
    if revision is None:
152
157
        revision = branch_from.last_revision()
153
158
    br_to.update_revisions(branch_from, stop_revision=revision)