~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/matchers.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-09-01 10:55:26 UTC
  • mfrom: (6110.6.3 haslayout-noversioneddirs)
  • Revision ID: pqm@pqm.ubuntu.com-20110901105526-jnqnr84fhdriyjee
(jelmer) Support repository formats without explicitly versioned directories
 in HasLayout. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    ]
34
34
 
35
35
from bzrlib import (
 
36
    osutils,
36
37
    revision as _mod_revision,
37
38
    )
38
39
 
54
55
        self.lockable_thing = lockable_thing
55
56
 
56
57
    def __str__(self):
57
 
        return ('ReturnsUnlockable(lockable_thing=%s)' % 
 
58
        return ('ReturnsUnlockable(lockable_thing=%s)' %
58
59
            self.lockable_thing)
59
60
 
60
61
    def match(self, lock_method):
131
132
        """Get the (path, file_id) pairs for the current tree."""
132
133
        tree.lock_read()
133
134
        try:
134
 
            return [(path, ie.file_id) for path, ie
135
 
                    in tree.iter_entries_by_dir()]
 
135
            for path, ie in tree.iter_entries_by_dir():
 
136
                if ie.parent_id is None:
 
137
                    yield (u"", ie.file_id)
 
138
                else:
 
139
                    yield (path+ie.kind_character(), ie.file_id)
136
140
        finally:
137
141
            tree.unlock()
138
142
 
 
143
    @staticmethod
 
144
    def _strip_unreferenced_directories(entries):
 
145
        """Strip all directories that don't (in)directly contain any files.
 
146
 
 
147
        :param entries: List of path strings or (path, ie) tuples to process
 
148
        """
 
149
        directories = []
 
150
        for entry in entries:
 
151
            if isinstance(entry, basestring):
 
152
                path = entry
 
153
            else:
 
154
                path = entry[0]
 
155
            if not path or path[-1] == "/":
 
156
                # directory
 
157
                directories.append((path, entry))
 
158
            else:
 
159
                # Yield the referenced parent directories
 
160
                for dirpath, direntry in directories:
 
161
                    if osutils.is_inside(dirpath, path):
 
162
                        yield direntry
 
163
                directories = []
 
164
                yield entry
 
165
 
139
166
    def __str__(self):
140
 
        return ('HasLayout(%r)' % self.entries)
 
167
        return 'HasLayout(%r)' % self.entries
141
168
 
142
169
    def match(self, tree):
143
 
        actual = self.get_tree_layout(tree)
 
170
        actual = list(self.get_tree_layout(tree))
144
171
        if self.entries and isinstance(self.entries[0], basestring):
145
172
            actual = [path for (path, fileid) in actual]
146
 
        return Equals(actual).match(self.entries)
 
173
        if not tree.has_versioned_directories():
 
174
            entries = list(self._strip_unreferenced_directories(self.entries))
 
175
        else:
 
176
            entries = self.entries
 
177
        return Equals(entries).match(actual)