~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clone.py

  • Committer: Aaron Bentley
  • Date: 2005-10-04 04:32:32 UTC
  • mfrom: (1185.12.6)
  • mto: (1185.12.13)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: aaron.bentley@utoronto.ca-20051004043231-40302a149769263b
merged my own changes

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
56
55
 
57
56
def copy_branch(branch_from, to_location, revision=None, basis_branch=None):
58
57
    """Copy branch_from into the existing directory to_location.
76
75
    assert isinstance(to_location, basestring)
77
76
    if basis_branch is not None:
78
77
        note("basis_branch is not supported for fast weave copy yet.")
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.set_root_id(branch_from.get_root_id())
91
 
        branch_to.append_revision(*history)
92
 
        _copy_control_weaves(branch_from, branch_to)
93
 
        _copy_text_weaves(branch_from, branch_to)
94
 
        _copy_revision_store(branch_from, branch_to)
95
 
        build_working_dir(to_location)
96
 
        branch_to.set_parent(branch_from.base)
97
 
        mutter("copied")
98
 
        return branch_to
99
 
    finally:
100
 
        branch_from.unlock()
 
78
    history = _get_truncated_history(branch_from, revision)
 
79
    if not bzrlib.osutils.lexists(to_location):
 
80
        os.mkdir(to_location)
 
81
    branch_to = Branch.initialize(to_location)
 
82
    mutter("copy branch from %s to %s", branch_from, branch_to)
 
83
    branch_to.set_root_id(branch_from.get_root_id())
 
84
    branch_to.append_revision(*history)
 
85
    _copy_control_weaves(branch_from, branch_to)
 
86
    _copy_text_weaves(branch_from, branch_to)
 
87
    _copy_revision_store(branch_from, branch_to)
 
88
    build_working_dir(to_location)
 
89
    branch_to.set_parent(branch_from.base)
 
90
    mutter("copied")
 
91
    return branch_to
 
92
 
101
93
 
102
94
 
103
95
def _get_truncated_history(branch_from, revision):
107
99
    try:
108
100
        idx = history.index(revision)
109
101
    except ValueError:
110
 
        raise InvalidRevisionId(revision_id=revision, branch=branch_from)
 
102
        raise InvalidRevisionId('revision {%s} is not on the mainline of %s' 
 
103
                                % (revision, branch_from))
111
104
    return history[:idx+1]
112
105
 
113
106
def _copy_text_weaves(branch_from, branch_to):
 
107
    # TODO: Handle UnlistableStore and fall back to getting a list of 
 
108
    # all file-ids and copying them one by one.
114
109
    copy_all(branch_from.weave_store, branch_to.weave_store)
115
110
 
116
111
 
117
112
def _copy_revision_store(branch_from, branch_to):
 
113
    # TODO: Copy all revisions mentioned in the ancestry of the selected revision
118
114
    copy_all(branch_from.revision_store, branch_to.revision_store)
119
115
 
120
116
 
121
117
def _copy_control_weaves(branch_from, branch_to):
122
118
    to_control = branch_to.control_weaves
123
119
    from_control = branch_from.control_weaves
124
 
    to_control.copy_multi(from_control, ['inventory'])
 
120
    to_control.copy_multi(from_control, ['inventory', 'ancestry'])
125
121
 
126
122
    
127
123
def copy_branch_slower(branch_from, to_location, revision=None, basis_branch=None):