/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2006-2010 Canonical Ltd
1570.1.2 by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.'
2
#
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.
7
#
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.
12
#
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1570.1.2 by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.'
16
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
17
"""Reconcilers are able to fix some potential data errors in a branch."""
18
2592.3.80 by Robert Collins
Make reconcile work, and pass tests.
19
__all__ = [
20
    'reconcile',
21
    'Reconciler',
22
    ]
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
23
24
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
25
from . import (
2745.6.16 by Aaron Bentley
Update from review
26
    errors,
2745.6.11 by Aaron Bentley
Fix knit file parents to follow parentage from revision/inventory XML
27
    ui,
28
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
29
from .trace import mutter
30
from .i18n import gettext
1570.1.2 by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.'
31
32
5375.1.3 by Andrew Bennetts
Add hidden --canonicalize-chks option to reconcile to trigger GCCHKCanonicalizingPacker, improve progress reporting a little.
33
def reconcile(dir, canonicalize_chks=False):
1570.1.2 by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.'
34
    """Reconcile the data in dir.
35
36
    Currently this is limited to a inventory 'reweave'.
37
1570.1.8 by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry.
38
    This is a convenience method, for using a Reconciler object.
39
40
    Directly using Reconciler is recommended for library users that
41
    desire fine grained control or analysis of the found issues.
1692.1.1 by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow
42
5375.1.3 by Andrew Bennetts
Add hidden --canonicalize-chks option to reconcile to trigger GCCHKCanonicalizingPacker, improve progress reporting a little.
43
    :param canonicalize_chks: Make sure CHKs are in canonical form.
1570.1.2 by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.'
44
    """
5375.1.3 by Andrew Bennetts
Add hidden --canonicalize-chks option to reconcile to trigger GCCHKCanonicalizingPacker, improve progress reporting a little.
45
    reconciler = Reconciler(dir, canonicalize_chks=canonicalize_chks)
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
46
    return reconciler.reconcile()
47
48
49
class ReconcileResult(object):
50
    """Class describing the result of a reconcile operation."""
1570.1.2 by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.'
51
52
1570.1.6 by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it.
53
class Reconciler(object):
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
54
    """Reconcilers are used to reconcile existing data."""
1570.1.6 by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it.
55
5375.1.3 by Andrew Bennetts
Add hidden --canonicalize-chks option to reconcile to trigger GCCHKCanonicalizingPacker, improve progress reporting a little.
56
    def __init__(self, dir, other=None, canonicalize_chks=False):
1692.1.1 by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow
57
        """Create a Reconciler."""
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
58
        self.controldir = dir
5375.1.3 by Andrew Bennetts
Add hidden --canonicalize-chks option to reconcile to trigger GCCHKCanonicalizingPacker, improve progress reporting a little.
59
        self.canonicalize_chks = canonicalize_chks
1570.1.6 by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it.
60
61
    def reconcile(self):
1570.1.8 by Robert Collins
Only reconcile if doing so will perform gc or correct ancestry.
62
        """Perform reconciliation.
63
        """
7143.22.2 by Jelmer Vernooij
use more context libs for progress bars.
64
        with ui.ui_factory.nested_progress_bar() as self.pb:
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
65
            result = ReconcileResult()
66
            branch_result = self._reconcile_branch()
67
            repo_result = self._reconcile_repository()
7206.6.5 by Jelmer Vernooij
Add TODO.
68
            # TODO(jelmer): Don't hardcode supported attributes here
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
69
            result.inconsistent_parents = getattr(
7206.6.8 by Jelmer Vernooij
Fix tests.
70
                repo_result, 'inconsistent_parents', None)
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
71
            result.aborted = getattr(repo_result, 'aborted', None)
72
            result.garbage_inventories = getattr(
7206.6.8 by Jelmer Vernooij
Fix tests.
73
                repo_result, 'garbage_inventories', None)
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
74
            result.fixed_branch_history = getattr(
75
                branch_result, 'fixed_history', None)
76
            return result
3389.2.3 by John Arbash Meinel
Add Branch.reconcile() functionality.
77
6861.4.3 by Jelmer Vernooij
Use OperationWithCleanups.
78
    def _reconcile_branch(self):
3389.2.3 by John Arbash Meinel
Add Branch.reconcile() functionality.
79
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
80
            self.branch = self.controldir.open_branch()
3389.2.3 by John Arbash Meinel
Add Branch.reconcile() functionality.
81
        except errors.NotBranchError:
82
            # Nothing to check here
83
            return
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
84
        ui.ui_factory.note(gettext('Reconciling branch %s') % self.branch.base)
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
85
        return self.branch.reconcile(thorough=True)
3389.2.3 by John Arbash Meinel
Add Branch.reconcile() functionality.
86
6861.4.3 by Jelmer Vernooij
Use OperationWithCleanups.
87
    def _reconcile_repository(self):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
88
        self.repo = self.controldir.find_repository()
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
89
        ui.ui_factory.note(gettext('Reconciling repository %s') %
7143.15.2 by Jelmer Vernooij
Run autopep8.
90
                           self.repo.user_url)
6861.4.3 by Jelmer Vernooij
Use OperationWithCleanups.
91
        self.pb.update(gettext("Reconciling repository"), 0, 1)
5375.1.3 by Andrew Bennetts
Add hidden --canonicalize-chks option to reconcile to trigger GCCHKCanonicalizingPacker, improve progress reporting a little.
92
        if self.canonicalize_chks:
5375.1.6 by Andrew Bennetts
Don't traceback if a repository doesn't support reconcile_canonicalize_chks.
93
            try:
94
                self.repo.reconcile_canonicalize_chks
95
            except AttributeError:
96
                raise errors.BzrError(
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
97
                    gettext("%s cannot canonicalize CHKs.") % (self.repo,))
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
98
            reconcile_result = self.repo.reconcile_canonicalize_chks()
5375.1.3 by Andrew Bennetts
Add hidden --canonicalize-chks option to reconcile to trigger GCCHKCanonicalizingPacker, improve progress reporting a little.
99
        else:
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
100
            reconcile_result = self.repo.reconcile(thorough=True)
101
        if reconcile_result.aborted:
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
102
            ui.ui_factory.note(gettext(
103
                'Reconcile aborted: revision index has inconsistent parents.'))
104
            ui.ui_factory.note(gettext(
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
105
                'Run "brz check" for more details.'))
2819.2.5 by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents.
106
        else:
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
107
            ui.ui_factory.note(gettext('Reconciliation complete.'))
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
108
        return reconcile_result