jeffpc added a comment.

  In https://phab.mercurial-scm.org/D2945#58586, @pulkit wrote:
  
  > There is a suggestion from @jeffpc to have a plain text header in 
statefiles like `HGStateFile` so that user can grep for them or look into files 
and know that they are state files. How does that sound?
  >  (@jeffpc I am not sure I explained this correctly, it will be great if you 
can chime in.)
  
  
  I don't really care about the actual string value, I just think it is a good 
storage design practice to have every on-disk structure contain a magic value 
of some sort.  (Beware, I have a storage background and therefore opinions 
about these things... ;) )  This makes it easier to do all sort of data 
recovery should the need arise.  E.g.,
  
  - if you know that a random file (e.g., from lost+found) is a hg state file, 
you can ignore/delete it and just reclone your repos
  - hg can detect some corruption better, and depending on the state file 
regenerate it or error out
  - hg developers can more easily sort out what's what when looking at 
buffers/files/etc.
  - as an added bonus, the magic can be used for format versioning
  
  FWIW, the three major things that I consider essential to good on-disk 
structures:
  
  1. magic numbers - see above
  2. checksums - possibly two checksums: one for the header and one for the 
payload
  3. back-pointers - see below
  
  Back-pointers allow you to tie the file/buffer into the bigger context - be 
it which state file it is, or which repository it belongs to.  In this case a 
state file's back-pointer could be something like the repo-id + state-file-name 
stored in the state file's header.  (I realize that there is no repo-id, but in 
general some approximation of it tends to be better than nothing.)  This should 
make it painfully obvious what data one is dealing with and how to 
parse/interpret it just by looking at the byte-stream without any other context.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: jeffpc, yuja, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to