1
# Copyright (C) 2006-2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Reconcilers are able to fix some potential data errors in a branch."""
29
from .trace import mutter
30
from .i18n import gettext
33
def reconcile(dir, canonicalize_chks=False):
34
"""Reconcile the data in dir.
36
Currently this is limited to a inventory 'reweave'.
38
This is a convenience method, for using a Reconciler object.
40
Directly using Reconciler is recommended for library users that
41
desire fine grained control or analysis of the found issues.
43
:param canonicalize_chks: Make sure CHKs are in canonical form.
45
reconciler = Reconciler(dir, canonicalize_chks=canonicalize_chks)
46
return reconciler.reconcile()
49
class ReconcileResult(object):
50
"""Class describing the result of a reconcile operation."""
53
class Reconciler(object):
54
"""Reconcilers are used to reconcile existing data."""
56
def __init__(self, dir, other=None, canonicalize_chks=False):
57
"""Create a Reconciler."""
59
self.canonicalize_chks = canonicalize_chks
62
"""Perform reconciliation.
64
with ui.ui_factory.nested_progress_bar() as self.pb:
65
result = ReconcileResult()
66
branch_result = self._reconcile_branch()
67
repo_result = self._reconcile_repository()
68
# TODO(jelmer): Don't hardcode supported attributes here
69
result.inconsistent_parents = getattr(
70
repo_result, 'inconsistent_parents', None)
71
result.aborted = getattr(repo_result, 'aborted', None)
72
result.garbage_inventories = getattr(
73
repo_result, 'garbage_inventories', None)
74
result.fixed_branch_history = getattr(
75
branch_result, 'fixed_history', None)
78
def _reconcile_branch(self):
80
self.branch = self.controldir.open_branch()
81
except errors.NotBranchError:
82
# Nothing to check here
84
ui.ui_factory.note(gettext('Reconciling branch %s') % self.branch.base)
85
return self.branch.reconcile(thorough=True)
87
def _reconcile_repository(self):
88
self.repo = self.controldir.find_repository()
89
ui.ui_factory.note(gettext('Reconciling repository %s') %
91
self.pb.update(gettext("Reconciling repository"), 0, 1)
92
if self.canonicalize_chks:
94
self.repo.reconcile_canonicalize_chks
95
except AttributeError:
96
raise errors.BzrError(
97
gettext("%s cannot canonicalize CHKs.") % (self.repo,))
98
reconcile_result = self.repo.reconcile_canonicalize_chks()
100
reconcile_result = self.repo.reconcile(thorough=True)
101
if reconcile_result.aborted:
102
ui.ui_factory.note(gettext(
103
'Reconcile aborted: revision index has inconsistent parents.'))
104
ui.ui_factory.note(gettext(
105
'Run "brz check" for more details.'))
107
ui.ui_factory.note(gettext('Reconciliation complete.'))
108
return reconcile_result