~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconfigure.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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"""
 
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
 
18
23
 
19
24
from bzrlib import (
20
25
    branch,
21
26
    bzrdir,
22
27
    errors,
 
28
    trace,
 
29
    ui,
 
30
    urlutils,
23
31
    )
24
32
 
 
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
 
25
73
class Reconfigure(object):
26
74
 
27
75
    def __init__(self, bzrdir, new_bound_location=None):
34
82
            self.repository = None
35
83
            self.local_repository = None
36
84
        else:
37
 
            if (self.repository.bzrdir.root_transport.base ==
38
 
                self.bzrdir.root_transport.base):
 
85
            if (self.repository.user_url == self.bzrdir.user_url):
39
86
                self.local_repository = self.repository
40
87
            else:
41
88
                self.local_repository = None
42
89
        try:
43
90
            branch = self.bzrdir.open_branch()
44
 
            if branch.bzrdir.root_transport.base == bzrdir.root_transport.base:
 
91
            if branch.user_url == bzrdir.user_url:
45
92
                self.local_branch = branch
46
93
                self.referenced_branch = None
47
94
            else:
169
216
            if not want_reference:
170
217
                self._create_repository = True
171
218
        else:
172
 
            if want_reference and (self.repository.bzrdir.root_transport.base
173
 
                                   == self.bzrdir.root_transport.base):
 
219
            if want_reference and (
 
220
                self.repository.user_url == self.bzrdir.user_url):
174
221
                if not self.repository.is_shared():
175
222
                    self._destroy_repository = True
176
223
        if self.referenced_branch is None:
217
264
 
218
265
    def _check(self):
219
266
        """Raise if reconfiguration would destroy local changes"""
220
 
        if self._destroy_tree:
221
 
            # XXX: What about pending merges ? -- vila 20090629
222
 
            if self.tree.has_changes(self.tree.basis_tree()):
 
267
        if self._destroy_tree and self.tree.has_changes():
223
268
                raise errors.UncommittedChanges(self.tree)
224
269
        if self._create_reference and self.local_branch is not None:
225
270
            reference_branch = branch.Branch.open(self._select_bind_location())
298
343
            if self._create_reference:
299
344
                reference_branch.repository.fetch(self.repository)
300
345
            elif self.local_branch is not None and not self._destroy_branch:
301
 
                up = self.local_branch.bzrdir.root_transport.clone('..')
 
346
                up = self.local_branch.user_transport.clone('..')
302
347
                up_bzrdir = bzrdir.BzrDir.open_containing_from_transport(up)[0]
303
348
                new_repo = up_bzrdir.find_repository()
304
349
                new_repo.fetch(self.repository)
322
367
            local_branch = self.local_branch
323
368
        if self._create_reference:
324
369
            format = branch.BranchReferenceFormat().initialize(self.bzrdir,
325
 
                reference_branch)
 
370
                target_branch=reference_branch)
326
371
        if self._destroy_tree:
327
372
            self.bzrdir.destroy_workingtree()
328
373
        if self._create_tree: