changeset 70:af4f7ef0a3c1

[obsolete] extract serialization logic.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 13 Sep 2011 21:29:52 +0200
parents aee53d546849
children 19e1930587a0
files README hgext/obsolete.py
diffstat 2 files changed, 24 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/README	Tue Sep 13 21:15:31 2011 +0200
+++ b/README	Tue Sep 13 21:29:52 2011 +0200
@@ -28,49 +28,6 @@
 
 
 
-Obsolete Extension
-======================
-
-state: in progress
-
-This extension introduces the *obsolete* concept. It adds a new *obsolete*
-relation between two changesets. A relation ``<changeset B> obsolete <changeset
-A>`` is set to denote that ``<changeset B>`` is new version of ``<changeset
-A>``.
-
-The *obsolete* relation act as a **perpendicular history** to the standard
-changeset history. Standard changeset history versions files. The *obsolete*
-relation versions changesets.
-
-Usage and Feature
-------------------
-
-obsolete changesets are hidden.
-
-Commands
-........
-
-
-a ``debugobsolete`` command has been added.
-
-
-To Do
------
-
-* do not exchange them
-
-* handle non-obsolete children
-
-* exchange the obsolete information
-
-* refuse to obsolete published changesets
-
-* handle split
-
-* handle conflict
-
-* handle out of sync
-
 rewrite Extension
 ======================
 
--- a/hgext/obsolete.py	Tue Sep 13 21:15:31 2011 +0200
+++ b/hgext/obsolete.py	Tue Sep 13 21:29:52 2011 +0200
@@ -55,6 +55,9 @@
 
 Add an ``obsolete()`` entry.
 
+repo extension
+..............
+
 To Do
 -----
 
@@ -158,7 +161,7 @@
         tmp = StringIO()
         tmp.write(raw)
         tmp.seek(0)
-        relations = repo._obsdeserialise(tmp)
+        relations = _obsdeserialise(tmp)
         for sub, objs in relations.iteritems():
             for obj in objs:
                 try:
@@ -171,7 +174,7 @@
 
 def listobsolete(repo):
     tmp = StringIO()
-    repo._obsserialise(tmp)
+    _obsserialise(repo._obssubrels, tmp)
     return {'relations': tmp.getvalue()}
 
 pushkey.register('obsolete', pushobsolete, listobsolete)
@@ -191,6 +194,21 @@
 
 cmdtable = {'debugobsolete': (cmddebugobsolete, [], '<subject> <object>')}
 
+### serialisation
+#############################
+
+def _obsserialise(obssubrels, flike):
+    for sub, objs in obssubrels.iteritems():
+        for obj in objs:
+            flike.write('%s %s\n' % (hex(sub), hex(obj)))
+
+def _obsdeserialise(flike):
+    rels = {}
+    for line in flike:
+        subhex, objhex = line.split()
+        rels.setdefault(bin(subhex), set()).add(bin(objhex))
+    return rels
+
 def reposetup(ui, repo):
 
     if not repo.local():
@@ -247,20 +265,6 @@
             """{<new-node> -> set(<old-node>)}"""
             return self._readobsrels()
 
-        ### serialisation
-        # XXX get this out the repo
-
-        def _obsserialise(self, flike):
-            for sub, objs in self._obssubrels.iteritems():
-                for obj in objs:
-                    flike.write('%s %s\n' % (hex(sub), hex(obj)))
-
-        def _obsdeserialise(self,flike):
-            rels = {}
-            for line in flike:
-                subhex, objhex = line.split()
-                rels.setdefault(bin(subhex), set()).add(bin(objhex))
-            return rels
 
 
 
@@ -271,7 +275,7 @@
             try:
                 f = self.opener('obsolete-relations')
                 try:
-                    return self._obsdeserialise(f)
+                    return _obsdeserialise(f)
                 finally:
                     f.close()
             except IOError:
@@ -282,7 +286,7 @@
             # XXX handle lock
             f = self.opener('obsolete-relations', 'w', atomictemp=True)
             try:
-                self._obsserialise(f)
+                _obsserialise(self._obssubrels, f)
                 f.rename()
             finally:
                 f.close()
@@ -300,7 +304,7 @@
                 tmp = StringIO()
                 tmp.write(remote.listkeys('obsolete')['relations'])
                 tmp.seek(0)
-                obsrels = repo._obsdeserialise(tmp)
+                obsrels = _obsdeserialise(tmp)
                 for sub, objs in obsrels.iteritems():
                     for obj in objs:
                         self.addobsolete(sub, obj)
@@ -310,7 +314,7 @@
             result = opush(remote, *args, **opts)
             if 'obsolete' in remote.listkeys('namespaces'):
                 tmp = StringIO()
-                repo._obsserialise(tmp)
+                _obsserialise(self._obssubrels, tmp)
                 remote.pushkey('obsolete', 'relations', '', tmp.getvalue())
 
             return result