tests/autodiff.py
changeset 43076 2372284d9457
parent 37368 cdccfe20eed7
child 48117 b74e128676d4
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
    11 )
    11 )
    12 
    12 
    13 cmdtable = {}
    13 cmdtable = {}
    14 command = registrar.command(cmdtable)
    14 command = registrar.command(cmdtable)
    15 
    15 
    16 @command(b'autodiff',
    16 
       
    17 @command(
       
    18     b'autodiff',
    17     [(b'', b'git', b'', b'git upgrade mode (yes/no/auto/warn/abort)')],
    19     [(b'', b'git', b'', b'git upgrade mode (yes/no/auto/warn/abort)')],
    18     b'[OPTION]... [FILE]...')
    20     b'[OPTION]... [FILE]...',
       
    21 )
    19 def autodiff(ui, repo, *pats, **opts):
    22 def autodiff(ui, repo, *pats, **opts):
    20     opts = pycompat.byteskwargs(opts)
    23     opts = pycompat.byteskwargs(opts)
    21     diffopts = patch.difffeatureopts(ui, opts)
    24     diffopts = patch.difffeatureopts(ui, opts)
    22     git = opts.get(b'git', b'no')
    25     git = opts.get(b'git', b'no')
    23     brokenfiles = set()
    26     brokenfiles = set()
    29         diffopts.git = False
    32         diffopts.git = False
    30         diffopts.upgrade = True
    33         diffopts.upgrade = True
    31     elif git == b'warn':
    34     elif git == b'warn':
    32         diffopts.git = False
    35         diffopts.git = False
    33         diffopts.upgrade = True
    36         diffopts.upgrade = True
       
    37 
    34         def losedatafn(fn=None, **kwargs):
    38         def losedatafn(fn=None, **kwargs):
    35             brokenfiles.add(fn)
    39             brokenfiles.add(fn)
    36             return True
    40             return True
       
    41 
    37     elif git == b'abort':
    42     elif git == b'abort':
    38         diffopts.git = False
    43         diffopts.git = False
    39         diffopts.upgrade = True
    44         diffopts.upgrade = True
       
    45 
    40         def losedatafn(fn=None, **kwargs):
    46         def losedatafn(fn=None, **kwargs):
    41             raise error.Abort(b'losing data for %s' % fn)
    47             raise error.Abort(b'losing data for %s' % fn)
       
    48 
    42     else:
    49     else:
    43         raise error.Abort(b'--git must be yes, no or auto')
    50         raise error.Abort(b'--git must be yes, no or auto')
    44 
    51 
    45     ctx1, ctx2 = scmutil.revpair(repo, [])
    52     ctx1, ctx2 = scmutil.revpair(repo, [])
    46     m = scmutil.match(ctx2, pats, opts)
    53     m = scmutil.match(ctx2, pats, opts)
    47     it = patch.diff(repo, ctx1.node(), ctx2.node(), match=m, opts=diffopts,
    54     it = patch.diff(
    48                     losedatafn=losedatafn)
    55         repo,
       
    56         ctx1.node(),
       
    57         ctx2.node(),
       
    58         match=m,
       
    59         opts=diffopts,
       
    60         losedatafn=losedatafn,
       
    61     )
    49     for chunk in it:
    62     for chunk in it:
    50         ui.write(chunk)
    63         ui.write(chunk)
    51     for fn in sorted(brokenfiles):
    64     for fn in sorted(brokenfiles):
    52         ui.write((b'data lost for: %s\n' % fn))
    65         ui.write((b'data lost for: %s\n' % fn))