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