~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/weave_fmt/branch.py

  • Committer: Rory Yorke
  • Date: 2010-10-20 14:38:53 UTC
  • mto: This revision was merged to the branch mainline in revision 5519.
  • Revision ID: rory.yorke@gmail.com-20101020143853-9kfd2ldcjfroh8jw
Show missing files in bzr status (bug 134168).

"bzr status" will now show missing files, that is, those added with "bzr
add" and then removed by non bzr means (e.g., rm).

Blackbox tests were added for this case, and tests were also added to
test_delta, since the implementation change is in bzrlib.delta.

Might also affect bug 189709.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""Weave-era branch implementations."""
18
 
 
19
 
from bzrlib import (
20
 
    errors,
21
 
    lockable_files,
22
 
    )
23
 
 
24
 
from bzrlib.trace import mutter
25
 
 
26
 
from bzrlib.branch import (
27
 
    BranchFormat,
28
 
    BzrBranch,
29
 
    )
30
 
 
31
 
 
32
 
class PreSplitOutBzrBranch(BzrBranch):
33
 
 
34
 
    def _get_checkout_format(self):
35
 
        """Return the most suitable metadir for a checkout of this branch.
36
 
        """
37
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
38
 
        from bzrlib.bzrdir import BzrDirMetaFormat1
39
 
        format = BzrDirMetaFormat1()
40
 
        format.repository_format = RepositoryFormat7()
41
 
        return format
42
 
 
43
 
 
44
 
class BzrBranchFormat4(BranchFormat):
45
 
    """Bzr branch format 4.
46
 
 
47
 
    This format has:
48
 
     - a revision-history file.
49
 
     - a branch-lock lock file [ to be shared with the bzrdir ]
50
 
    """
51
 
 
52
 
    def initialize(self, a_bzrdir, name=None, repository=None):
53
 
        """Create a branch of this format in a_bzrdir.
54
 
 
55
 
        :param a_bzrdir: The bzrdir to initialize the branch in
56
 
        :param name: Name of colocated branch to create, if any
57
 
        :param repository: Repository for this branch (unused)
58
 
        """
59
 
        if repository is not None:
60
 
            raise NotImplementedError(
61
 
                "initialize(repository=<not None>) on %r" % (self,))
62
 
        if not [isinstance(a_bzrdir._format, format) for format in
63
 
                self._compatible_bzrdirs]:
64
 
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
65
 
        utf8_files = [('revision-history', ''),
66
 
                      ('branch-name', ''),
67
 
                      ]
68
 
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
69
 
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
70
 
        control_files = lockable_files.LockableFiles(branch_transport,
71
 
            'branch-lock', lockable_files.TransportLock)
72
 
        control_files.create_lock()
73
 
        try:
74
 
            control_files.lock_write()
75
 
        except errors.LockContention:
76
 
            lock_taken = False
77
 
        else:
78
 
            lock_taken = True
79
 
        try:
80
 
            for (filename, content) in utf8_files:
81
 
                branch_transport.put_bytes(
82
 
                    filename, content,
83
 
                    mode=a_bzrdir._get_file_mode())
84
 
        finally:
85
 
            if lock_taken:
86
 
                control_files.unlock()
87
 
        branch = self.open(a_bzrdir, name, _found=True,
88
 
                found_repository=None)
89
 
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
90
 
        return branch
91
 
 
92
 
    def __init__(self):
93
 
        super(BzrBranchFormat4, self).__init__()
94
 
        from bzrlib.plugins.weave_fmt.bzrdir import (
95
 
            BzrDirFormat4, BzrDirFormat5, BzrDirFormat6,
96
 
            )
97
 
        self._matchingbzrdir = BzrDirFormat6()
98
 
        self._compatible_bzrdirs = [BzrDirFormat4, BzrDirFormat5,
99
 
            BzrDirFormat6]
100
 
 
101
 
    def network_name(self):
102
 
        """The network name for this format is the control dirs disk label."""
103
 
        return self._matchingbzrdir.get_format_string()
104
 
 
105
 
    def get_format_description(self):
106
 
        return "Branch format 4"
107
 
 
108
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
109
 
            found_repository=None):
110
 
        """See BranchFormat.open()."""
111
 
        if name is not None:
112
 
            raise errors.NoColocatedBranchSupport(self)
113
 
        if not _found:
114
 
            # we are being called directly and must probe.
115
 
            raise NotImplementedError
116
 
        if found_repository is None:
117
 
            found_repository = a_bzrdir.open_repository()
118
 
        return PreSplitOutBzrBranch(_format=self,
119
 
                         _control_files=a_bzrdir._control_files,
120
 
                         a_bzrdir=a_bzrdir,
121
 
                         name=name,
122
 
                         _repository=found_repository)
123
 
 
124
 
    def __str__(self):
125
 
        return "Bazaar-NG branch format 4"
126
 
 
127
 
    def supports_leaving_lock(self):
128
 
        return False