~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clone.py

  • Committer: Aaron Bentley
  • Date: 2005-10-01 06:48:01 UTC
  • mto: (1185.12.13)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: aaron.bentley@utoronto.ca-20051001064801-7400c2ed0fe26080
Made iter_conflicts a WorkingTree method

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
import os
48
48
import sys
49
49
 
50
 
import bzrlib
51
50
from bzrlib.merge import build_working_dir
52
51
from bzrlib.branch import Branch
53
52
from bzrlib.trace import mutter, note
54
53
from bzrlib.store import copy_all
55
 
from bzrlib.errors import InvalidRevisionId
56
54
 
57
55
def copy_branch(branch_from, to_location, revision=None, basis_branch=None):
58
56
    """Copy branch_from into the existing directory to_location.
76
74
    assert isinstance(to_location, basestring)
77
75
    if basis_branch is not None:
78
76
        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()
 
77
    history = _get_truncated_history(branch_from, revision)
 
78
    if not os.path.exists(to_location):
 
79
        os.mkdir(to_location)
 
80
    branch_to = Branch.initialize(to_location)
 
81
    mutter("copy branch from %s to %s", branch_from, branch_to)
 
82
    branch_to.set_root_id(branch_from.get_root_id())
 
83
    branch_to.append_revision(*history)
 
84
    _copy_control_weaves(branch_from, branch_to)
 
85
    _copy_text_weaves(branch_from, branch_to)
 
86
    _copy_revision_store(branch_from, branch_to)
 
87
    build_working_dir(to_location)
 
88
    branch_to.set_parent(branch_from.base)
 
89
    mutter("copied")
 
90
    return branch_to
 
91
 
101
92
 
102
93
 
103
94
def _get_truncated_history(branch_from, revision):
107
98
    try:
108
99
        idx = history.index(revision)
109
100
    except ValueError:
110
 
        raise InvalidRevisionId(revision_id=revision, branch=branch_from)
 
101
        raise InvalidRevisionId('revision {%s} is not on the mainline of %s' 
 
102
                                % (revision, branch_from))
111
103
    return history[:idx+1]
112
104
 
113
105
def _copy_text_weaves(branch_from, branch_to):
 
106
    # TODO: Handle UnlistableStore and fall back to getting a list of 
 
107
    # all file-ids and copying them one by one.
114
108
    copy_all(branch_from.weave_store, branch_to.weave_store)
115
109
 
116
110
 
117
111
def _copy_revision_store(branch_from, branch_to):
 
112
    # TODO: Copy all revisions mentioned in the ancestry of the selected revision
118
113
    copy_all(branch_from.revision_store, branch_to.revision_store)
119
114
 
120
115
 
121
116
def _copy_control_weaves(branch_from, branch_to):
122
117
    to_control = branch_to.control_weaves
123
118
    from_control = branch_from.control_weaves
124
 
    to_control.copy_multi(from_control, ['inventory'])
 
119
    to_control.copy_multi(from_control, ['inventory', 'ancestry'])
125
120
 
126
121
    
127
122
def copy_branch_slower(branch_from, to_location, revision=None, basis_branch=None):
145
140
    """
146
141
    assert isinstance(branch_from, Branch)
147
142
    assert isinstance(to_location, basestring)
148
 
    if not bzrlib.osutils.lexists(to_location):
 
143
    if not os.path.exists(to_location):
149
144
        os.mkdir(to_location)
150
145
    br_to = Branch.initialize(to_location)
151
146
    mutter("copy branch from %s to %s", branch_from, br_to)