/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/reconfigure.py

  • Committer: John Arbash Meinel
  • Date: 2009-04-21 23:54:16 UTC
  • mto: (4300.1.7 groupcompress_info)
  • mto: This revision was merged to the branch mainline in revision 4301.
  • Revision ID: john@arbash-meinel.com-20090421235416-f0cz6ilf5cufbugi
Fix bug #364900, properly remove the 64kB that was just encoded in the copy.
Also, stop supporting None as a copy length in 'encode_copy_instruction'.
It was only used by the test suite, and it is good to pull that sort of thing out of
production code. (Besides, setting the copy to 64kB has the same effect.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Reconfigure a bzrdir into a new tree/branch/repository layout.
18
 
 
19
 
Various types of reconfiguration operation are available either by
20
 
constructing a class or using a factory method on Reconfigure.
21
 
"""
22
 
 
 
17
"""Reconfigure a bzrdir into a new tree/branch/repository layout"""
23
18
 
24
19
from bzrlib import (
25
20
    branch,
26
21
    bzrdir,
27
22
    errors,
28
 
    trace,
29
 
    ui,
30
 
    urlutils,
31
23
    )
32
24
 
33
 
 
34
 
# TODO: common base class for all reconfigure operations, making no
35
 
# assumptions about what kind of change will be done.
36
 
 
37
 
 
38
 
class ReconfigureStackedOn(object):
39
 
    """Reconfigures a branch to be stacked on another branch."""
40
 
 
41
 
    def apply(self, bzrdir, stacked_on_url):
42
 
        branch = bzrdir.open_branch()
43
 
        # it may be a path relative to the cwd or a url; the branch wants
44
 
        # a path relative to itself...
45
 
        on_url = urlutils.relative_url(branch.base,
46
 
            urlutils.normalize_url(stacked_on_url))
47
 
        branch.lock_write()
48
 
        try:
49
 
            branch.set_stacked_on_url(on_url)
50
 
            if not trace.is_quiet():
51
 
                ui.ui_factory.note(
52
 
                    "%s is now stacked on %s\n"
53
 
                    % (branch.base, branch.get_stacked_on_url()))
54
 
        finally:
55
 
            branch.unlock()
56
 
 
57
 
 
58
 
class ReconfigureUnstacked(object):
59
 
 
60
 
    def apply(self, bzrdir):
61
 
        branch = bzrdir.open_branch()
62
 
        branch.lock_write()
63
 
        try:
64
 
            branch.set_stacked_on_url(None)
65
 
            if not trace.is_quiet():
66
 
                ui.ui_factory.note(
67
 
                    "%s is now not stacked\n"
68
 
                    % (branch.base,))
69
 
        finally:
70
 
            branch.unlock()
71
 
 
72
 
 
73
25
class Reconfigure(object):
74
26
 
75
27
    def __init__(self, bzrdir, new_bound_location=None):
76
28
        self.bzrdir = bzrdir
77
29
        self.new_bound_location = new_bound_location
78
 
        self.local_repository = None
79
30
        try:
80
31
            self.repository = self.bzrdir.find_repository()
81
32
        except errors.NoRepositoryPresent:
82
33
            self.repository = None
83
 
            self.local_repository = None
84
34
        else:
85
 
            if (self.repository.user_url == self.bzrdir.user_url):
 
35
            if (self.repository.bzrdir.root_transport.base ==
 
36
                self.bzrdir.root_transport.base):
86
37
                self.local_repository = self.repository
87
38
            else:
88
39
                self.local_repository = None
89
40
        try:
90
41
            branch = self.bzrdir.open_branch()
91
 
            if branch.user_url == bzrdir.user_url:
 
42
            if branch.bzrdir.root_transport.base == bzrdir.root_transport.base:
92
43
                self.local_branch = branch
93
44
                self.referenced_branch = None
94
45
            else:
216
167
            if not want_reference:
217
168
                self._create_repository = True
218
169
        else:
219
 
            if want_reference and (
220
 
                self.repository.user_url == self.bzrdir.user_url):
 
170
            if want_reference and (self.repository.bzrdir.root_transport.base
 
171
                                   == self.bzrdir.root_transport.base):
221
172
                if not self.repository.is_shared():
222
173
                    self._destroy_repository = True
223
174
        if self.referenced_branch is None:
264
215
 
265
216
    def _check(self):
266
217
        """Raise if reconfiguration would destroy local changes"""
267
 
        if self._destroy_tree and self.tree.has_changes():
 
218
        if self._destroy_tree:
 
219
            changes = self.tree.changes_from(self.tree.basis_tree())
 
220
            if changes.has_changed():
268
221
                raise errors.UncommittedChanges(self.tree)
269
222
        if self._create_reference and self.local_branch is not None:
270
223
            reference_branch = branch.Branch.open(self._select_bind_location())
315
268
        if not force:
316
269
            self._check()
317
270
        if self._create_repository:
318
 
            if self.local_branch and not self._destroy_branch:
319
 
                old_repo = self.local_branch.repository
320
 
            elif self._create_branch and self.referenced_branch is not None:
321
 
                old_repo = self.referenced_branch.repository
322
 
            else:
323
 
                old_repo = None
324
 
            if old_repo is not None:
325
 
                repository_format = old_repo._format
326
 
            else:
327
 
                repository_format = None
328
 
            if repository_format is not None:
329
 
                repo = repository_format.initialize(self.bzrdir)
330
 
            else:
331
 
                repo = self.bzrdir.create_repository()
 
271
            repo = self.bzrdir.create_repository()
332
272
            if self.local_branch and not self._destroy_branch:
333
273
                repo.fetch(self.local_branch.repository,
334
274
                           self.local_branch.last_revision())
343
283
            if self._create_reference:
344
284
                reference_branch.repository.fetch(self.repository)
345
285
            elif self.local_branch is not None and not self._destroy_branch:
346
 
                up = self.local_branch.user_transport.clone('..')
 
286
                up = self.local_branch.bzrdir.root_transport.clone('..')
347
287
                up_bzrdir = bzrdir.BzrDir.open_containing_from_transport(up)[0]
348
288
                new_repo = up_bzrdir.find_repository()
349
289
                new_repo.fetch(self.repository)
362
302
                local_branch.set_last_revision_info(*last_revision_info)
363
303
            if self._destroy_reference:
364
304
                self.referenced_branch.tags.merge_to(local_branch.tags)
365
 
                self.referenced_branch.update_references(local_branch)
366
305
        else:
367
306
            local_branch = self.local_branch
368
307
        if self._create_reference:
369
308
            format = branch.BranchReferenceFormat().initialize(self.bzrdir,
370
 
                target_branch=reference_branch)
 
309
                reference_branch)
371
310
        if self._destroy_tree:
372
311
            self.bzrdir.destroy_workingtree()
373
312
        if self._create_tree: