D2945: state: add a magicheader to each state file

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Tue Mar 27 08:58:08 EDT 2018


yuja added a comment.


  I think the magic has to vary depending on the current state file format.
  The state file must be backward/forward compatible with the older/newer formats.
  
  If the current magic is `2\n` (and is parsed as `int(f.readline())`) for example, the
  CBOR preamble would have to be `3\n`. Otherwise, old hg client cant determine
  whether the state file is corrupted or written by newer client.
  
  FWIW, last time I reviewed `simplekeyvaluefile`, I insisted that a parser should
  take a file stream instead of a filename, so the caller can handle compatibility thingy.
  
    with open("statefile", "rb") as fp:
        try:
            version = int(fp.readline())
        except ValueError:
            raise some nicer exception
        if version == 2:
            return readold(fp)
        elif version == 3:
            return readcbor(fp)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2945

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list