/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to patches/meta-data-in-inventory.patch

  • Committer: Robert Collins
  • Date: 2008-01-06 20:04:22 UTC
  • mto: (3221.11.1 StackableBranch)
  • mto: This revision was merged to the branch mainline in revision 3226.
  • Revision ID: robertc@robertcollins.net-20080106200422-x8yz6cxotlzltvwp
The bzrdir format registry now accepts an ``alias`` keyword to
register_metadir, used to indicate that a format name is an alias for
some other format and thus should not be reported when describing the
format. (Robert Collins)
-------------- This line and the fmllowing will be ignored --------------

modified:
  NEWS
  bzrlib/bzrdir.py
  bzrlib/info.py
  bzrlib/tests/test_bzrdir.py
  bzrlib/tests/test_info.py

=== modified file 'NEWS'
--- a/NEWS      2008-01-02 22:30:46 +0000
+++ b/NEWS      2008-01-06 20:04:15 +0000
@@ -135,6 +135,11 @@
     * Patience Diff now supports arbitrary python objects, as long as they
       support ``hash()``. (John Arbash Meinel)
 
+    * The bzrdir format registry now accepts an ``alias`` keyword to
+      register_metadir, used to indicate that a format name is an alias for
+      some other format and thus should not be reported when describing the
+      format. (Robert Collins)
+
   API BREAKS:
 
   TESTING:

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py  2008-01-02 22:30:46 +0000
+++ b/bzrlib/bzrdir.py  2008-01-06 19:41:29 +0000
@@ -2447,12 +2447,22 @@
     e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
     """
 
+    def __init__(self):
+        """Create a BzrDirFormatRegistry."""
+        self._aliases = set()
+        super(BzrDirFormatRegistry, self).__init__()
+
+    def aliases(self):
+        """Return a set of the format names which are aliases."""
+        return frozenset(self._aliases)
+
     def register_metadir(self, key,
              repository_format, help, native=True, deprecated=False,
              branch_format=None,
              tree_format=None,
              hidden=False,
-             experimental=False):
+             experimental=False,
+             alias=False):
         """Register a metadir subformat.
 
         These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
@@ -2491,10 +2501,10 @@
                 bd.repository_format = _load(repository_format)
             return bd
         self.register(key, helper, help, native, deprecated, hidden,
-            experimental)
+            experimental, alias)
 
     def register(self, key, factory, help, native=True, deprecated=False,
-                 hidden=False, experimental=False):
+                 hidden=False, experimental=False, alias=False):
         """Register a BzrDirFormat factory.
         
         The factory must be a callable that takes one parameter: the key.
@@ -2505,11 +2515,15 @@
         """
         registry.Registry.register(self, key, factory, help,
             BzrDirFormatInfo(native, deprecated, hidden, experimental))
+        if alias:
+            self._aliases.add(key)
 
     def register_lazy(self, key, module_name, member_name, help, native=True,
-                      deprecated=False, hidden=False, experimental=False):
+        deprecated=False, hidden=False, experimental=False, alias=False):
         registry.Registry.register_lazy(self, key, module_name, member_name,
             help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
+        if alias:
+            self._aliases.add(key)
 
     def set_default(self, key):
         """Set the 'default' key to be a clone of the supplied key.
@@ -2518,6 +2532,7 @@
         """
         registry.Registry.register(self, 'default', self.get(key),
             self.get_help(key), info=self.get_info(key))
+        self._aliases.add('default')
 
     def set_default_repository(self, key):
         """Set the FormatRegistry default and Repository default.
@@ -2670,6 +2685,7 @@
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     hidden=False,
     )
+# The following two formats should always just be aliases.
 format_registry.register_metadir('development',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
     help='Current development format. Can convert data to and from pack-0.92 '
@@ -2681,6 +2697,7 @@
     branch_format='bzrlib.branch.BzrBranchFormat6',
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     experimental=True,
+    alias=True,
     )
 format_registry.register_metadir('development-subtree',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
@@ -2693,7 +2710,9 @@
     branch_format='bzrlib.branch.BzrBranchFormat6',
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     experimental=True,
+    alias=True,
     )
+# And the development formats which the will have aliased one of follow:
 format_registry.register_metadir('development0',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
     help='Trivial rename of pack-0.92 to provide a development format. '

=== modified file 'bzrlib/info.py'
--- a/bzrlib/info.py    2007-11-06 09:00:25 +0000
+++ b/bzrlib/info.py    2008-01-06 20:01:30 +0000
@@ -440,7 +440,9 @@
         tree.bzrdir.root_transport.base):
         branch = None
         repository = None
-    for key in bzrdir.format_registry.keys():
+    non_aliases = set(bzrdir.format_registry.keys())
+    non_aliases.difference_update(bzrdir.format_registry.aliases())
+    for key in non_aliases:
         format = bzrdir.format_registry.make_bzrdir(key)
         if isinstance(format, bzrdir.BzrDirMetaFormat1):
             if (tree and format.workingtree_format !=
@@ -457,11 +459,12 @@
         candidates.append(key)
     if len(candidates) == 0:
         return 'unnamed'
-    new_candidates = [c for c in candidates if c != 'default']
-    if len(new_candidates) > 0:
-        candidates = new_candidates
+    candidates.sort()
     new_candidates = [c for c in candidates if not
         bzrdir.format_registry.get_info(c).hidden]
     if len(new_candidates) > 0:
+        # If there are any non-hidden formats that match, only return those to
+        # avoid listing hidden formats except when only a hidden format will
+        # do.
         candidates = new_candidates
     return ' or '.join(candidates)

=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py       2007-12-21 20:32:22 +0000
+++ b/bzrlib/tests/test_bzrdir.py       2008-01-06 19:45:00 +0000
@@ -170,6 +170,16 @@
         finally:
             bzrdir.format_registry.set_default_repository(old_default)
 
+    def test_aliases(self):
+        a_registry = bzrdir.BzrDirFormatRegistry()
+        a_registry.register('weave', bzrdir.BzrDirFormat6,
+            'Pre-0.8 format.  Slower and does not support checkouts or shared'
+            ' repositories', deprecated=True)
+        a_registry.register('weavealias', bzrdir.BzrDirFormat6,
+            'Pre-0.8 format.  Slower and does not support checkouts or shared'
+            ' repositories', deprecated=True, alias=True)
+        self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
+    
 
 class SampleBranch(bzrlib.branch.Branch):
     """A dummy branch for guess what, dummy use."""

=== modified file 'bzrlib/tests/test_info.py'
--- a/bzrlib/tests/test_info.py 2007-11-26 13:55:51 +0000
+++ b/bzrlib/tests/test_info.py 2008-01-06 20:02:10 +0000
@@ -126,16 +126,22 @@
 
     def test_describe_tree_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             self.assertTreeDescription(key)
 
     def test_describe_checkout_format(self):
         for key in bzrdir.format_registry.keys():
-            if key in ('default', 'weave', 'experimental'):
-                continue
-            if key.startswith('experimental-'):
-                # these are typically hidden or aliases for other formats
+            if key in bzrdir.format_registry.aliases():
+                # Aliases will not describe correctly in the UI because the
+                # real format is found.
+                continue
+            # legacy: weave does not support checkouts
+            if key == 'weave':
+                continue
+            if bzrdir.format_registry.get_info(key).experimental:
+                # We don't require that experimental formats support checkouts
+                # or describe correctly in the UI.
                 continue
             expected = None
             if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree',
@@ -149,7 +155,7 @@
 
     def test_describe_branch_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             expected = None
             if key in ('dirstate', 'knit'):
@@ -158,7 +164,7 @@
 
     def test_describe_repo_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             expected = None
             if key in ('dirstate', 'knit', 'dirstate-tags'):

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
*** modified file 'bzrlib/commands.py'
2
 
--- bzrlib/commands.py 
3
 
+++ bzrlib/commands.py 
4
 
@@ -1175,7 +1175,68 @@
5
 
         b = Branch('.')
6
 
         statcache.update_cache(b.base, b.read_working_inventory())
7
 
 
8
 
-
9
 
+class cmd_meta(Command):
10
 
+    """Get or set the meta information properties about a file.
11
 
+
12
 
+    bzr meta FILENAME # Display all meta information
13
 
+    bzr meta FILENAME prop # Display the value of meta-info named prop, return error if not found
14
 
+    bzr meta FILENAME --set prop value # Set the value of prop to value
15
 
+    echo "the value" | bzr meta FILENAME --set prop # Set the value to whatever is read from stdin
16
 
+    bzr meta FILENAME --unset prop # Remove the property
17
 
+
18
 
+    bzr meta FILENAME --revision=10 # Display the meta information for a given revision
19
 
+        (Not supported yet)
20
 
+    """
21
 
+    hidden = True
22
 
+    takes_args = ['filename', 'property?', 'value?']
23
 
+    takes_options = ['revision', 'set', 'unset']
24
 
+
25
 
+    def run(self, filename, property=None, value=None, revision=None, set=False, unset=False):
26
 
+        if isinstance(revision, list) and len(revision) > 1:
27
 
+            raise BzrCommandError('bzr meta takes at most 1 revision.')
28
 
+        if revision is not None and (set or unset):
29
 
+            raise BzrCommandError('Cannot set/unset meta information in an old version.')
30
 
+        if set and unset:
31
 
+            raise BzrCommandError('Cannot set and unset at the same time')
32
 
+        if not set and value:
33
 
+            raise BzrCommandError('You must supply --set if you want to set the value of a property.')
34
 
+
35
 
+        b = Branch(filename)
36
 
+        inv = b.inventory
37
 
+        file_id = inv.path2id(b.relpath(filename))
38
 
+        inv_entry = inv[file_id]
39
 
+        if not property:
40
 
+            meta = inv_entry.meta
41
 
+            if meta: # Not having meta is the same as having an empty meta
42
 
+                keys = meta.properties.keys()
43
 
+                keys.sort()
44
 
+                # The output really needs to be parseable
45
 
+                for key in keys:
46
 
+                    print '%s: %r' % (key, meta.properties[key])
47
 
+        else:
48
 
+            meta = inv_entry.meta
49
 
+            if set:
50
 
+                if value is None:
51
 
+                    value = sys.stdin.read()
52
 
+                if not meta:
53
 
+                    from bzrlib.inventory import Meta
54
 
+                    inv_entry.meta = Meta({property:value})
55
 
+                else:
56
 
+                    inv_entry.meta.properties[property] = value
57
 
+                b.inventory = inv # This should cause it to be saved
58
 
+            elif unset:
59
 
+                if not meta or not meta.properties.has_key(property):
60
 
+                    return 3 # Cannot unset a property that doesn't exist
61
 
+                    # I wonder if this should be a different return code
62
 
+                del inv_entry.meta.properties[property]
63
 
+                b.inventory = inv
64
 
+            else:
65
 
+                if not meta or not meta.properties.has_key(property):
66
 
+                    return 3 # Missing property
67
 
+                # Probably this should not be print, but 
68
 
+                # sys.stdout.write() so that you get back exactly
69
 
+                # what was given. But I'm leaving it this way for now
70
 
+                print meta.properties[property]
71
 
 
72
 
 # list of all available options; the rhs can be either None for an
73
 
 # option that takes no argument, or a constructor function that checks
74
 
@@ -1196,6 +1257,8 @@
75
 
     'verbose':                None,
76
 
     'version':                None,
77
 
     'email':                  None,
78
 
+    'set':                    None,
79
 
+    'unset':                  None,
80
 
     }
81
 
 
82
 
 SHORT_OPTIONS = {
83
 
 
84
 
*** modified file 'bzrlib/diff.py'
85
 
--- bzrlib/diff.py 
86
 
+++ bzrlib/diff.py 
87
 
@@ -226,8 +226,10 @@
88
 
                       new_tree.get_file(file_id).readlines(),
89
 
                       to_file)
90
 
 
91
 
-    for old_path, new_path, file_id, kind, text_modified in delta.renamed:
92
 
+    for old_path, new_path, file_id, kind, text_modified, meta_modified in delta.renamed:
93
 
         print '*** renamed %s %r => %r' % (kind, old_path, new_path)
94
 
+        if meta_modified:
95
 
+            print '## Meta-info modified'
96
 
         if text_modified:
97
 
             diff_file(old_label + old_path,
98
 
                       old_tree.get_file(file_id).readlines(),
99
 
@@ -235,9 +237,11 @@
100
 
                       new_tree.get_file(file_id).readlines(),
101
 
                       to_file)
102
 
 
103
 
-    for path, file_id, kind in delta.modified:
104
 
+    for path, file_id, kind, text_modified, meta_modified in delta.modified:
105
 
         print '*** modified %s %r' % (kind, path)
106
 
-        if kind == 'file':
107
 
+        if meta_modified:
108
 
+            print '## Meta-info modified'
109
 
+        if kind == 'file' and text_modified:
110
 
             diff_file(old_label + path,
111
 
                       old_tree.get_file(file_id).readlines(),
112
 
                       new_label + path,
113
 
@@ -316,7 +320,7 @@
114
 
 
115
 
         if self.renamed:
116
 
             print >>to_file, 'renamed:'
117
 
-            for oldpath, newpath, fid, kind, text_modified in self.renamed:
118
 
+            for oldpath, newpath, fid, kind, text_modified, meta_modified in self.renamed:
119
 
                 if show_ids:
120
 
                     print >>to_file, '  %s => %s %s' % (oldpath, newpath, fid)
121
 
                 else:
122
 
@@ -324,7 +328,16 @@
123
 
                     
124
 
         if self.modified:
125
 
             print >>to_file, 'modified:'
126
 
-            show_list(self.modified)
127
 
+            for path, fid, kind, text_modified, meta_modified in self.modified:
128
 
+                if kind == 'directory':
129
 
+                    path += '/'
130
 
+                elif kind == 'symlink':
131
 
+                    path += '@'
132
 
+                    
133
 
+                if show_ids:
134
 
+                    print >>to_file, '  %-30s %s' % (path, fid)
135
 
+                else:
136
 
+                    print >>to_file, ' ', path
137
 
             
138
 
         if show_unchanged and self.unchanged:
139
 
             print >>to_file, 'unchanged:'
140
 
@@ -388,6 +401,14 @@
141
 
                 ## mutter("no text to check for %r %r" % (file_id, kind))
142
 
                 text_modified = False
143
 
 
144
 
+            old_meta = old_inv[file_id].meta
145
 
+            new_meta = new_inv[file_id].meta
146
 
+
147
 
+            if old_meta != new_meta:
148
 
+                meta_modified = True
149
 
+            else:
150
 
+                meta_modified = False
151
 
+
152
 
             # TODO: Can possibly avoid calculating path strings if the
153
 
             # two files are unchanged and their names and parents are
154
 
             # the same and the parents are unchanged all the way up.
155
 
@@ -395,9 +416,10 @@
156
 
             
157
 
             if old_path != new_path:
158
 
                 delta.renamed.append((old_path, new_path, file_id, kind,
159
 
-                                      text_modified))
160
 
-            elif text_modified:
161
 
-                delta.modified.append((new_path, file_id, kind))
162
 
+                                      text_modified, meta_modified))
163
 
+            elif text_modified or meta_modified:
164
 
+                delta.modified.append((new_path, file_id, kind,
165
 
+                                       text_modified, meta_modified))
166
 
             elif want_unchanged:
167
 
                 delta.unchanged.append((new_path, file_id, kind))
168
 
         else:
169
 
 
170
 
*** modified file 'bzrlib/inventory.py'
171
 
--- bzrlib/inventory.py 
172
 
+++ bzrlib/inventory.py 
173
 
@@ -33,6 +33,67 @@
174
 
 import bzrlib
175
 
 from bzrlib.osutils import uuid, quotefn, splitpath, joinpath, appendpath
176
 
 from bzrlib.trace import mutter
177
 
+
178
 
+class Meta(XMLMixin):
179
 
+    """Meta information about a single inventory entry.
180
 
+
181
 
+    This is basically just a set of key->value pairs.
182
 
+
183
 
+    In general, bzr does not handle this information, it only provides
184
 
+    a location for plugins and other data sources to store this data.
185
 
+
186
 
+    """
187
 
+    def __init__(self, properties):
188
 
+        self.properties = properties
189
 
+
190
 
+    def __eq__(self, other):
191
 
+        if other is None:
192
 
+            return False
193
 
+        if not isinstance(other, Meta):
194
 
+            return NotImplemented
195
 
+
196
 
+        return (self.properties == other.properties)
197
 
+
198
 
+    def __ne__(self, other):
199
 
+        return not (self == other)
200
 
+
201
 
+    def __hash__(self):
202
 
+        raise ValueError('not hashable')
203
 
+
204
 
+    def from_element(cls, elt):
205
 
+        assert elt.tag == 'meta'
206
 
+
207
 
+        properties = {}
208
 
+        for child in elt:
209
 
+            if child.tag == 'property':
210
 
+                if child.text is None:
211
 
+                    properties[child.get('name')] = ''
212
 
+                else:
213
 
+                    properties[child.get('name')] = child.text
214
 
+        self = cls(properties)
215
 
+        return self
216
 
+
217
 
+    from_element = classmethod(from_element)
218
 
+
219
 
+    def to_element(self):
220
 
+        e = Element('meta')
221
 
+        keys = self.properties.keys()
222
 
+        keys.sort()
223
 
+
224
 
+        # The blah.text is just to make things look pretty in the files
225
 
+        # We may want to remove it
226
 
+        if len(keys) > 0:
227
 
+            e.text = '\n'
228
 
+
229
 
+        for key in keys:
230
 
+            prop = Element('property')
231
 
+            prop.set('name', key)
232
 
+            prop.text=self.properties[key]
233
 
+            prop.tail='\n'
234
 
+            e.append(prop)
235
 
+
236
 
+        return e
237
 
+
238
 
 
239
 
 class InventoryEntry(XMLMixin):
240
 
     """Description of a versioned file.
241
 
@@ -100,6 +161,7 @@
242
 
 
243
 
     text_sha1 = None
244
 
     text_size = None
245
 
+    meta = None
246
 
     
247
 
     def __init__(self, file_id, name, kind, parent_id, text_id=None):
248
 
         """Create an InventoryEntry
249
 
@@ -124,6 +186,7 @@
250
 
         self.kind = kind
251
 
         self.text_id = text_id
252
 
         self.parent_id = parent_id
253
 
+        self.meta = None
254
 
         if kind == 'directory':
255
 
             self.children = {}
256
 
         elif kind == 'file':
257
 
@@ -146,6 +209,10 @@
258
 
         other.text_size = self.text_size
259
 
         # note that children are *not* copied; they're pulled across when
260
 
         # others are added
261
 
+        if self.meta:
262
 
+            other.meta = Meta(self.meta.properties)
263
 
+        else:
264
 
+            other.meta = None
265
 
         return other
266
 
 
267
 
 
268
 
@@ -182,6 +249,9 @@
269
 
             e.set('parent_id', self.parent_id)
270
 
 
271
 
         e.tail = '\n'
272
 
+
273
 
+        if self.meta:
274
 
+            e.append(self.meta.to_element())
275
 
             
276
 
         return e
277
 
 
278
 
@@ -205,6 +275,11 @@
279
 
         v = elt.get('text_size')
280
 
         self.text_size = v and int(v)
281
 
 
282
 
+        self.meta = None
283
 
+        for child in elt:
284
 
+            if child.tag == 'meta':
285
 
+                self.meta = Meta.from_element(child)
286
 
+
287
 
         return self
288
 
             
289
 
 
290
 
@@ -220,7 +295,8 @@
291
 
                and (self.text_size == other.text_size) \
292
 
                and (self.text_id == other.text_id) \
293
 
                and (self.parent_id == other.parent_id) \
294
 
-               and (self.kind == other.kind)
295
 
+               and (self.kind == other.kind) \
296
 
+               and (self.meta == other.meta)
297
 
 
298
 
 
299
 
     def __ne__(self, other):
300