1
 
*** modified file 'bzrlib/commands.py'
 
6
 
         statcache.update_cache(b.base, b.read_working_inventory())
 
9
 
+class cmd_meta(Command):
 
10
 
+    """Get or set the meta information properties about a file.
 
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
 
18
 
+    bzr meta FILENAME --revision=10 # Display the meta information for a given revision
 
22
 
+    takes_args = ['filename', 'property?', 'value?']
 
23
 
+    takes_options = ['revision', 'set', 'unset']
 
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.')
 
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.')
 
35
 
+        b = Branch(filename)
 
37
 
+        file_id = inv.path2id(b.relpath(filename))
 
38
 
+        inv_entry = inv[file_id]
 
40
 
+            meta = inv_entry.meta
 
41
 
+            if meta: # Not having meta is the same as having an empty meta
 
42
 
+                keys = meta.properties.keys()
 
44
 
+                # The output really needs to be parseable
 
46
 
+                    print '%s: %r' % (key, meta.properties[key])
 
48
 
+            meta = inv_entry.meta
 
51
 
+                    value = sys.stdin.read()
 
53
 
+                    from bzrlib.inventory import Meta
 
54
 
+                    inv_entry.meta = Meta({property:value})
 
56
 
+                    inv_entry.meta.properties[property] = value
 
57
 
+                b.inventory = inv # This should cause it to be saved
 
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]
 
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]
 
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
 
84
 
*** modified file 'bzrlib/diff.py'
 
88
 
                       new_tree.get_file(file_id).readlines(),
 
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)
 
95
 
+            print '## Meta-info modified'
 
97
 
             diff_file(old_label + old_path,
 
98
 
                       old_tree.get_file(file_id).readlines(),
 
100
 
                       new_tree.get_file(file_id).readlines(),
 
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)
 
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(),
 
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:
 
120
 
                     print >>to_file, '  %s => %s %s' % (oldpath, newpath, fid)
 
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':
 
130
 
+                elif kind == 'symlink':
 
134
 
+                    print >>to_file, '  %-30s %s' % (path, fid)
 
136
 
+                    print >>to_file, ' ', path
 
138
 
         if show_unchanged and self.unchanged:
 
139
 
             print >>to_file, 'unchanged:'
 
141
 
                 ## mutter("no text to check for %r %r" % (file_id, kind))
 
142
 
                 text_modified = False
 
144
 
+            old_meta = old_inv[file_id].meta
 
145
 
+            new_meta = new_inv[file_id].meta
 
147
 
+            if old_meta != new_meta:
 
148
 
+                meta_modified = True
 
150
 
+                meta_modified = False
 
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.
 
157
 
             if old_path != new_path:
 
158
 
                 delta.renamed.append((old_path, new_path, file_id, kind,
 
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))
 
167
 
                 delta.unchanged.append((new_path, file_id, kind))
 
170
 
*** modified file 'bzrlib/inventory.py'
 
171
 
--- bzrlib/inventory.py 
 
172
 
+++ bzrlib/inventory.py 
 
175
 
 from bzrlib.osutils import uuid, quotefn, splitpath, joinpath, appendpath
 
176
 
 from bzrlib.trace import mutter
 
178
 
+class Meta(XMLMixin):
 
179
 
+    """Meta information about a single inventory entry.
 
181
 
+    This is basically just a set of key->value pairs.
 
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.
 
187
 
+    def __init__(self, properties):
 
188
 
+        self.properties = properties
 
190
 
+    def __eq__(self, other):
 
193
 
+        if not isinstance(other, Meta):
 
194
 
+            return NotImplemented
 
196
 
+        return (self.properties == other.properties)
 
198
 
+    def __ne__(self, other):
 
199
 
+        return not (self == other)
 
201
 
+    def __hash__(self):
 
202
 
+        raise ValueError('not hashable')
 
204
 
+    def from_element(cls, elt):
 
205
 
+        assert elt.tag == 'meta'
 
209
 
+            if child.tag == 'property':
 
210
 
+                if child.text is None:
 
211
 
+                    properties[child.get('name')] = ''
 
213
 
+                    properties[child.get('name')] = child.text
 
214
 
+        self = cls(properties)
 
217
 
+    from_element = classmethod(from_element)
 
219
 
+    def to_element(self):
 
220
 
+        e = Element('meta')
 
221
 
+        keys = self.properties.keys()
 
224
 
+        # The blah.text is just to make things look pretty in the files
 
225
 
+        # We may want to remove it
 
230
 
+            prop = Element('property')
 
231
 
+            prop.set('name', key)
 
232
 
+            prop.text=self.properties[key]
 
239
 
 class InventoryEntry(XMLMixin):
 
240
 
     """Description of a versioned file.
 
247
 
     def __init__(self, file_id, name, kind, parent_id, text_id=None):
 
248
 
         """Create an InventoryEntry
 
251
 
         self.text_id = text_id
 
252
 
         self.parent_id = parent_id
 
254
 
         if kind == 'directory':
 
258
 
         other.text_size = self.text_size
 
259
 
         # note that children are *not* copied; they're pulled across when
 
262
 
+            other.meta = Meta(self.meta.properties)
 
269
 
             e.set('parent_id', self.parent_id)
 
274
 
+            e.append(self.meta.to_element())
 
279
 
         v = elt.get('text_size')
 
280
 
         self.text_size = v and int(v)
 
284
 
+            if child.tag == 'meta':
 
285
 
+                self.meta = Meta.from_element(child)
 
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)
 
299
 
     def __ne__(self, other):