/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3907.2.1 by Ian Clatworthy
WorkingTreeFormat5 supporting content filtering and views
1
# Copyright (C) 2008 Canonical Ltd
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""WorkingTree5 format and implementation.
18
"""
19
20
from bzrlib.lazy_import import lazy_import
21
lazy_import(globals(), """
22
from bzrlib import (
23
    workingtree_4,
24
    )
25
""")
26
27
28
class WorkingTree5(workingtree_4.WorkingTree4):
29
    """This is the Format 5 working tree.
30
31
    This differs from WorkingTree4 by:
32
     - Supporting content filtering.
33
     - Supporting a current view that may mask the set of files in a tree
34
       impacted by most user operations.
35
36
    This is new in bzr 1.11.
37
    """
38
39
40
class WorkingTreeFormat5(workingtree_4.WorkingTreeFormat4):
41
    """WorkingTree format supporting views.
42
    """
43
44
    upgrade_recommended = False
45
46
    _tree_class = WorkingTree5
47
48
    def get_format_string(self):
49
        """See WorkingTreeFormat.get_format_string()."""
50
        return "Bazaar Working Tree Format 5 (bzr 1.11)\n"
51
52
    def get_format_description(self):
53
        """See WorkingTreeFormat.get_format_description()."""
54
        return "Working tree format 5"
55
56
    def _init_custom_control_files(self, wt):
57
        """Subclasses with custom control files should override this method."""
58
        wt._transport.put_bytes('views', '', mode=wt.bzrdir._get_file_mode())
59
60
    def supports_content_filtering(self):
61
        return True
62
63
    def supports_views(self):
64
        return True
65
66
67
class Converter4to5(object):
68
    """Perform an in-place upgrade of format 4 to format 5 trees."""
69
70
    def __init__(self):
71
        self.target_format = WorkingTreeFormat5()
72
73
    def convert(self, tree):
74
        # lock the control files not the tree, so that we don't get tree
75
        # on-unlock behaviours, and so that no-one else diddles with the 
76
        # tree during upgrade.
77
        tree._control_files.lock_write()
78
        try:
79
            self.init_custom_control_files(tree)
80
            self.update_format(tree)
81
        finally:
82
            tree._control_files.unlock()
83
84
    def init_custom_control_files(self, tree):
85
        """Initialize custom control files."""
86
        tree._transport.put_bytes('views', '',
87
            mode=tree.bzrdir._get_file_mode())
88
89
    def update_format(self, tree):
90
        """Change the format marker."""
91
        tree._transport.put_bytes('format',
92
            self.target_format.get_format_string(),
93
            mode=tree.bzrdir._get_file_mode())