Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 23434:60300a4c0ae5
patch.difffeatureopts: add a feature for format-changing diffopts
Typically, callers that are interested in this set are also interested in the
others. We still add it as a first-class flag for convenience.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 18 Nov 2014 17:22:03 -0800 |
parents | 41dd76b3facb |
children | dbd60f8d88d5 |
comparison
equal
deleted
inserted
replaced
23433:41dd76b3facb | 23434:60300a4c0ae5 |
---|---|
1559 pass | 1559 pass |
1560 | 1560 |
1561 def diffallopts(ui, opts=None, untrusted=False, section='diff'): | 1561 def diffallopts(ui, opts=None, untrusted=False, section='diff'): |
1562 '''return diffopts with all features supported and parsed''' | 1562 '''return diffopts with all features supported and parsed''' |
1563 return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section, | 1563 return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section, |
1564 git=True, whitespace=True) | 1564 git=True, whitespace=True, formatchanging=True) |
1565 | 1565 |
1566 diffopts = diffallopts | 1566 diffopts = diffallopts |
1567 | 1567 |
1568 def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False, | 1568 def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False, |
1569 whitespace=False): | 1569 whitespace=False, formatchanging=False): |
1570 '''return diffopts with only opted-in features parsed | 1570 '''return diffopts with only opted-in features parsed |
1571 | 1571 |
1572 Features: | 1572 Features: |
1573 - git: git-style diffs | 1573 - git: git-style diffs |
1574 - whitespace: whitespace options like ignoreblanklines and ignorews | 1574 - whitespace: whitespace options like ignoreblanklines and ignorews |
1575 - formatchanging: options that will likely break or cause correctness issues | |
1576 with most diff parsers | |
1575 ''' | 1577 ''' |
1576 def get(key, name=None, getter=ui.configbool, forceplain=None): | 1578 def get(key, name=None, getter=ui.configbool, forceplain=None): |
1577 if opts: | 1579 if opts: |
1578 v = opts.get(key) | 1580 v = opts.get(key) |
1579 if v: | 1581 if v: |
1580 return v | 1582 return v |
1581 if forceplain is not None and ui.plain(): | 1583 if forceplain is not None and ui.plain(): |
1582 return forceplain | 1584 return forceplain |
1583 return getter(section, name or key, None, untrusted=untrusted) | 1585 return getter(section, name or key, None, untrusted=untrusted) |
1584 | 1586 |
1587 # core options, expected to be understood by every diff parser | |
1585 buildopts = { | 1588 buildopts = { |
1586 'text': opts and opts.get('text'), | |
1587 'nodates': get('nodates'), | 1589 'nodates': get('nodates'), |
1588 'nobinary': get('nobinary'), | |
1589 'noprefix': get('noprefix', forceplain=False), | |
1590 'showfunc': get('show_function', 'showfunc'), | 1590 'showfunc': get('show_function', 'showfunc'), |
1591 'context': get('unified', getter=ui.config), | 1591 'context': get('unified', getter=ui.config), |
1592 } | 1592 } |
1593 | 1593 |
1594 if git: | 1594 if git: |
1597 buildopts['ignorews'] = get('ignore_all_space', 'ignorews') | 1597 buildopts['ignorews'] = get('ignore_all_space', 'ignorews') |
1598 buildopts['ignorewsamount'] = get('ignore_space_change', | 1598 buildopts['ignorewsamount'] = get('ignore_space_change', |
1599 'ignorewsamount') | 1599 'ignorewsamount') |
1600 buildopts['ignoreblanklines'] = get('ignore_blank_lines', | 1600 buildopts['ignoreblanklines'] = get('ignore_blank_lines', |
1601 'ignoreblanklines') | 1601 'ignoreblanklines') |
1602 if formatchanging: | |
1603 buildopts['text'] = opts and opts.get('text') | |
1604 buildopts['nobinary'] = get('nobinary') | |
1605 buildopts['noprefix'] = get('noprefix', forceplain=False) | |
1602 | 1606 |
1603 return mdiff.diffopts(**buildopts) | 1607 return mdiff.diffopts(**buildopts) |
1604 | 1608 |
1605 def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, | 1609 def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, |
1606 losedatafn=None, prefix=''): | 1610 losedatafn=None, prefix=''): |