# HG changeset patch # User Pierre-Yves.David@ens-lyon.org # Date 2012-07-12 17:58:07 # Node ID 494a970f68deb6b27cc21552ecbf46e07d2e2bc0 # Parent b8661d7c940f958e6540cf174cb88dc85468146b obsolete: refactor writemarkers to only encode them The function is now able to write the version header as necessary. The function now yield bytes to be written to a stream. This should ease later use of this function for wireprotocol based exchanged. Prepare the public use of the writemarker by wireprotocol function. diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py --- a/mercurial/obsolete.py +++ b/mercurial/obsolete.py @@ -203,10 +203,9 @@ class obsstore(object): f.seek(0, 2) # os.SEEK_END offset = f.tell() transaction.add('obsstore', offset) - if offset == 0: - # new file add version header - f.write(_pack('>B', _fmversion)) - _writemarkers(f.write, [marker]) + # offset == 0: new file - add the version header + for bytes in _encodemarkers([marker], offset == 0): + f.write(bytes) finally: # XXX: f.close() == filecache invalidation == obsstore rebuilt. # call 'filecacheentry.refresh()' here @@ -229,25 +228,26 @@ class obsstore(object): for suc in sucs: self.successors.setdefault(suc, set()).add(marker) -def _writemarkers(write, markers): +def _encodemarkers(markers, addheader=False): # Kept separate from flushmarkers(), it will be reused for # markers exchange. + if addheader: + yield _pack('>B', _fmversion) for marker in markers: pre, sucs, flags, metadata = marker nbsuc = len(sucs) format = _fmfixed + (_fmnode * nbsuc) data = [nbsuc, len(metadata), flags, pre] data.extend(sucs) - write(_pack(format, *data)) - write(metadata) + yield _pack(format, *data) + yield metadata def listmarkers(repo): """List markers over pushkey""" if not repo.obsstore: return {} - data = [_pack('>B', _fmversion)] - _writemarkers(data.append, repo.obsstore) - return {'dump': base85.b85encode(''.join(data))} + markers = _encodemarkers(repo.obsstore, True) + return {'dump': base85.b85encode(''.join(markers))} def pushmarker(repo, key, old, new): """Push markers over pushkey"""