Commits

Pierre-Yves David  committed bd33e74

[states] move IO logic outside the repository subclass

This is meant to lighted this part a bit

  • Participants
  • Parent commits 0dfe459
  • Branches default

Comments (0)

Files changed (1)

File hgext/states.py

         heads = remote._reducehead(heads)
     return common, anyinc, heads
 
+# states boundary IO
+#####################
+
+def _readheadsfile(repo, filename):
+    """read head from the given file
+
+    XXX move me elsewhere"""
+    heads = [nullid]
+    try:
+        f = repo.opener(filename)
+        try:
+            heads = sorted([node.bin(n) for n in f.read().split() if n])
+        finally:
+            f.close()
+    except IOError:
+        pass
+    return heads
+
+def _readstatesheads(repo, undo=False):
+    """read all state heads
+
+    XXX move me elsewhere"""
+    statesheads = {}
+    for state in STATES:
+        if state.trackheads:
+            filemask = 'states/%s-heads'
+            filename = filemask % state.name
+            statesheads[state] = _readheadsfile(repo, filename)
+    return statesheads
+
+def _writeheadsfile(repo, filename, heads):
+    """write given <heads> in the file with at <filename>
+
+    XXX move me elsewhere"""
+    f = repo.opener(filename, 'w', atomictemp=True)
+    try:
+        for h in heads:
+            f.write(hex(h) + '\n')
+        f.rename()
+    finally:
+        f.close()
+
+def _writestateshead(repo):
+    """write all heads
+
+    XXX move me elsewhere"""
+    # XXX transaction!
+    for state in STATES:
+        if state.trackheads:
+            filename = 'states/%s-heads' % state.name
+            _writeheadsfile(repo, filename, repo._statesheads[state])
+
 # WireProtocols
 ####################
 def wireheads(repo, proto):
         if state.trackheads:
             revset.symbols[state.headssymbol] = state._revsetheads
 
+
+
 def reposetup(ui, repo):
     """Repository setup
 
         @util.propertycache
         def _statesheads(self):
             """{ state-object -> set(defining head)} mapping"""
-            return self._readstatesheads()
-
-
-        def _readheadsfile(self, filename):
-            """read head from the given file
-
-            XXX move me elsewhere"""
-            heads = [nullid]
-            try:
-                f = self.opener(filename)
-                try:
-                    heads = sorted([node.bin(n) for n in f.read().split() if n])
-                finally:
-                    f.close()
-            except IOError:
-                pass
-            return heads
-
-        def _readstatesheads(self, undo=False):
-            """read all state heads
-
-            XXX move me elsewhere"""
-            statesheads = {}
-            for state in STATES:
-                if state.trackheads:
-                    filemask = 'states/%s-heads'
-                    filename = filemask % state.name
-                    statesheads[state] = self._readheadsfile(filename)
-            return statesheads
-
-        def _writeheadsfile(self, filename, heads):
-            """write given <heads> in the file with at <filename>
-
-            XXX move me elsewhere"""
-            f = self.opener(filename, 'w', atomictemp=True)
-            try:
-                for h in heads:
-                    f.write(hex(h) + '\n')
-                f.rename()
-            finally:
-                f.close()
-
-        def _writestateshead(self):
-            """write all heads
-
-            XXX move me elsewhere"""
-            # XXX transaction!
-            for state in STATES:
-                if state.trackheads:
-                    filename = 'states/%s-heads' % state.name
-                    self._writeheadsfile(filename, self._statesheads[state])
+            return _readstatesheads(self)
 
         def setstate(self, state, nodes):
             """change state of targets changeset and it's ancestors.
                 heads[:] = noderange(repo, ["heads(::%s())" % state.headssymbol])
                 heads.sort()
             if olds != heads:
-                self._writestateshead()
+                _writestateshead(self)
             if state.next is not None and state.next.trackheads:
                 self.setstate(state.next, nodes) # cascading