author | Gregory Szorc <gregory.szorc@gmail.com> |
Mon, 04 Feb 2019 09:00:52 -0800 | |
changeset 41535 | 7a90ff8cd14c |
parent 41487 | fa471151d269 |
child 41584 | a4cd77a425a3 |
permissions | -rw-r--r-- |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1 |
# extdiff.py - external diff program support for mercurial |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
2 |
# |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
4 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8076
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
10263 | 6 |
# GNU General Public License version 2 or any later version. |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
7 |
|
8934
9dda4c73fc3b
extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8873
diff
changeset
|
8 |
'''command to allow external programs to compare revisions |
8873
e872ef2e6758
help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8866
diff
changeset
|
9 |
|
9286
a8fdcec4ab34
doc: fix quotes mismatches affecting rst
Cédric Duval <cedricduval@free.fr>
parents:
9257
diff
changeset
|
10 |
The extdiff Mercurial extension allows you to use external programs |
9257
50ebe8845a1b
extdiff: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9207
diff
changeset
|
11 |
to compare revisions, or revision with working directory. The external |
50ebe8845a1b
extdiff: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9207
diff
changeset
|
12 |
diff programs are called with a configurable set of options and two |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
13 |
non-option arguments: paths to directories containing snapshots of |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
14 |
files to compare. |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
15 |
|
37209
2208149c4b8e
extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents:
37120
diff
changeset
|
16 |
If there is more than one file being compared and the "child" revision |
2208149c4b8e
extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents:
37120
diff
changeset
|
17 |
is the working directory, any modifications made in the external diff |
2208149c4b8e
extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents:
37120
diff
changeset
|
18 |
program will be copied back to the working directory from the temporary |
2208149c4b8e
extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents:
37120
diff
changeset
|
19 |
directory. |
2208149c4b8e
extdiff: document that it copies modified files back to working directory
Kyle Lippincott <spectral@google.com>
parents:
37120
diff
changeset
|
20 |
|
14327
d943412e2fba
extdiff: grammar "allows to" -> "allows one to"
Javi Merino <cibervicho@gmail.com>
parents:
14322
diff
changeset
|
21 |
The extdiff extension also allows you to configure new diff commands, so |
11191
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
22 |
you do not need to type :hg:`extdiff -p kdiff3` always. :: |
3127
8e8deb8035a4
Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents:
3090
diff
changeset
|
23 |
|
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
24 |
[extdiff] |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
25 |
# add new command that runs GNU diff(1) in 'context diff' mode |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
26 |
cdiff = gdiff -Nprc5 |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
27 |
## or the old way: |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
28 |
#cmd.cdiff = gdiff |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
29 |
#opts.cdiff = -Nprc5 |
3127
8e8deb8035a4
Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents:
3090
diff
changeset
|
30 |
|
23150
aff73c777b0b
extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents:
23149
diff
changeset
|
31 |
# add new command called meld, runs meld (no need to name twice). If |
aff73c777b0b
extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents:
23149
diff
changeset
|
32 |
# the meld executable is not available, the meld tool in [merge-tools] |
aff73c777b0b
extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents:
23149
diff
changeset
|
33 |
# will be used, if available |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
34 |
meld = |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
35 |
|
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
36 |
# add new command called vimdiff, runs gvimdiff with DirDiff plugin |
9257
50ebe8845a1b
extdiff: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9207
diff
changeset
|
37 |
# (see http://www.vim.org/scripts/script.php?script_id=102) Non |
50ebe8845a1b
extdiff: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9207
diff
changeset
|
38 |
# English user, be sure to put "let g:DirDiffDynamicDiffText = 1" in |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
39 |
# your .vimrc |
16242
55174ab81973
extdiff: escape filenames with vim/DirDiff and make quoting work with Windows
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14739
diff
changeset
|
40 |
vimdiff = gvim -f "+next" \\ |
55174ab81973
extdiff: escape filenames with vim/DirDiff and make quoting work with Windows
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14739
diff
changeset
|
41 |
"+execute 'DirDiff' fnameescape(argv(0)) fnameescape(argv(1))" |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
42 |
|
11191
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
43 |
Tool arguments can include variables that are expanded at runtime:: |
11184
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
44 |
|
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
45 |
$parent1, $plabel1 - filename, descriptive label of first parent |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
46 |
$child, $clabel - filename, descriptive label of child revision |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
47 |
$parent2, $plabel2 - filename, descriptive label of second parent |
14045
1c38777f7b8a
extdiff: add repository root as a variable
Steven Stallion <sstallion@gmail.com>
parents:
14024
diff
changeset
|
48 |
$root - repository root |
11184
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
49 |
$parent is an alias for $parent1. |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
50 |
|
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
51 |
The extdiff extension will look in your [diff-tools] and [merge-tools] |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
52 |
sections for diff tool arguments, when none are specified in [extdiff]. |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
53 |
|
11191
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
54 |
:: |
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
55 |
|
11184
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
56 |
[extdiff] |
11191
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
57 |
kdiff3 = |
11184
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
58 |
|
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
59 |
[diff-tools] |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
60 |
kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
61 |
|
11191
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
62 |
You can use -I/-X and list of file or directory names like normal |
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
63 |
:hg:`diff` command. The extdiff extension makes snapshots of only |
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
64 |
needed files, so running the external diff program will actually be |
c45a47bc4114
extdiff: fix reST syntax in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
11184
diff
changeset
|
65 |
pretty fast (at least faster than having to compare the entire tree). |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
66 |
''' |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
67 |
|
28970
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
68 |
from __future__ import absolute_import |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
69 |
|
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
70 |
import os |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
71 |
import re |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
72 |
import shutil |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36268
diff
changeset
|
73 |
import stat |
38165
2ce60954b1b7
py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents:
37604
diff
changeset
|
74 |
|
3891 | 75 |
from mercurial.i18n import _ |
28970
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
76 |
from mercurial.node import ( |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
77 |
nullid, |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
78 |
short, |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
79 |
) |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
80 |
from mercurial import ( |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
81 |
archival, |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
82 |
cmdutil, |
41487
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
83 |
encoding, |
28970
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
84 |
error, |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
85 |
filemerge, |
37604
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37253
diff
changeset
|
86 |
formatter, |
30678
caf7e1c5efe4
py3: have a bytes version of shlex.split()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29841
diff
changeset
|
87 |
pycompat, |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32283
diff
changeset
|
88 |
registrar, |
28970
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
89 |
scmutil, |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
90 |
util, |
4f86c3bed63b
py3: make extdiff use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27681
diff
changeset
|
91 |
) |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
92 |
from mercurial.utils import ( |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
93 |
procutil, |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
94 |
stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
95 |
) |
5135
1830bc7676ee
extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents:
4730
diff
changeset
|
96 |
|
21246
29eeaa6d662f
extdiff: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20674
diff
changeset
|
97 |
cmdtable = {} |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32283
diff
changeset
|
98 |
command = registrar.command(cmdtable) |
34777
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
99 |
|
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
100 |
configtable = {} |
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
101 |
configitem = registrar.configitem(configtable) |
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
102 |
|
36267
08f061a48a8f
py3: make regexp patterns bytes in extdiff
Yuya Nishihara <yuya@tcha.org>
parents:
36266
diff
changeset
|
103 |
configitem('extdiff', br'opts\..*', |
34777
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
104 |
default='', |
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
105 |
generic=True, |
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
106 |
) |
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
107 |
|
36267
08f061a48a8f
py3: make regexp patterns bytes in extdiff
Yuya Nishihara <yuya@tcha.org>
parents:
36266
diff
changeset
|
108 |
configitem('diff-tools', br'.*\.diffargs$', |
34778
bf138446ac2f
configitems: register the 'extdata.*.diffargs' config
Boris Feld <boris.feld@octobus.net>
parents:
34777
diff
changeset
|
109 |
default=None, |
bf138446ac2f
configitems: register the 'extdata.*.diffargs' config
Boris Feld <boris.feld@octobus.net>
parents:
34777
diff
changeset
|
110 |
generic=True, |
bf138446ac2f
configitems: register the 'extdata.*.diffargs' config
Boris Feld <boris.feld@octobus.net>
parents:
34777
diff
changeset
|
111 |
) |
bf138446ac2f
configitems: register the 'extdata.*.diffargs' config
Boris Feld <boris.feld@octobus.net>
parents:
34777
diff
changeset
|
112 |
|
29841
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29723
diff
changeset
|
113 |
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
25186
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24193
diff
changeset
|
114 |
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24193
diff
changeset
|
115 |
# be specifying the version(s) of Mercurial they are tested with, or |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24193
diff
changeset
|
116 |
# leave the attribute unspecified. |
29841
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29723
diff
changeset
|
117 |
testedwith = 'ships-with-hg-core' |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
16686
diff
changeset
|
118 |
|
25813
18bae5eb58c5
extdiff: add support for subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25812
diff
changeset
|
119 |
def snapshot(ui, repo, files, node, tmproot, listsubrepos): |
8064
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
120 |
'''snapshot files as of some revision |
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
121 |
if not using snapshot, -I/-X does not work and recursive diff |
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
122 |
in tools like kdiff3 and meld displays too many files.''' |
5135
1830bc7676ee
extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents:
4730
diff
changeset
|
123 |
dirname = os.path.basename(repo.root) |
1830bc7676ee
extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents:
4730
diff
changeset
|
124 |
if dirname == "": |
1830bc7676ee
extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents:
4730
diff
changeset
|
125 |
dirname = "root" |
8064
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
126 |
if node is not None: |
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
127 |
dirname = '%s.%s' % (dirname, short(node)) |
5135
1830bc7676ee
extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents:
4730
diff
changeset
|
128 |
base = os.path.join(tmproot, dirname) |
1830bc7676ee
extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents:
4730
diff
changeset
|
129 |
os.mkdir(base) |
32217
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
130 |
fnsandstat = [] |
25812
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
131 |
|
8064
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
132 |
if node is not None: |
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
133 |
ui.note(_('making snapshot of %d files from rev %s\n') % |
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
134 |
(len(files), short(node))) |
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
135 |
else: |
8066 | 136 |
ui.note(_('making snapshot of %d files from working directory\n') % |
8064
5c7bc1aece9e
extdiff: merge node and working dir snapshot modes
Patrick Mezard <pmezard@gmail.com>
parents:
7758
diff
changeset
|
137 |
(len(files))) |
25812
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
138 |
|
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
139 |
if files: |
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
140 |
repo.ui.setconfig("ui", "archivemeta", False) |
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
141 |
|
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
142 |
archival.archive(repo, base, node, 'files', |
40407
3d76a8e627a6
archive: change "matcnfn" argument to a real matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
40293
diff
changeset
|
143 |
match=scmutil.matchfiles(repo, files), |
25813
18bae5eb58c5
extdiff: add support for subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25812
diff
changeset
|
144 |
subrepos=listsubrepos) |
25812
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
145 |
|
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
146 |
for fn in sorted(files): |
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
147 |
wfn = util.pconvert(fn) |
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
148 |
ui.note(' %s\n' % wfn) |
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
149 |
|
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
150 |
if node is None: |
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
151 |
dest = os.path.join(base, wfn) |
68822b7cdd01
extdiff: use archiver to take snapshots of committed revisions
Matt Harbison <matt_harbison@yahoo.com>
parents:
25186
diff
changeset
|
152 |
|
32217
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
153 |
fnsandstat.append((dest, repo.wjoin(fn), os.lstat(dest))) |
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
154 |
return dirname, fnsandstat |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5137
diff
changeset
|
155 |
|
41196
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
156 |
def formatcmdline(cmdline, repo_root, do3way, |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
157 |
parent1, plabel1, parent2, plabel2, child, clabel): |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
158 |
# Function to quote file/dir names in the argument string. |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
159 |
# When not operating in 3-way mode, an empty string is |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
160 |
# returned for parent2 |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
161 |
replace = {'parent': parent1, 'parent1': parent1, 'parent2': parent2, |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
162 |
'plabel1': plabel1, 'plabel2': plabel2, |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
163 |
'child': child, 'clabel': clabel, |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
164 |
'root': repo_root} |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
165 |
def quote(match): |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
166 |
pre = match.group(2) |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
167 |
key = match.group(3) |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
168 |
if not do3way and key == 'parent2': |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
169 |
return pre |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
170 |
return pre + procutil.shellquote(replace[key]) |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
171 |
|
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
172 |
# Match parent2 first, so 'parent1?' will match both parent1 and parent |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
173 |
regex = (br'''(['"]?)([^\s'"$]*)''' |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
174 |
br'\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)\1') |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
175 |
if not do3way and not re.search(regex, cmdline): |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
176 |
cmdline += ' $parent1 $child' |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
177 |
return re.sub(regex, quote, cmdline) |
4f675c12d083
extdiff: move external tool command line building into separate function
Ludovic Chabant <ludovic@chabant.com>
parents:
40819
diff
changeset
|
178 |
|
41487
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
179 |
def _runperfilediff(cmdline, repo_root, ui, do3way, confirm, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
180 |
commonfiles, tmproot, dir1a, dir1b, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
181 |
dir2root, dir2, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
182 |
rev1a, rev1b, rev2): |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
183 |
# Note that we need to sort the list of files because it was |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
184 |
# built in an "unstable" way and it's annoying to get files in a |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
185 |
# random order, especially when "confirm" mode is enabled. |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
186 |
totalfiles = len(commonfiles) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
187 |
for idx, commonfile in enumerate(sorted(commonfiles)): |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
188 |
path1a = os.path.join(tmproot, dir1a, commonfile) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
189 |
label1a = commonfile + rev1a |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
190 |
if not os.path.isfile(path1a): |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
191 |
path1a = os.devnull |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
192 |
|
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
193 |
path1b = '' |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
194 |
label1b = '' |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
195 |
if do3way: |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
196 |
path1b = os.path.join(tmproot, dir1b, commonfile) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
197 |
label1b = commonfile + rev1b |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
198 |
if not os.path.isfile(path1b): |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
199 |
path1b = os.devnull |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
200 |
|
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
201 |
path2 = os.path.join(dir2root, dir2, commonfile) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
202 |
label2 = commonfile + rev2 |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
203 |
|
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
204 |
if confirm: |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
205 |
# Prompt before showing this diff |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
206 |
difffiles = _('diff %s (%d of %d)') % (commonfile, idx + 1, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
207 |
totalfiles) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
208 |
responses = _('[Yns?]' |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
209 |
'$$ &Yes, show diff' |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
210 |
'$$ &No, skip this diff' |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
211 |
'$$ &Skip remaining diffs' |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
212 |
'$$ &? (display help)') |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
213 |
r = ui.promptchoice('%s %s' % (difffiles, responses)) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
214 |
if r == 3: # ? |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
215 |
while r == 3: |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
216 |
for c, t in ui.extractchoices(responses)[1]: |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
217 |
ui.write('%s - %s\n' % (c, encoding.lower(t))) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
218 |
r = ui.promptchoice('%s %s' % (difffiles, responses)) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
219 |
if r == 0: # yes |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
220 |
pass |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
221 |
elif r == 1: # no |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
222 |
continue |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
223 |
elif r == 2: # skip |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
224 |
break |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
225 |
|
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
226 |
curcmdline = formatcmdline( |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
227 |
cmdline, repo_root, do3way=do3way, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
228 |
parent1=path1a, plabel1=label1a, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
229 |
parent2=path1b, plabel2=label1b, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
230 |
child=path2, clabel=label2) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
231 |
ui.debug('running %r in %s\n' % (pycompat.bytestr(curcmdline), |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
232 |
tmproot)) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
233 |
|
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
234 |
# Run the comparison program and wait for it to exit |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
235 |
# before we show the next file. |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
236 |
ui.system(curcmdline, cwd=tmproot, blockedtag='extdiff') |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
237 |
|
23681
9476cb62298e
extdiff: rename the name of an argument for readability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23680
diff
changeset
|
238 |
def dodiff(ui, repo, cmdline, pats, opts): |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
16743
diff
changeset
|
239 |
'''Do the actual diff: |
6103
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
240 |
|
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
241 |
- copy to a temp structure if diffing 2 internal revisions |
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
242 |
- copy to a temp structure if diffing working revision with |
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
243 |
another one and more than 1 file is changed |
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
244 |
- just invoke the diff for a single file in the working dir |
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
245 |
''' |
7758
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
246 |
|
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
247 |
revs = opts.get('rev') |
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
248 |
change = opts.get('change') |
23681
9476cb62298e
extdiff: rename the name of an argument for readability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23680
diff
changeset
|
249 |
do3way = '$parent2' in cmdline |
7758
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
250 |
|
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
251 |
if revs and change: |
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
252 |
msg = _('cannot specify --rev and --change at the same time') |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26229
diff
changeset
|
253 |
raise error.Abort(msg) |
7758
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
254 |
elif change: |
37253
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
255 |
ctx2 = scmutil.revsingle(repo, change, None) |
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
256 |
ctx1a, ctx1b = ctx2.p1(), ctx2.p2() |
7758
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
257 |
else: |
37253
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
258 |
ctx1a, ctx2 = scmutil.revpair(repo, revs) |
9512
e7bde4680eec
extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents:
9467
diff
changeset
|
259 |
if not revs: |
37253
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
260 |
ctx1b = repo[None].p2() |
9512
e7bde4680eec
extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents:
9467
diff
changeset
|
261 |
else: |
37253
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
262 |
ctx1b = repo[nullid] |
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
263 |
|
41487
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
264 |
perfile = opts.get('per_file') |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
265 |
confirm = opts.get('confirm') |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
266 |
|
37253
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
267 |
node1a = ctx1a.node() |
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
268 |
node1b = ctx1b.node() |
6089ef933ab5
extdiff: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
269 |
node2 = ctx2.node() |
9512
e7bde4680eec
extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents:
9467
diff
changeset
|
270 |
|
e7bde4680eec
extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents:
9467
diff
changeset
|
271 |
# Disable 3-way merge if there is only one parent |
e7bde4680eec
extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents:
9467
diff
changeset
|
272 |
if do3way: |
e7bde4680eec
extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents:
9467
diff
changeset
|
273 |
if node1b == nullid: |
e7bde4680eec
extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents:
9467
diff
changeset
|
274 |
do3way = False |
7758
e81e6c996e99
extdiff: add --change option to display single changeset diff
Gilles Moris <gilles.moris@free.fr>
parents:
7599
diff
changeset
|
275 |
|
25813
18bae5eb58c5
extdiff: add support for subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25812
diff
changeset
|
276 |
subrepos=opts.get('subrepos') |
18bae5eb58c5
extdiff: add support for subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25812
diff
changeset
|
277 |
|
14671
35c2cc322ba8
scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents:
14327
diff
changeset
|
278 |
matcher = scmutil.match(repo[node2], pats, opts) |
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
279 |
|
26228
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
280 |
if opts.get('patch'): |
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
281 |
if subrepos: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26229
diff
changeset
|
282 |
raise error.Abort(_('--patch cannot be used with --subrepos')) |
41487
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
283 |
if perfile: |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
284 |
raise error.Abort(_('--patch cannot be used with --per-file')) |
26228
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
285 |
if node2 is None: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26229
diff
changeset
|
286 |
raise error.Abort(_('--patch requires two revisions')) |
26228
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
287 |
else: |
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
288 |
mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher, |
25813
18bae5eb58c5
extdiff: add support for subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25812
diff
changeset
|
289 |
listsubrepos=subrepos)[:3]) |
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
290 |
if do3way: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
291 |
mod_b, add_b, rem_b = map(set, |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
292 |
repo.status(node1b, node2, matcher, |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
293 |
listsubrepos=subrepos)[:3]) |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
294 |
else: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
295 |
mod_b, add_b, rem_b = set(), set(), set() |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
296 |
modadd = mod_a | add_a | mod_b | add_b |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
297 |
common = modadd | rem_a | rem_b |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
298 |
if not common: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
299 |
return 0 |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
300 |
|
38165
2ce60954b1b7
py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents:
37604
diff
changeset
|
301 |
tmproot = pycompat.mkdtemp(prefix='extdiff.') |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
302 |
try: |
26228
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
303 |
if not opts.get('patch'): |
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
304 |
# Always make a copy of node1a (and node1b, if applicable) |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
305 |
dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a) |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
306 |
dir1a = snapshot(ui, repo, dir1a_files, node1a, tmproot, |
25813
18bae5eb58c5
extdiff: add support for subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25812
diff
changeset
|
307 |
subrepos)[0] |
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
308 |
rev1a = '@%d' % repo[node1a].rev() |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
309 |
if do3way: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
310 |
dir1b_files = mod_b | rem_b | ((mod_a | add_a) - add_b) |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
311 |
dir1b = snapshot(ui, repo, dir1b_files, node1b, tmproot, |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
312 |
subrepos)[0] |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
313 |
rev1b = '@%d' % repo[node1b].rev() |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
314 |
else: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
315 |
dir1b = None |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
316 |
rev1b = '' |
9512
e7bde4680eec
extdiff: add 3-way diff for merge changesets
Sune Foldager <cryo@cyanite.org>
parents:
9467
diff
changeset
|
317 |
|
32217
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
318 |
fnsandstat = [] |
5137
2be225ea5722
extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents:
5136
diff
changeset
|
319 |
|
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
320 |
# If node2 in not the wc or there is >1 change, copy it |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
321 |
dir2root = '' |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
322 |
rev2 = '' |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
323 |
if node2: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
324 |
dir2 = snapshot(ui, repo, modadd, node2, tmproot, subrepos)[0] |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
325 |
rev2 = '@%d' % repo[node2].rev() |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
326 |
elif len(common) > 1: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
327 |
#we only actually need to get the files to copy back to |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
328 |
#the working dir in this case (because the other cases |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
329 |
#are: diffing 2 revisions or single file -- in which case |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
330 |
#the file is already directly passed to the diff tool). |
32217
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
331 |
dir2, fnsandstat = snapshot(ui, repo, modadd, None, tmproot, |
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
332 |
subrepos) |
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
333 |
else: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
334 |
# This lets the diff tool open the changed file directly |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
335 |
dir2 = '' |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
336 |
dir2root = repo.root |
5137
2be225ea5722
extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents:
5136
diff
changeset
|
337 |
|
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
338 |
label1a = rev1a |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
339 |
label1b = rev1b |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
340 |
label2 = rev2 |
11184
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
341 |
|
26227
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
342 |
# If only one change, diff the files instead of the directories |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
343 |
# Handle bogus modifies correctly by checking if the files exist |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
344 |
if len(common) == 1: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
345 |
common_file = util.localpath(common.pop()) |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
346 |
dir1a = os.path.join(tmproot, dir1a, common_file) |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
347 |
label1a = common_file + rev1a |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
348 |
if not os.path.isfile(dir1a): |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
349 |
dir1a = os.devnull |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
350 |
if do3way: |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
351 |
dir1b = os.path.join(tmproot, dir1b, common_file) |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
352 |
label1b = common_file + rev1b |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
353 |
if not os.path.isfile(dir1b): |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
354 |
dir1b = os.devnull |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
355 |
dir2 = os.path.join(dir2root, dir2, common_file) |
611ba118ebfc
extdiff: prepare sections of dodiff() for conditionalizing
Matt Harbison <matt_harbison@yahoo.com>
parents:
25876
diff
changeset
|
356 |
label2 = common_file + rev2 |
26228
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
357 |
else: |
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
358 |
template = 'hg-%h.patch' |
37604
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37253
diff
changeset
|
359 |
with formatter.nullformatter(ui, 'extdiff', {}) as fm: |
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37253
diff
changeset
|
360 |
cmdutil.export(repo, [repo[node1a].rev(), repo[node2].rev()], |
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37253
diff
changeset
|
361 |
fm, |
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37253
diff
changeset
|
362 |
fntemplate=repo.vfs.reljoin(tmproot, template), |
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37253
diff
changeset
|
363 |
match=matcher) |
36204
33ed8b511185
cmdutil: pass ctx to makefilename() in place of repo/node pair (API)
Yuya Nishihara <yuya@tcha.org>
parents:
34976
diff
changeset
|
364 |
label1a = cmdutil.makefilename(repo[node1a], template) |
33ed8b511185
cmdutil: pass ctx to makefilename() in place of repo/node pair (API)
Yuya Nishihara <yuya@tcha.org>
parents:
34976
diff
changeset
|
365 |
label2 = cmdutil.makefilename(repo[node2], template) |
26228
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
366 |
dir1a = repo.vfs.reljoin(tmproot, label1a) |
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
367 |
dir2 = repo.vfs.reljoin(tmproot, label2) |
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
368 |
dir1b = None |
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
369 |
label1b = None |
32217
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
370 |
fnsandstat = [] |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5137
diff
changeset
|
371 |
|
41487
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
372 |
if not perfile: |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
373 |
# Run the external tool on the 2 temp directories or the patches |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
374 |
cmdline = formatcmdline( |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
375 |
cmdline, repo.root, do3way=do3way, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
376 |
parent1=dir1a, plabel1=label1a, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
377 |
parent2=dir1b, plabel2=label1b, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
378 |
child=dir2, clabel=label2) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
379 |
ui.debug('running %r in %s\n' % (pycompat.bytestr(cmdline), |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
380 |
tmproot)) |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
381 |
ui.system(cmdline, cwd=tmproot, blockedtag='extdiff') |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
382 |
else: |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
383 |
# Run the external tool once for each pair of files |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
384 |
_runperfilediff( |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
385 |
cmdline, repo.root, ui, do3way=do3way, confirm=confirm, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
386 |
commonfiles=common, tmproot=tmproot, dir1a=dir1a, dir1b=dir1b, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
387 |
dir2root=dir2root, dir2=dir2, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
388 |
rev1a=rev1a, rev1b=rev1b, rev2=rev2) |
6103
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
389 |
|
32217
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
390 |
for copy_fn, working_fn, st in fnsandstat: |
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
391 |
cpstat = os.lstat(copy_fn) |
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
392 |
# Some tools copy the file and attributes, so mtime may not detect |
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
393 |
# all changes. A size check will detect more cases, but not all. |
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
394 |
# The only certain way to detect every case is to diff all files, |
affd753ddaf1
extdiff: copy back files to the working directory if the size changed
Matt Harbison <matt_harbison@yahoo.com>
parents:
31451
diff
changeset
|
395 |
# which could be expensive. |
32283
8a1ff5ed620e
extdiff: copy back execbit-only changes to the working directory
Matt Harbison <matt_harbison@yahoo.com>
parents:
32217
diff
changeset
|
396 |
# copyfile() carries over the permission, so the mode check could |
8a1ff5ed620e
extdiff: copy back execbit-only changes to the working directory
Matt Harbison <matt_harbison@yahoo.com>
parents:
32217
diff
changeset
|
397 |
# be in an 'elif' branch, but for the case where the file has |
8a1ff5ed620e
extdiff: copy back execbit-only changes to the working directory
Matt Harbison <matt_harbison@yahoo.com>
parents:
32217
diff
changeset
|
398 |
# changed without affecting mtime or size. |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36268
diff
changeset
|
399 |
if (cpstat[stat.ST_MTIME] != st[stat.ST_MTIME] |
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36268
diff
changeset
|
400 |
or cpstat.st_size != st.st_size |
32283
8a1ff5ed620e
extdiff: copy back execbit-only changes to the working directory
Matt Harbison <matt_harbison@yahoo.com>
parents:
32217
diff
changeset
|
401 |
or (cpstat.st_mode & 0o100) != (st.st_mode & 0o100)): |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9286
diff
changeset
|
402 |
ui.debug('file changed while diffing. ' |
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9286
diff
changeset
|
403 |
'Overwriting: %s (src: %s)\n' % (working_fn, copy_fn)) |
6103
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
404 |
util.copyfile(copy_fn, working_fn) |
e668fd796b8b
Propagating changes back to working dirs when changing files in external
Fabio Zadrozny <fabiofz at gmail dot com>
parents:
5293
diff
changeset
|
405 |
|
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
406 |
return 1 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
407 |
finally: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
408 |
ui.note(_('cleaning up temp directory\n')) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
409 |
shutil.rmtree(tmproot) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
410 |
|
27680
c750245c6b85
extdiff: factor out list of common options
Yuya Nishihara <yuya@tcha.org>
parents:
26587
diff
changeset
|
411 |
extdiffopts = [ |
21246
29eeaa6d662f
extdiff: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20674
diff
changeset
|
412 |
('o', 'option', [], |
29eeaa6d662f
extdiff: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20674
diff
changeset
|
413 |
_('pass option to comparison program'), _('OPT')), |
29eeaa6d662f
extdiff: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20674
diff
changeset
|
414 |
('r', 'rev', [], _('revision'), _('REV')), |
29eeaa6d662f
extdiff: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20674
diff
changeset
|
415 |
('c', 'change', '', _('change made by revision'), _('REV')), |
41487
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
416 |
('', 'per-file', False, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
417 |
_('compare each file instead of revision snapshots')), |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
418 |
('', 'confirm', False, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
419 |
_('prompt user before each external program invocation')), |
26228
0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
Matt Harbison <matt_harbison@yahoo.com>
parents:
26227
diff
changeset
|
420 |
('', 'patch', None, _('compare patches for two revisions')) |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32337
diff
changeset
|
421 |
] + cmdutil.walkopts + cmdutil.subrepoopts |
27680
c750245c6b85
extdiff: factor out list of common options
Yuya Nishihara <yuya@tcha.org>
parents:
26587
diff
changeset
|
422 |
|
c750245c6b85
extdiff: factor out list of common options
Yuya Nishihara <yuya@tcha.org>
parents:
26587
diff
changeset
|
423 |
@command('extdiff', |
c750245c6b85
extdiff: factor out list of common options
Yuya Nishihara <yuya@tcha.org>
parents:
26587
diff
changeset
|
424 |
[('p', 'program', '', _('comparison program to run'), _('CMD')), |
c750245c6b85
extdiff: factor out list of common options
Yuya Nishihara <yuya@tcha.org>
parents:
26587
diff
changeset
|
425 |
] + extdiffopts, |
21781
f0c3b95af47f
extdiff: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21246
diff
changeset
|
426 |
_('hg extdiff [OPT]... [FILE]...'), |
40293
c303d65d2e34
help: assigning categories to existing commands
rdamazio@google.com
parents:
38165
diff
changeset
|
427 |
helpcategory=command.CATEGORY_FILE_CONTENTS, |
21781
f0c3b95af47f
extdiff: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21246
diff
changeset
|
428 |
inferrepo=True) |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
429 |
def extdiff(ui, repo, *pats, **opts): |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
430 |
'''use external program to diff repository (or selected files) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
431 |
|
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
432 |
Show differences between revisions for the specified files, using |
7983
7b813bdbd5d0
Change double spaces to single spaces in help texts.
Martin Geisler <mg@daimi.au.dk>
parents:
7758
diff
changeset
|
433 |
an external program. The default program used is diff, with |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
434 |
default options "-Npru". |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
435 |
|
8076
5ec526c1a32f
help texts: write command line switches as -a/--abc
Martin Geisler <mg@lazybytes.net>
parents:
8066
diff
changeset
|
436 |
To select a different program, use the -p/--program option. The |
41487
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
437 |
program will be passed the names of two directories to compare, |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
438 |
unless the --per-file option is specified (see below). To pass |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
439 |
additional options to the program, use -o/--option. These will be |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
440 |
passed before the names of the directories or files to compare. |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
441 |
|
7990
cdb848e8c4b5
extdiff: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
442 |
When two revision arguments are given, then changes are shown |
cdb848e8c4b5
extdiff: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
443 |
between those revisions. If only one revision is specified then |
cdb848e8c4b5
extdiff: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
444 |
that revision is compared to the working directory, and, when no |
cdb848e8c4b5
extdiff: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
445 |
revisions are specified, the working directory files are compared |
41487
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
446 |
to its parent. |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
447 |
|
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
448 |
The --per-file option runs the external program repeatedly on each |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
449 |
file to diff, instead of once on two directories. |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
450 |
|
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
451 |
The --confirm option will prompt the user before each invocation of |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
452 |
the external program. It is ignored if --per-file isn't specified. |
fa471151d269
extdiff: add --per-file and --confirm options
Ludovic Chabant <ludovic@chabant.com>
parents:
41196
diff
changeset
|
453 |
''' |
34976
a8bc191fee5a
py3: handle keyword arguments in hgext/extdiff.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34778
diff
changeset
|
454 |
opts = pycompat.byteskwargs(opts) |
9519
0d3c1aa9d5de
extdiff: fix defaulting to "diff" if no --program is given
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8934
diff
changeset
|
455 |
program = opts.get('program') |
0d3c1aa9d5de
extdiff: fix defaulting to "diff" if no --program is given
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8934
diff
changeset
|
456 |
option = opts.get('option') |
0d3c1aa9d5de
extdiff: fix defaulting to "diff" if no --program is given
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8934
diff
changeset
|
457 |
if not program: |
0d3c1aa9d5de
extdiff: fix defaulting to "diff" if no --program is given
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8934
diff
changeset
|
458 |
program = 'diff' |
0d3c1aa9d5de
extdiff: fix defaulting to "diff" if no --program is given
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8934
diff
changeset
|
459 |
option = option or ['-Npru'] |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
460 |
cmdline = ' '.join(map(procutil.shellquote, [program] + option)) |
23680
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
461 |
return dodiff(ui, repo, cmdline, pats, opts) |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
462 |
|
29721
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
463 |
class savedcmd(object): |
29723
91b2f2176395
extdiff: isolate path variable of saved command to independent paragraph
Yuya Nishihara <yuya@tcha.org>
parents:
29722
diff
changeset
|
464 |
"""use external program to diff repository (or selected files) |
29721
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
465 |
|
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
466 |
Show differences between revisions for the specified files, using |
29723
91b2f2176395
extdiff: isolate path variable of saved command to independent paragraph
Yuya Nishihara <yuya@tcha.org>
parents:
29722
diff
changeset
|
467 |
the following program:: |
91b2f2176395
extdiff: isolate path variable of saved command to independent paragraph
Yuya Nishihara <yuya@tcha.org>
parents:
29722
diff
changeset
|
468 |
|
91b2f2176395
extdiff: isolate path variable of saved command to independent paragraph
Yuya Nishihara <yuya@tcha.org>
parents:
29722
diff
changeset
|
469 |
%(path)s |
29721
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
470 |
|
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
471 |
When two revision arguments are given, then changes are shown |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
472 |
between those revisions. If only one revision is specified then |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
473 |
that revision is compared to the working directory, and, when no |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
474 |
revisions are specified, the working directory files are compared |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
475 |
to its parent. |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
476 |
""" |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
477 |
|
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
478 |
def __init__(self, path, cmdline): |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
479 |
# We can't pass non-ASCII through docstrings (and path is |
40806
151aec6494a8
extdiff: avoid double backslashes in the displayed tool path on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40407
diff
changeset
|
480 |
# in an unknown encoding anyway), but avoid double separators on |
151aec6494a8
extdiff: avoid double backslashes in the displayed tool path on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40407
diff
changeset
|
481 |
# Windows |
151aec6494a8
extdiff: avoid double backslashes in the displayed tool path on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40407
diff
changeset
|
482 |
docpath = stringutil.escapestr(path).replace(b'\\\\', b'\\') |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36781
diff
changeset
|
483 |
self.__doc__ %= {r'path': pycompat.sysstr(stringutil.uirepr(docpath))} |
29721
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
484 |
self._cmdline = cmdline |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
485 |
|
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
486 |
def __call__(self, ui, repo, *pats, **opts): |
34976
a8bc191fee5a
py3: handle keyword arguments in hgext/extdiff.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34778
diff
changeset
|
487 |
opts = pycompat.byteskwargs(opts) |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
488 |
options = ' '.join(map(procutil.shellquote, opts['option'])) |
29721
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
489 |
if options: |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
490 |
options = ' ' + options |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
491 |
return dodiff(ui, repo, self._cmdline + options, pats, opts) |
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
492 |
|
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
493 |
def uisetup(ui): |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
494 |
for cmd, path in ui.configitems('extdiff'): |
24193
fa4642439aa0
extdiff: expand tildes and variables in paths to user-supplied diff programs
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
23969
diff
changeset
|
495 |
path = util.expandpath(path) |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
496 |
if cmd.startswith('cmd.'): |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
497 |
cmd = cmd[4:] |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
498 |
if not path: |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
499 |
path = procutil.findexe(cmd) |
23150
aff73c777b0b
extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents:
23149
diff
changeset
|
500 |
if path is None: |
aff73c777b0b
extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents:
23149
diff
changeset
|
501 |
path = filemerge.findexternaltool(ui, cmd) or cmd |
34777
bb2525871d95
configitems: register the 'exdiff.opts.*' config
Boris Feld <boris.feld@octobus.net>
parents:
32431
diff
changeset
|
502 |
diffopts = ui.config('extdiff', 'opts.' + cmd) |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
503 |
cmdline = procutil.shellquote(path) |
23680
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
504 |
if diffopts: |
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
505 |
cmdline += ' ' + diffopts |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
506 |
elif cmd.startswith('opts.'): |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
507 |
continue |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
508 |
else: |
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
509 |
if path: |
23680
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
510 |
# case "cmd = path opts" |
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
511 |
cmdline = path |
30678
caf7e1c5efe4
py3: have a bytes version of shlex.split()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29841
diff
changeset
|
512 |
diffopts = len(pycompat.shlexsplit(cmdline)) > 1 |
5245
a1efa71f3ece
Improve extdiff configuration.
Brendan Cully <brendan@kublai.com>
parents:
5147
diff
changeset
|
513 |
else: |
23680
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
514 |
# case "cmd =" |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
515 |
path = procutil.findexe(cmd) |
23150
aff73c777b0b
extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents:
23149
diff
changeset
|
516 |
if path is None: |
aff73c777b0b
extdiff: allow a preconfigured merge-tool to be invoked
Matt Harbison <matt_harbison@yahoo.com>
parents:
23149
diff
changeset
|
517 |
path = filemerge.findexternaltool(ui, cmd) or cmd |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
518 |
cmdline = procutil.shellquote(path) |
23680
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
519 |
diffopts = False |
11184
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
520 |
# look for diff arguments in [diff-tools] then [merge-tools] |
23680
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
521 |
if not diffopts: |
11184
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
522 |
args = ui.config('diff-tools', cmd+'.diffargs') or \ |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
523 |
ui.config('merge-tools', cmd+'.diffargs') |
7d99edddbaea
extdiff: add labels, read diff arguments from [merge-tools]
Steve Borho <steve@borho.org>
parents:
10394
diff
changeset
|
524 |
if args: |
23680
4075f2f8ea53
extdiff: avoid unexpected quoting arguments for external tools (issue4463)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23270
diff
changeset
|
525 |
cmdline += ' ' + args |
27681
174069440929
extdiff: use @command decorator to set up diff commands
Yuya Nishihara <yuya@tcha.org>
parents:
27680
diff
changeset
|
526 |
command(cmd, extdiffopts[:], _('hg %s [OPTION]... [FILE]...') % cmd, |
40801
97190b0bb81a
extdiff: register the configuration generated commands with a help category
Matt Harbison <matt_harbison@yahoo.com>
parents:
40293
diff
changeset
|
527 |
helpcategory=command.CATEGORY_FILE_CONTENTS, |
29721
479076db51be
extdiff: refactor closure of saved diff command as a top-level class
Yuya Nishihara <yuya@tcha.org>
parents:
29630
diff
changeset
|
528 |
inferrepo=True)(savedcmd(path, cmdline)) |
29722
14c3afcb1c26
extdiff: export __doc__ of saved command for translation
Yuya Nishihara <yuya@tcha.org>
parents:
29721
diff
changeset
|
529 |
|
14c3afcb1c26
extdiff: export __doc__ of saved command for translation
Yuya Nishihara <yuya@tcha.org>
parents:
29721
diff
changeset
|
530 |
# tell hggettext to extract docstrings from these functions: |
14c3afcb1c26
extdiff: export __doc__ of saved command for translation
Yuya Nishihara <yuya@tcha.org>
parents:
29721
diff
changeset
|
531 |
i18nfunctions = [savedcmd] |