/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 breezy/reconfigure.py

  • Committer: Jelmer Vernooij
  • Date: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
constructing a class or using a factory method on Reconfigure.
21
21
"""
22
22
 
23
 
from __future__ import absolute_import
24
 
 
25
23
 
26
24
from . import (
27
25
    branch,
118
116
        # it may be a path relative to the cwd or a url; the branch wants
119
117
        # a path relative to itself...
120
118
        on_url = urlutils.relative_url(branch.base,
121
 
            urlutils.normalize_url(stacked_on_url))
122
 
        branch.lock_write()
123
 
        try:
 
119
                                       urlutils.normalize_url(stacked_on_url))
 
120
        with branch.lock_write():
124
121
            branch.set_stacked_on_url(on_url)
125
122
            if not trace.is_quiet():
126
123
                ui.ui_factory.note(gettext(
127
124
                    "{0} is now stacked on {1}\n").format(
128
 
                      branch.base, branch.get_stacked_on_url()))
129
 
        finally:
130
 
            branch.unlock()
 
125
                    branch.base, branch.get_stacked_on_url()))
131
126
 
132
127
 
133
128
class ReconfigureUnstacked(object):
134
129
 
135
130
    def apply(self, controldir):
136
131
        branch = controldir.open_branch()
137
 
        branch.lock_write()
138
 
        try:
 
132
        with branch.lock_write():
139
133
            branch.set_stacked_on_url(None)
140
134
            if not trace.is_quiet():
141
135
                ui.ui_factory.note(gettext(
142
136
                    "%s is now not stacked\n")
143
137
                    % (branch.base,))
144
 
        finally:
145
 
            branch.unlock()
146
138
 
147
139
 
148
140
class Reconfigure(object):
273
265
            raise ReconfigurationNotSupported(reconfiguration.controldir)
274
266
        if with_trees and reconfiguration.repository.make_working_trees():
275
267
            raise AlreadyWithTrees(controldir)
276
 
        elif (not with_trees
277
 
              and not reconfiguration.repository.make_working_trees()):
 
268
        elif (not with_trees and
 
269
              not reconfiguration.repository.make_working_trees()):
278
270
            raise AlreadyWithNoTrees(controldir)
279
271
        else:
280
272
            reconfiguration._repository_trees = with_trees
292
284
                self._create_repository = True
293
285
        else:
294
286
            if want_reference and (
295
 
                self.repository.user_url == self.controldir.user_url):
 
287
                    self.repository.user_url == self.controldir.user_url):
296
288
                if not self.repository.is_shared():
297
289
                    self._destroy_repository = True
298
290
        if self.referenced_branch is None:
332
324
 
333
325
    def changes_planned(self):
334
326
        """Return True if changes are planned, False otherwise"""
335
 
        return (self._unbind or self._bind or self._destroy_tree
336
 
                or self._create_tree or self._destroy_reference
337
 
                or self._create_branch or self._create_repository
338
 
                or self._create_reference or self._destroy_repository)
 
327
        return (self._unbind or self._bind or self._destroy_tree or
 
328
                self._create_tree or self._destroy_reference or
 
329
                self._create_branch or self._create_repository or
 
330
                self._create_reference or self._destroy_repository)
339
331
 
340
332
    def _check(self):
341
333
        """Raise if reconfiguration would destroy local changes"""
342
334
        if self._destroy_tree and self.tree.has_changes():
343
 
                raise errors.UncommittedChanges(self.tree)
 
335
            raise errors.UncommittedChanges(self.tree)
344
336
        if self._create_reference and self.local_branch is not None:
345
337
            reference_branch = branch.Branch.open(self._select_bind_location())
346
 
            if (reference_branch.last_revision() !=
347
 
                self.local_branch.last_revision()):
 
338
            if (reference_branch.last_revision()
 
339
                    != self.local_branch.last_revision()):
348
340
                raise UnsyncedBranches(self.controldir, reference_branch)
349
341
 
350
342
    def _select_bind_location(self):