Mercurial > hg
annotate mercurial/diffutil.py @ 52068:c392d57e8a06
manifest: drop the CamelCase name for `manifest.treemanifest`
See 61557734c0ae for the reasoning.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 23 Oct 2024 16:32:34 -0400 |
parents | f4733654f144 |
children |
rev | line source |
---|---|
38562
c88d2c9b00dd
diffutil: extract diff options code into a dedicated util-module
Boris Feld <boris.feld@octobus.net>
parents:
38493
diff
changeset
|
1 # diffutil.py - utility functions related to diff and patch |
2861
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
2 # |
2865
71e78f2ca5ae
merge git patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2863
diff
changeset
|
3 # Copyright 2006 Brendan Cully <brendan@kublai.com> |
4897
4574925db5c0
Add Chris Mason's mpatch library.
Bryan O'Sullivan <bos@serpentine.com>
parents:
4778
diff
changeset
|
4 # Copyright 2007 Chris Mason <chris.mason@oracle.com> |
38562
c88d2c9b00dd
diffutil: extract diff options code into a dedicated util-module
Boris Feld <boris.feld@octobus.net>
parents:
38493
diff
changeset
|
5 # Copyright 2018 Octobus <octobus@octobus.net> |
2865
71e78f2ca5ae
merge git patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2863
diff
changeset
|
6 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
7 # This software may be used and distributed according to the terms of the |
10263 | 8 # GNU General Public License version 2 or any later version. |
2861
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
9 |
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51143
diff
changeset
|
10 from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51143
diff
changeset
|
11 |
50247
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
12 import typing |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
13 |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
14 from typing import ( |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
15 Any, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
16 Dict, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
17 Optional, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
18 ) |
14370
17cea10c343e
patch: add a workingbackend dirstate layer on top of fsbackend
Patrick Mezard <pmezard@gmail.com>
parents:
14369
diff
changeset
|
19 |
38588
1c93e0237a24
diffutil: move the module out of utils package
Yuya Nishihara <yuya@tcha.org>
parents:
38587
diff
changeset
|
20 from .i18n import _ |
51143
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
21 from .node import nullrev |
24269
9a745ced79a9
record: move filterpatch from record to patch
Laurent Charignon <lcharignon@fb.com>
parents:
24268
diff
changeset
|
22 |
38588
1c93e0237a24
diffutil: move the module out of utils package
Yuya Nishihara <yuya@tcha.org>
parents:
38587
diff
changeset
|
23 from . import ( |
38562
c88d2c9b00dd
diffutil: extract diff options code into a dedicated util-module
Boris Feld <boris.feld@octobus.net>
parents:
38493
diff
changeset
|
24 mdiff, |
c88d2c9b00dd
diffutil: extract diff options code into a dedicated util-module
Boris Feld <boris.feld@octobus.net>
parents:
38493
diff
changeset
|
25 pycompat, |
c88d2c9b00dd
diffutil: extract diff options code into a dedicated util-module
Boris Feld <boris.feld@octobus.net>
parents:
38493
diff
changeset
|
26 ) |
7198
df79ee9b6278
patch: extract local function addmodehdr
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7186
diff
changeset
|
27 |
50247
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
28 if typing.TYPE_CHECKING: |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
29 from . import ui as uimod |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
30 |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
31 # TODO: narrow the value after the config module is typed |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
32 _Opts = Dict[bytes, Any] |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
33 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
34 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
35 def diffallopts( |
50247
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
36 ui: "uimod.ui", |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
37 opts: Optional[_Opts] = None, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
38 untrusted: bool = False, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
39 section: bytes = b'diff', |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
40 configprefix: bytes = b'', |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
41 ) -> mdiff.diffopts: |
23430
3821be85fd4d
patch: add a new function to initialize diffopts by feature
Siddharth Agarwal <sid0@fb.com>
parents:
23429
diff
changeset
|
42 '''return diffopts with all features supported and parsed''' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
43 return difffeatureopts( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
44 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
45 opts=opts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
46 untrusted=untrusted, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
47 section=section, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
48 git=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
49 whitespace=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
50 formatchanging=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
51 configprefix=configprefix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
52 ) |
23430
3821be85fd4d
patch: add a new function to initialize diffopts by feature
Siddharth Agarwal <sid0@fb.com>
parents:
23429
diff
changeset
|
53 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
54 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
55 def difffeatureopts( |
50247
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
56 ui: "uimod.ui", |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
57 opts: Optional[_Opts] = None, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
58 untrusted: bool = False, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
59 section: bytes = b'diff', |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
60 git: bool = False, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
61 whitespace: bool = False, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
62 formatchanging: bool = False, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
63 configprefix: bytes = b'', |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
64 ) -> mdiff.diffopts: |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43077
diff
changeset
|
65 """return diffopts with only opted-in features parsed |
23432
27af986a332b
patch.difffeatureopts: add a feature for diff.git
Siddharth Agarwal <sid0@fb.com>
parents:
23431
diff
changeset
|
66 |
27af986a332b
patch.difffeatureopts: add a feature for diff.git
Siddharth Agarwal <sid0@fb.com>
parents:
23431
diff
changeset
|
67 Features: |
27af986a332b
patch.difffeatureopts: add a feature for diff.git
Siddharth Agarwal <sid0@fb.com>
parents:
23431
diff
changeset
|
68 - git: git-style diffs |
23433
41dd76b3facb
patch.difffeatureopts: add a feature for whitespace diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
23432
diff
changeset
|
69 - whitespace: whitespace options like ignoreblanklines and ignorews |
23434
60300a4c0ae5
patch.difffeatureopts: add a feature for format-changing diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
23433
diff
changeset
|
70 - formatchanging: options that will likely break or cause correctness issues |
60300a4c0ae5
patch.difffeatureopts: add a feature for format-changing diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
23433
diff
changeset
|
71 with most diff parsers |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43077
diff
changeset
|
72 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
73 |
50247
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
74 def get( |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
75 key: bytes, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
76 name: Optional[bytes] = None, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
77 getter=ui.configbool, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
78 forceplain: Optional[bool] = None, |
b8cac4e37100
typing: add typehints to mercurial/diffutil.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
79 ) -> Any: |
23295
ac072c79bd9d
patch.diffopts: break get function into if statements
Siddharth Agarwal <sid0@fb.com>
parents:
22460
diff
changeset
|
80 if opts: |
ac072c79bd9d
patch.diffopts: break get function into if statements
Siddharth Agarwal <sid0@fb.com>
parents:
22460
diff
changeset
|
81 v = opts.get(key) |
29948
e40343ce9c4c
diffopts: notice a negated boolean flag in diffopts
Augie Fackler <augie@google.com>
parents:
29900
diff
changeset
|
82 # diffopts flags are either None-default (which is passed |
e40343ce9c4c
diffopts: notice a negated boolean flag in diffopts
Augie Fackler <augie@google.com>
parents:
29900
diff
changeset
|
83 # through unchanged, so we can identify unset values), or |
e40343ce9c4c
diffopts: notice a negated boolean flag in diffopts
Augie Fackler <augie@google.com>
parents:
29900
diff
changeset
|
84 # some other falsey default (eg --unified, which defaults |
e40343ce9c4c
diffopts: notice a negated boolean flag in diffopts
Augie Fackler <augie@google.com>
parents:
29900
diff
changeset
|
85 # to an empty string). We only want to override the config |
e40343ce9c4c
diffopts: notice a negated boolean flag in diffopts
Augie Fackler <augie@google.com>
parents:
29900
diff
changeset
|
86 # entries from hgrc with command line values if they |
e40343ce9c4c
diffopts: notice a negated boolean flag in diffopts
Augie Fackler <augie@google.com>
parents:
29900
diff
changeset
|
87 # appear to have been set, which is any truthy value, |
e40343ce9c4c
diffopts: notice a negated boolean flag in diffopts
Augie Fackler <augie@google.com>
parents:
29900
diff
changeset
|
88 # True, or False. |
e40343ce9c4c
diffopts: notice a negated boolean flag in diffopts
Augie Fackler <augie@google.com>
parents:
29900
diff
changeset
|
89 if v or isinstance(v, bool): |
23295
ac072c79bd9d
patch.diffopts: break get function into if statements
Siddharth Agarwal <sid0@fb.com>
parents:
22460
diff
changeset
|
90 return v |
23296
922fcfb02e77
patch.diffopts: allow a setting to be forced in plain mode
Siddharth Agarwal <sid0@fb.com>
parents:
23295
diff
changeset
|
91 if forceplain is not None and ui.plain(): |
922fcfb02e77
patch.diffopts: allow a setting to be forced in plain mode
Siddharth Agarwal <sid0@fb.com>
parents:
23295
diff
changeset
|
92 return forceplain |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
93 return getter( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
94 section, configprefix + (name or key), untrusted=untrusted |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
95 ) |
23295
ac072c79bd9d
patch.diffopts: break get function into if statements
Siddharth Agarwal <sid0@fb.com>
parents:
22460
diff
changeset
|
96 |
23434
60300a4c0ae5
patch.difffeatureopts: add a feature for format-changing diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
23433
diff
changeset
|
97 # core options, expected to be understood by every diff parser |
23429
f35526b999f4
patch.diffopts: use a dict for initialization
Siddharth Agarwal <sid0@fb.com>
parents:
23300
diff
changeset
|
98 buildopts = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
99 b'nodates': get(b'nodates'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
100 b'showfunc': get(b'show_function', b'showfunc'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
101 b'context': get(b'unified', getter=ui.config), |
23429
f35526b999f4
patch.diffopts: use a dict for initialization
Siddharth Agarwal <sid0@fb.com>
parents:
23300
diff
changeset
|
102 } |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
103 buildopts[b'xdiff'] = ui.configbool(b'experimental', b'xdiff') |
23429
f35526b999f4
patch.diffopts: use a dict for initialization
Siddharth Agarwal <sid0@fb.com>
parents:
23300
diff
changeset
|
104 |
23432
27af986a332b
patch.difffeatureopts: add a feature for diff.git
Siddharth Agarwal <sid0@fb.com>
parents:
23431
diff
changeset
|
105 if git: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
106 buildopts[b'git'] = get(b'git') |
30788
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
107 |
30806
e2796f193f06
patch: add similarity config knob in experimental section
Sean Farley <sean@farley.io>
parents:
30790
diff
changeset
|
108 # since this is in the experimental section, we need to call |
e2796f193f06
patch: add similarity config knob in experimental section
Sean Farley <sean@farley.io>
parents:
30790
diff
changeset
|
109 # ui.configbool directory |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
110 buildopts[b'showsimilarity'] = ui.configbool( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
111 b'experimental', b'extendedheader.similarity' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
112 ) |
30806
e2796f193f06
patch: add similarity config knob in experimental section
Sean Farley <sean@farley.io>
parents:
30790
diff
changeset
|
113 |
30788
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
114 # need to inspect the ui object instead of using get() since we want to |
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
115 # test for an int |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
116 hconf = ui.config(b'experimental', b'extendedheader.index') |
30788
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
117 if hconf is not None: |
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
118 hlen = None |
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
119 try: |
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
120 # the hash config could be an integer (for length of hash) or a |
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
121 # word (e.g. short, full, none) |
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
122 hlen = int(hconf) |
30819
897726622877
patch: check length of git index header only if integer is specified
Yuya Nishihara <yuya@tcha.org>
parents:
30808
diff
changeset
|
123 if hlen < 0 or hlen > 40: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
124 msg = _(b"invalid length for extendedheader.index: '%d'\n") |
30819
897726622877
patch: check length of git index header only if integer is specified
Yuya Nishihara <yuya@tcha.org>
parents:
30808
diff
changeset
|
125 ui.warn(msg % hlen) |
30788
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
126 except ValueError: |
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
127 # default value |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
128 if hconf == b'short' or hconf == b'': |
30788
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
129 hlen = 12 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
130 elif hconf == b'full': |
30788
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
131 hlen = 40 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
132 elif hconf != b'none': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 msg = _(b"invalid value for extendedheader.index: '%s'\n") |
30788
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
134 ui.warn(msg % hconf) |
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
135 finally: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
136 buildopts[b'index'] = hlen |
30788
d1901c4c8ec0
patch: add config knob for displaying the index header
Sean Farley <sean@farley.io>
parents:
30407
diff
changeset
|
137 |
23433
41dd76b3facb
patch.difffeatureopts: add a feature for whitespace diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
23432
diff
changeset
|
138 if whitespace: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 buildopts[b'ignorews'] = get(b'ignore_all_space', b'ignorews') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
140 buildopts[b'ignorewsamount'] = get( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
141 b'ignore_space_change', b'ignorewsamount' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
142 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
143 buildopts[b'ignoreblanklines'] = get( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
144 b'ignore_blank_lines', b'ignoreblanklines' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
145 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
146 buildopts[b'ignorewseol'] = get(b'ignore_space_at_eol', b'ignorewseol') |
23434
60300a4c0ae5
patch.difffeatureopts: add a feature for format-changing diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
23433
diff
changeset
|
147 if formatchanging: |
49898
024e0580b853
diffutil: rewrite an ersatz ternary operator for building diffopts.text
Matt Harbison <matt_harbison@yahoo.com>
parents:
48875
diff
changeset
|
148 buildopts[b'text'] = None if opts is None else opts.get(b'text') |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
149 binary = None if opts is None else opts.get(b'binary') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
150 buildopts[b'nobinary'] = ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
151 not binary |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
152 if binary is not None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
153 else get(b'nobinary', forceplain=False) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41559
diff
changeset
|
154 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
155 buildopts[b'noprefix'] = get(b'noprefix', forceplain=False) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
156 buildopts[b'worddiff'] = get( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
157 b'word_diff', b'word-diff', forceplain=False |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
158 ) |
23432
27af986a332b
patch.difffeatureopts: add a feature for diff.git
Siddharth Agarwal <sid0@fb.com>
parents:
23431
diff
changeset
|
159 |
31631
a7acda2de4b8
diff: use pycompat.{byteskwargs, strkwargs} to switch opts b/w bytes and str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31630
diff
changeset
|
160 return mdiff.diffopts(**pycompat.strkwargs(buildopts)) |
51143
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
161 |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
162 |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
163 def diff_parent(ctx): |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
164 """get the context object to use as parent when diffing |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
165 |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
166 |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
167 If diff.merge is enabled, an overlayworkingctx of the auto-merged parents will be returned. |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
168 """ |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
169 repo = ctx.repo() |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
170 if repo.ui.configbool(b"diff", b"merge") and ctx.p2().rev() != nullrev: |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
171 # avoid circular import |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
172 from . import ( |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
173 context, |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
174 merge, |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
175 ) |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
176 |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
177 wctx = context.overlayworkingctx(repo) |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
178 wctx.setbase(ctx.p1()) |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
179 with repo.ui.configoverride( |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
180 { |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
181 ( |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
182 b"ui", |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
183 b"forcemerge", |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
184 ): b"internal:merge3-lie-about-conflicts", |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
185 }, |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
186 b"merge-diff", |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
187 ): |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
188 with repo.ui.silent(): |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
189 merge.merge(ctx.p2(), wc=wctx) |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
190 return wctx |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
191 else: |
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
50252
diff
changeset
|
192 return ctx.p1() |