# HG changeset patch # User Pierre-Yves David # Date 1315942192 -7200 # Node ID af4f7ef0a3c1538a5cf1dab5489d3eca32eb2caa # Parent aee53d5468492a158a1615bb8ab510e33a66cd94 [obsolete] extract serialization logic. diff -r aee53d546849 -r af4f7ef0a3c1 README --- 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 `` obsolete `` is set to denote that ```` is new version of ````. - -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 ====================== diff -r aee53d546849 -r af4f7ef0a3c1 hgext/obsolete.py --- 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, [], ' ')} +### 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 @@ """{ -> set()}""" 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