~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clone.py

  • Committer: Martin Pool
  • Date: 2005-09-30 07:38:34 UTC
  • mto: (1185.14.2)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050930073834-e2813ae9936fb006
- fix cloning of part of a branch

- add test for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
    to_location -- The destination directory; must either exist and be 
66
66
        empty, or not exist, in which case it is created.
67
67
 
68
 
    revno -- This revision should be the head of the new branch.
69
 
 
70
68
    basis_branch
71
69
        A local branch to copy revisions from, related to branch_from. 
72
70
        This is used when branching from a remote (slow) branch, and we have
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.")
 
77
    history = _get_truncated_history(branch_from, revision)
79
78
    if not os.path.exists(to_location):
80
79
        os.mkdir(to_location)
81
80
    branch_to = Branch.initialize(to_location)
82
81
    mutter("copy branch from %s to %s", branch_from, branch_to)
83
82
    branch_to.set_root_id(branch_from.get_root_id())
84
 
    if revision is None:
85
 
        revision = branch_from.last_revision()
 
83
    branch_to.append_revision(*history)
86
84
    _copy_control_weaves(branch_from, branch_to)
87
 
    _copy_revision_history(branch_from, branch_to)
88
85
    _copy_text_weaves(branch_from, branch_to)
89
86
    _copy_revision_store(branch_from, branch_to)
90
87
    build_working_dir(to_location)
93
90
    return branch_to
94
91
 
95
92
 
 
93
 
 
94
def _get_truncated_history(branch_from, revision):
 
95
    history = branch_from.revision_history()
 
96
    if revision is None:
 
97
        return history
 
98
    try:
 
99
        idx = history.index(revision)
 
100
    except ValueError:
 
101
        raise InvalidRevisionId('revision {%s} is not on the mainline of %s' 
 
102
                                % (revision, branch_from))
 
103
    return history[:idx+1]
 
104
 
96
105
def _copy_text_weaves(branch_from, branch_to):
97
106
    # TODO: Handle UnlistableStore and fall back to getting a list of 
98
107
    # all file-ids and copying them one by one.
104
113
    copy_all(branch_from.revision_store, branch_to.revision_store)
105
114
 
106
115
 
107
 
def _copy_revision_history(branch_from, branch_to):
108
 
    ff = branch_from.controlfile('revision-history')
109
 
    tf = branch_to.put_controlfile('revision-history', ff.read())
110
 
 
111
 
 
112
116
def _copy_control_weaves(branch_from, branch_to):
113
117
    to_control = branch_to.control_weaves
114
118
    from_control = branch_from.control_weaves