Commit Graph

106 Commits

Author SHA1 Message Date
Jordi Gutiérrez Hermoso
3fea7e90e6 extdiff: expand tildes and variables in paths to user-supplied diff programs 2015-02-27 17:35:07 -05:00
Mads Kiilerich
a59deecf40 extdiff: reintroduce backward compatibility with manual quoting of parameters
b8552020f458 broke things ... and the following cleanups didn't fix all issues.
It didn't work with the diffargs shipped in mergetools.rc with explicit
quoting. Parameters would end up with being quoted twice - especially if they
really needed quoting.

To work around that, look for explicit quotes around the variables that will be
substituted with proper quoting. Also accept an additional prefix so we can
handle both
  --foo='$parent'
and
  '--foo=$parent'

It will however still fail if the user intentionally place the variable inside
a quoted string, as in
  'parent $parent is on the left'
There is currently no good way to handle that, short of knowing exactly which
quoting mechanism will be used.
2015-01-28 02:28:39 +01:00
FUJIWARA Katsunori
557f94c70c extdiff: rename the name of an argument for readability
To reduce amount of changes for review-ability, previous patch uses
"args" as argument name of "dodiff()", even though "args" includes
also the name of command to be executed (or full-path of it).

This patch replaces "args" by more appropriate name "cmdline".
2014-12-25 23:33:26 +09:00
FUJIWARA Katsunori
203706516b extdiff: avoid unexpected quoting arguments for external tools (issue4463)
Before this patch, all command line arguments for external tools are
quoted by the combination of "shlex.split" and "util.shellquote". But
this causes some problems.

  - some problematic commands can't work correctly with quoted arguments

    For example, 'WinMerge /r ....' is OK, but 'WinMerge "/r" ....' is
    NG. See also below for detail about this problem.

        https://bitbucket.org/tortoisehg/thg/issue/3978/

  - quoting itself may change semantics of arguments

    For example, when the environment variable CONCAT="foo bar baz':

      - mydiff $CONCAT   => mydiff foo bar baz   (taking 3 arguments)
      - mydiff "$CONCAT" => mydiff "foo bar baz" (taking only 1 argument)

    For another example, single quoting (= "util.shellquote") on POSIX
    environment prevents shells from expanding environment variables,
    tilde, and so on:

      - mydiff "$HOME" => mydiff /home/foobar
      - mydiff '$HOME' => mydiff $HOME

  - "shlex.split" can't handle some special characters correctly

    It just splits specified command line by whitespaces.

    For example, "echo foo;echo bar" is split into ["echo",
    "foo;echo", "bar"].

On the other hand, if quoting itself is omitted, users can't specify
options including space characters with "--option" at runtime.

The root cause of this issue is that "shlex.split + util.shellquote"
combination loses whether users really want to quote each command line
elements or not, even though these can be quoted arbitrarily in
configurations.

To resolve this problem, this patch does:

  - prevent configurations from being processed by "shlex.split" and
    "util.shellquote"

    only (possibly) "findexe"-ed or "findexternaltool"-ed command path
    is "util.shellquote", because it may contain whitespaces.

  - quote options specified by "--option" via command line at runtime

This patch also makes "dodiff()" take only one "args" argument instead
of "diffcmd" and "diffopts. It also omits applying "util.shellquote"
on "args", because "args" should be already stringified in "extdiff()"
and "mydiff()".

The last hunk for "test-extdiff.t" replaces two whitespaces by single
whitespace, because change of "' '.join()" logic causes omitting
redundant whitespaces.
2014-12-25 23:33:26 +09:00
Yuya Nishihara
ceda6fbba9 util.system: use ui.system() in place of optional ui.fout parameter 2014-11-08 13:06:22 +09:00
Matt Mackall
462cd9a28d merge with stable 2014-11-03 16:56:32 -06:00
Matt Harbison
13f1cdf941 extdiff: drop the command alias without options example in the help text
In the dropped example, the extension would look for 'vdiff.diffargs' in the
configuration, and not finding it, would run kdiff3 without the configured
options.  That's not obvious to a new user who sees a kdiff3 configuration in
the prepackaged mergetools.rc file, and sees that kdiff3 still runs.  While it
is conceivable that the user wants a kdiff3 command that runs without the
preconfigured options, it is more likely what they want is this, which uses the
canned options:

    [alias]
    vdiff = kdiff3

    [extdiff]
    kdiff3 =

We could mention alias here, but that seems like it belongs elswhere.
2014-11-02 15:27:15 -05:00
Matt Harbison
41a84ec470 extdiff: allow a preconfigured merge-tool to be invoked
There are three ways to configure an extdiff tool:

    1) cmd.tool = (/path/to/exe optional)
    2) tool = (path/to/exe optional)
    3) tool = sometool someargs

Previously, if no executable is specified in the first two forms, the named tool
must be in $PATH, or the invocation fails.  Since the [merge-tools] section
already has the path to the diff executable, and/or the registry keys to find
the executable on Windows, reuse that configuration for forms 1 and 2 instead of
failing.  We already fallback to [diff-tools] and then [merge-tools] for program
arguments if they aren't specified in the [extdiff] section.

Since this additional lookup only occurs if an executable is not on the $PATH
for the named tool, this is backwards compatible.  For now, we assume the user
knows what he is doing if a path is provided.

This change allows a configuration file like this (assuming beyondcompare3 is
configured in merge-tools), instead of hardcoding system specific a path:

    [extdiff]
    beyondcompare3 =
2014-10-31 21:34:55 -04:00
Matt Mackall
a933604ec7 extdiff: sort files when snapshotting
This fixes output stability and is generally
filesystem-performance-friendly.
2014-11-03 16:30:21 -06:00
Mads Kiilerich
3947517b04 cleanup: remove some unused / duplicate imports 2014-08-15 04:37:45 +02:00
Gregory Szorc
3086949df4 extdiff: define inferrepo in command decorator 2014-05-04 22:29:27 -07:00
Michael Fyles
001d1e7cb7 extdiff: quote user-supplied options passed to shell
$ hg extdiff -p cmd -o "name <user@example.com>"
resulted in a shell redirection error (due to the less-than sign),
rather than passing the single option to cmd. This was due to options
not being quoted for passing to the shell, via util.system(). Apply
util.shellquote() to each of the user-specified options (-o) to the
comparison program before they are concatenated and passed to
util.system(). The requested external diff command (-p) and the
files/directories being compared are already quoted correctly.

The discussion at the time of changeset 6654fcb57d92 correctly noted
that this course of action breaks whitespace-separated options specified
for external diff commands in the configuration. The lower part of the
patch corrects this by lexing options read from the configuration file
into separate options rather than reading them all into the first
option.

Update test to cover these conditions.

Related changesets (reverse-chronological):
- 6654fcb57d92 (fix reverted to make configuration file options work)
- c64ec6e8ffa2 (issue fixed but without fix for configuration file)
2012-07-26 11:38:13 +01:00
Gregory Szorc
07cdf48f61 extdiff: declare command using decorator 2014-05-04 21:54:01 -07:00
Augie Fackler
05a09487ed extdiff: move from dict() construction to {} literals
The latter are both faster and more consistent across Python 2 and 3.
2014-03-12 13:13:42 -04:00
Siddharth Agarwal
a5e71891bd commands: don't infer repo for commands like update (issue2748)
Maintain a whitelist of commands to infer the repo for instead. The whitelist
contains those commands that take file(s) in the working dir as arguments.
2012-10-16 11:43:15 -07:00
Mads Kiilerich
2f4504e446 fix trivial spelling errors 2012-08-15 22:38:42 +02:00
Augie Fackler
96d44b39f7 hgext: mark all first-party extensions as such 2012-05-15 14:37:49 -05:00
Brodie Rao
a7ef0a0cc5 cleanup: "not x in y" -> "x not in y" 2012-05-12 16:00:57 +02:00
Thomas Arendsen Hein
2210a784fd extdiff: escape filenames with vim/DirDiff and make quoting work with Windows
Use vim function fnameescape() on filenames.
Use double quotes for arguments so cmd.exe is happy.
2012-03-12 09:39:30 +01:00
Idan Kamara
09b97b7cff extdiff: use ui out descriptor when calling util.system 2011-06-24 17:04:37 +03:00
Matt Mackall
5ab97592f7 scmutil: switch match users to supplying contexts
The most appropriate context is not always clearly defined. The obvious cases:

For working directory commands, we use None
For commands (eg annotate) with single revs, we use that revision

The less obvious cases:

For commands (eg status, diff) with a pair of revs, we use the second revision
For commands that take a range (like log), we use None
2011-06-18 16:52:51 -05:00
Javi Merino
c3168645be extdiff: grammar "allows to" -> "allows one to"
The verb to allow requires a direct object.

Lintian, a Debian tool to find common mistakes, reported it. I'm not a
native english speaker but I think this is correct.
2011-05-15 18:00:22 +01:00
Matt Mackall
0832007f60 scmutil: drop aliases in cmdutil for match functions 2011-05-13 14:58:24 -05:00
Matt Mackall
cf07129983 scmutil: move revsingle/pair/range from cmdutil
This allows users at levels below the command layer to avoid import loops.
2011-05-13 14:06:28 -05:00
Adrian Buehlmann
c415440828 rename util.set_flags to setflags 2011-05-06 15:22:31 +02:00
Dan Villiom Podlaski Christiansen
511c941422 prevent transient leaks of file handle by using new helper functions
These leaks may occur in environments that don't employ a reference
counting GC, i.e. PyPy.

This implies:
 - changing opener(...).read() calls to opener.read(...)
 - changing opener(...).write() calls to opener.write(...)
 - changing open(...).read(...) to util.readfile(...)
 - changing open(...).write(...) to util.writefile(...)
2011-05-02 10:11:18 +02:00
Steven Stallion
b6327cdf0a extdiff: add repository root as a variable
Some external diff tools (notably Plan 9 diff(1)) require the absolute path
to the file being diffed for proper function. A root variable was added to
inform an external tool of the repository root (the tool is invoked with the
cwd set to tmproot).
2011-04-27 21:55:46 -04:00
Thomas Arendsen Hein
e6dcc5994e merge with stable 2011-04-29 11:10:11 +02:00
Patrick Mezard
2cbeb4b9c6 extdiff: fix broken symlinks handling (issue1909) 2011-04-29 08:04:46 +02:00
Adrian Buehlmann
cf126bb7dd move opener from util to scmutil 2011-04-20 19:54:57 +02:00
Matt Mackall
a8dd64dcb0 misc: replace .parents()[0] with p1() 2011-04-04 16:21:59 -05:00
jfh
a63916e626 extdiff: use absolute paths for any temporary files
This allows the use of p4merge amongst possible other external tools.
2011-03-21 17:03:16 +01:00
David Wolever
7bd158b865 Updating hgext.extdiff to use revsets 2011-03-15 17:50:02 -04:00
FUJIWARA Katsunori
ce06b102df help: show value requirement and multiple occurrence of options
this helps users to know what kind of option is:

  - no value is required(flag option)
  - value is required
  - value is required, and multiple occurrences are allowed

each kinds are shown as below:

 -f --force              force push
 -e --ssh CMD            specify ssh command to use
 -b --branch BRANCH [+]  a specific branch you would like to push

if one or more 3rd type options are shown, explanation for '[+]' mark
is also shown as footnote.
2010-06-06 17:25:00 +09:00
Martin Geisler
a6312d22f5 extdiff: fix reST syntax in module docstring 2010-05-17 23:11:27 +02:00
Steve Borho
c76d6b8145 extdiff: add labels, read diff arguments from [merge-tools]
hgtk has been using these same configs since Feb. Users only have to name the
tools they would like to use, ex:

[extdiff]
kdiff3 =
meld =
2010-01-07 22:19:05 -06:00
Benoit Boissinot
328394047f fix coding style (reported by pylint) 2010-02-08 15:36:34 +01:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Matt Mackall
cd3ef170f7 Merge with stable 2010-01-19 22:45:09 -06:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Sune Foldager
2368eabe27 extdiff: respect --option in command aliases (issue949) 2009-11-30 19:37:38 +01:00
Martin Geisler
5ad36f40d3 extdiff: prevent exception on double-translation
The docstring is translated twice: once when used as a format string,
and once on display. The second translation fails when the first
translation introduces non-ASCII characters in the string.

The problem is that the gettext module calls unicode(message) on the
string, i.e., it decodes it to a Unicode string using the ASCII
encoding (the default encoding). By translating it into a Unicode
string here, the unicode() call becomes a noop.
2009-11-26 20:06:45 +01:00
Matt Mackall
13b406f027 Merge with -stable 2009-10-03 14:39:57 -05:00
Sune Foldager
c7e7232f9e extdiff: add 3-way diff for merge changesets
This adds 3-way diff for merge changesets (using -c) and for diffing
the working directory context against two parents. To enable it, use
the new magic value '$parent2' in the argument line. In order to work,
your differ must support that the second parent argument is left out;
this will happen in 2-way mode. Default arguments are as before, without
enabling 3-way mode, ensuring backwards compatibility.

This also fixes a problem when diffing a merge changeset with a single
file change. Extdiff would sometimes do the wrong thing in that situation.
2009-09-17 21:12:32 +02:00
Martin Geisler
9f1896c083 do not attempt to translate ui.debug output 2009-09-19 01:15:38 +02:00
Peter Arrenbrecht
4e1708dc3a extdiff: fix defaulting to "diff" if no --program is given 2009-10-01 08:50:10 +02:00
Cédric Duval
21be180306 doc: fix quotes mismatches affecting rst 2009-07-31 01:40:45 +02:00
Martin Geisler
917d000717 extdiff: wrap docstrings at 70 characters 2009-07-26 01:45:36 +02:00
Martin Geisler
a3715f628a extdiff: use reST syntax for literal block 2009-07-23 00:22:50 +02:00
Martin Geisler
e48f6a2ae3 extdiff: wrapped docstrings at 78 characters 2009-07-07 23:54:42 +02:00