Mercurial > evolve
changeset 62:bd33e749dfcc
[states] move IO logic outside the repository subclass
This is meant to lighted this part a bit
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 12 Sep 2011 19:35:50 +0200 |
parents | 0dfe459c7b1c |
children | f47a5f990eb2 |
files | hgext/states.py |
diffstat | 1 files changed, 56 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/states.py Mon Sep 12 19:23:35 2011 +0200 +++ b/hgext/states.py Mon Sep 12 19:35:50 2011 +0200 @@ -572,6 +572,58 @@ 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): @@ -605,6 +657,8 @@ if state.trackheads: revset.symbols[state.headssymbol] = state._revsetheads + + def reposetup(ui, repo): """Repository setup @@ -654,57 +708,7 @@ @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. @@ -720,7 +724,7 @@ 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