comparison tests/autodiff.py @ 10189:e451e599fbcf

patch: support diff data loss detection and upgrade In worst case, generating diff in upgrade mode can be two times more expensive than generating it in git mode directly: we may have to regenerate the whole diff again whenever a git feature is detected. Also, the first diff attempt is completely buffered instead of being streamed. That said, even without having profiled it yet, I am convinced we can fast-path the upgrade mode if necessary were it to be used in regular diff commands, and not only in mq where avoiding data loss is worth the price.
author Patrick Mezard <pmezard@gmail.com>
date Fri, 01 Jan 2010 20:54:05 +0100
parents
children b33f3e35efb0
comparison
equal deleted inserted replaced
10188:fd6e9c7cd98c 10189:e451e599fbcf
1 # Extension dedicated to test patch.diff() upgrade modes
2 #
3 #
4 from mercurial import cmdutil, patch, util
5
6 def autodiff(ui, repo, *pats, **opts):
7 diffopts = patch.diffopts(ui, opts)
8 git = opts.get('git', 'no')
9 brokenfiles = set()
10 losedatafn = None
11 if git in ('yes', 'no'):
12 diffopts.git = git == 'yes'
13 diffopts.upgrade = False
14 elif git == 'auto':
15 diffopts.git = False
16 diffopts.upgrade = True
17 elif git == 'warn':
18 diffopts.git = False
19 diffopts.upgrade = True
20 def losedatafn(fn=None, **kwargs):
21 brokenfiles.add(fn)
22 return True
23 elif git == 'abort':
24 diffopts.git = False
25 diffopts.upgrade = True
26 def losedatafn(fn=None, **kwargs):
27 raise util.Abort('losing data for %s' % fn)
28 else:
29 raise util.Abort('--git must be yes, no or auto')
30
31 node1, node2 = cmdutil.revpair(repo, [])
32 m = cmdutil.match(repo, pats, opts)
33 it = patch.diff(repo, node1, node2, match=m, opts=diffopts,
34 losedatafn=losedatafn)
35 for chunk in it:
36 ui.write(chunk)
37 for fn in sorted(brokenfiles):
38 ui.write('data lost for: %s\n' % fn)
39
40 cmdtable = {
41 "autodiff":
42 (autodiff,
43 [('', 'git', '', 'git upgrade mode (yes/no/auto/warn/abort)'),
44 ],
45 '[OPTION]... [FILE]...'),
46 }