~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconfigure.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-29 21:35:05 UTC
  • mfrom: (4576 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4577.
  • Revision ID: john@arbash-meinel.com-20090729213505-tkqsvy1zfpocu75w
Merge bzr.dev 4576 in prep for NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2009 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):
28
76
        self.bzrdir = bzrdir
29
77
        self.new_bound_location = new_bound_location
 
78
        self.local_repository = None
30
79
        try:
31
80
            self.repository = self.bzrdir.find_repository()
32
81
        except errors.NoRepositoryPresent:
217
266
    def _check(self):
218
267
        """Raise if reconfiguration would destroy local changes"""
219
268
        if self._destroy_tree:
220
 
            changes = self.tree.changes_from(self.tree.basis_tree())
221
 
            if changes.has_changed():
 
269
            # XXX: What about pending merges ? -- vila 20090629
 
270
            if self.tree.has_changes(self.tree.basis_tree()):
222
271
                raise errors.UncommittedChanges(self.tree)
223
272
        if self._create_reference and self.local_branch is not None:
224
273
            reference_branch = branch.Branch.open(self._select_bind_location())