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."""
19
from __future__ import absolute_import
32
from .trace import mutter
33
from .i18n import gettext
36
def reconcile(dir, canonicalize_chks=False):
37
"""Reconcile the data in dir.
39
Currently this is limited to a inventory 'reweave'.
41
This is a convenience method, for using a Reconciler object.
43
Directly using Reconciler is recommended for library users that
44
desire fine grained control or analysis of the found issues.
46
:param canonicalize_chks: Make sure CHKs are in canonical form.
48
reconciler = Reconciler(dir, canonicalize_chks=canonicalize_chks)
49
return reconciler.reconcile()
52
class ReconcileResult(object):
53
"""Class describing the result of a reconcile operation."""
56
class Reconciler(object):
57
"""Reconcilers are used to reconcile existing data."""
59
def __init__(self, dir, other=None, canonicalize_chks=False):
60
"""Create a Reconciler."""
62
self.canonicalize_chks = canonicalize_chks
65
"""Perform reconciliation.
67
with ui.ui_factory.nested_progress_bar() as self.pb:
68
result = ReconcileResult()
69
branch_result = self._reconcile_branch()
70
repo_result = self._reconcile_repository()
71
# TODO(jelmer): Don't hardcode supported attributes here
72
result.inconsistent_parents = getattr(
73
repo_result, 'inconsistent_parents', None)
74
result.aborted = getattr(repo_result, 'aborted', None)
75
result.garbage_inventories = getattr(
76
repo_result, 'garbage_inventories', None)
77
result.fixed_branch_history = getattr(
78
branch_result, 'fixed_history', None)
81
def _reconcile_branch(self):
83
self.branch = self.controldir.open_branch()
84
except errors.NotBranchError:
85
# Nothing to check here
87
ui.ui_factory.note(gettext('Reconciling branch %s') % self.branch.base)
88
return self.branch.reconcile(thorough=True)
90
def _reconcile_repository(self):
91
self.repo = self.controldir.find_repository()
92
ui.ui_factory.note(gettext('Reconciling repository %s') %
94
self.pb.update(gettext("Reconciling repository"), 0, 1)
95
if self.canonicalize_chks:
97
self.repo.reconcile_canonicalize_chks
98
except AttributeError:
99
raise errors.BzrError(
100
gettext("%s cannot canonicalize CHKs.") % (self.repo,))
101
reconcile_result = self.repo.reconcile_canonicalize_chks()
103
reconcile_result = self.repo.reconcile(thorough=True)
104
if reconcile_result.aborted:
105
ui.ui_factory.note(gettext(
106
'Reconcile aborted: revision index has inconsistent parents.'))
107
ui.ui_factory.note(gettext(
108
'Run "brz check" for more details.'))
110
ui.ui_factory.note(gettext('Reconciliation complete.'))
111
return reconcile_result