This is an archive of the discontinued Mercurial Phabricator instance.

histedit: use cbor to write histedit-state file
Changes PlannedPublic

Authored by pulkit on Jun 30 2018, 11:10 AM.

Details

Reviewers
durin42
Group Reviewers
hg-reviewers
Summary

This patch starts using state.cmdstate.write() which uses cbor as serialization
format to write histedit-state files.

Compatibility for reading old state files using new code is maintained.

Some changes in test which depended on the format of histedit state file.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

pulkit created this revision.Jun 30 2018, 11:10 AM
yuja added a subscriber: yuja.Jul 1 2018, 8:35 AM

Queued the first 4 patches, thanks.

$ HGEDITOR="sh $TESTTMP/editplan.sh" hg histedit --edit-plan
$ cat .hg/histedit-state
  • v1
  • 055a42cdd88768532f9cf79daa407fc8d138de9b
  • 3c6a8ed2ebe862cc949d2caa30775dd6f16fb799
  • False
  • 3
  • drop
  • e860deea161a2f77de56603b340ebbb4536308ae
  • drop
  • 652413bf663ef2a641cab26574e46d5f5a64a55a
  • drop
  • 3c6a8ed2ebe862cc949d2caa30775dd6f16fb799
  • 0
  • strip-backup/177f92b77385-0ebe6a8f-histedit.hg

+ 2

I know anything other than "v1" will make old hg crash, but I think the
version syntax should stay "v%d" (i.e. "v2" in this case.)

def _write(self, fp):
  • fp.write('v1\n')
  • fp.write('%s\n' % node.hex(self.parentctxnode))
  • fp.write('%s\n' % node.hex(self.topmost))
  • fp.write('%s\n' % ('True' if self.keep else 'False'))
  • fp.write('%d\n' % len(self.actions))

+ data = {'parentctxnode': self.parentctxnode,
+ 'topmost': self.topmost,
+ 'keep': self.keep,
+ 'backupfile': self.backupfile,
+ 'replacements': self.replacements}
+ rules = []

for action in self.actions:
  • fp.write('%s\n' % action.tostate())
  • fp.write('%d\n' % len(self.replacements))
  • for replacement in self.replacements:
  • fp.write('%s%s\n' % (node.hex(replacement[0]), ''.join(node.hex(r)
  • for r in replacement[1])))
  • backupfile = self.backupfile
  • if not backupfile:
  • backupfile = ''
  • fp.write('%s\n' % backupfile)

+ rules.append(action.tostate().split('\n'))
+ rules = "\n".join(["%s %s" % (verb, rest) for [verb, rest] in rules])

Isn't it better to serialize [(verb, rest)] as is since CBOR can store that?

pulkit added a comment.Jul 1 2018, 5:11 PM
In D3866#60421, @yuja wrote:

Queued the first 4 patches, thanks.

$ HGEDITOR="sh $TESTTMP/editplan.sh" hg histedit --edit-plan
$ cat .hg/histedit-state
  • v1
  • 055a42cdd88768532f9cf79daa407fc8d138de9b
  • 3c6a8ed2ebe862cc949d2caa30775dd6f16fb799
  • False
  • 3
  • drop
  • e860deea161a2f77de56603b340ebbb4536308ae
  • drop
  • 652413bf663ef2a641cab26574e46d5f5a64a55a
  • drop
  • 3c6a8ed2ebe862cc949d2caa30775dd6f16fb799
  • 0
  • strip-backup/177f92b77385-0ebe6a8f-histedit.hg

+ 2

I know anything other than "v1" will make old hg crash, but I think the
version syntax should stay "v%d" (i.e. "v2" in this case.)

Yeah, I think we need to pass version number in the state.cmdstate.read(). Supporting rebasestate will also need similar tweak.

def _write(self, fp):
  • fp.write('v1\n')
  • fp.write('%s\n' % node.hex(self.parentctxnode))
  • fp.write('%s\n' % node.hex(self.topmost))
  • fp.write('%s\n' % ('True' if self.keep else 'False'))
  • fp.write('%d\n' % len(self.actions))

+ data = {'parentctxnode': self.parentctxnode,
+ 'topmost': self.topmost,
+ 'keep': self.keep,
+ 'backupfile': self.backupfile,
+ 'replacements': self.replacements}
+ rules = []

for action in self.actions:
  • fp.write('%s\n' % action.tostate())
  • fp.write('%d\n' % len(self.replacements))
  • for replacement in self.replacements:
  • fp.write('%s%s\n' % (node.hex(replacement[0]), ''.join(node.hex(r)
  • for r in replacement[1])))
  • backupfile = self.backupfile
  • if not backupfile:
  • backupfile = ''
  • fp.write('%s\n' % backupfile)

+ rules.append(action.tostate().split('\n'))
+ rules = "\n".join(["%s %s" % (verb, rest) for [verb, rest] in rules])

Isn't it better to serialize [(verb, rest)] as is since CBOR can store that?

Yeah, it's better. I will do that.

pulkit planned changes to this revision.Jul 9 2018, 2:31 PM

I am not confident to land some state format changes at this point in the cycle. Let's do it early in next cycle.