filelog: add metadata support
authormpm@selenic.com
Wed, 15 Jun 2005 13:04:05 -0800
changeset 360 10519e4cbd02
parent 359 0c4688e9ee5c
child 361 88268aa2b8d2
filelog: add metadata support -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 filelog: add metadata support To add metadata, we add an escape sequence "\1\n" to indicate that some key:value metadata pairs follow. manifest hash: 9a019d50f8d389b2c16cb46f4eab62c136b70fd7 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCsJfFywK+sNU5EO8RAl1AAJ9BJPgDWnot5MUdPnzPiNxlyhG0rACfVo10 6q9fGaPUpf8mxefz7G8D0Z0= =1BL6 -----END PGP SIGNATURE-----
mercurial/hg.py
--- a/mercurial/hg.py	Wed Jun 15 10:20:26 2005 -0800
+++ b/mercurial/hg.py	Wed Jun 15 13:04:05 2005 -0800
@@ -34,8 +34,29 @@
                         os.path.join("data", path + ".d"))
 
     def read(self, node):
-        return self.revision(node)
-    def add(self, text, transaction, link, p1=None, p2=None):
+        t = self.revision(node)
+        if t[:2] != '\1\n':
+            return t
+        s = t.find('\1\n', 2)
+        return t[s+2:]
+
+    def readmeta(self, node):
+        t = self.revision(node)
+        if t[:2] != '\1\n':
+            return t
+        s = t.find('\1\n', 2)
+        mt = t[2:s]
+        for l in mt.splitlines():
+            k, v = l.split(": ", 1)
+            m[k] = v
+        return m
+
+    def add(self, text, meta, transaction, link, p1=None, p2=None):
+        if meta or text[:2] == '\1\n':
+            mt = ""
+            if meta:
+                mt = [ "%s: %s\n" % (k, v) for k,v in meta.items() ]
+            text = "\1\n" + "".join(mt) + "\1\n" + text
         return self.addrevision(text, transaction, link, p1, p2)
 
     def annotate(self, node):
@@ -475,7 +496,7 @@
                 tm = is_exec(self.wjoin(f))
                 r = self.file(f)
                 mfm[f] = tm
-                mm[f] = r.add(t, tr, linkrev,
+                mm[f] = r.add(t, {}, tr, linkrev,
                               m1.get(f, nullid), m2.get(f, nullid))
                 self.dirstate.update([f], "n")
             except IOError:
@@ -538,7 +559,7 @@
             r = self.file(f)
             fp1 = m1.get(f, nullid)
             fp2 = m2.get(f, nullid)
-            new[f] = r.add(t, tr, linkrev, fp1, fp2)
+            new[f] = r.add(t, {}, tr, linkrev, fp1, fp2)
 
         # update manifest
         m1.update(new)