Commit Graph

123 Commits

Author SHA1 Message Date
Pulkit Goyal
d310fba3dd py3: have a bytes version of shlex.split()
shlex.split() only accepts unicodes on Python 3. After this patch we will be
using pycompat.shlexsplit(). This patch also replaces existing occurences of
shlex.split with pycompat.shlexsplit.
2016-12-25 03:06:55 +05:30
Augie Fackler
4e1c384d0a extensions: change magic "shipped with hg" string
I've caught multiple extensions in the wild lying about being
'internal', so it's time to move the goalposts on people. Goalpost
moving will continue until third party extensions stop trying to
defeat the system.
2016-08-23 11:26:08 -04:00
Yuya Nishihara
84f406e3b9 extdiff: isolate path variable of saved command to independent paragraph
Otherwise, the whole paragraph wouldn't be translated.
2016-07-27 21:44:49 +09:00
Yuya Nishihara
22ee04a3ca extdiff: export __doc__ of saved command for translation 2016-07-27 21:42:24 +09:00
Yuya Nishihara
fe246a4d88 extdiff: refactor closure of saved diff command as a top-level class
This allows us to collect __doc__ for translation.
2016-07-27 21:40:42 +09:00
Matt Mackall
01b803db22 extdiff: escape path for docstring (issue5301)
The existing code (a) assumed path would be specified in
encoding.encoding and (b) assumed unicode() objects wouldn't cause
other parts of Mercurial to blow up. Both are dangerous assumptions.

Since we don't know the encoding of path and can't pass non-ASCII
through docstrings, just escape the path and drop the early _(). Will
have to suffice until we can teach docstrings to handle UTF-8b
escaping.

This has the side-effect that the line containing the path is now
variable by the time it reaches _() and thus can't be translated.
2016-07-18 16:25:35 -05:00
Pulkit Goyal
d623f99ed3 py3: make extdiff use absolute_import 2016-04-17 02:15:05 +05:30
Yuya Nishihara
699ec74ad9 extdiff: use @command decorator to set up diff commands
It can set "inferrepo" attribute appropriately.
2016-01-01 22:35:34 +09:00
Yuya Nishihara
daf4a450f1 extdiff: factor out list of common options 2016-01-04 22:13:46 +09:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Matt Harbison
99ffdaafef extdiff: enable -I/-X with --patch
Not sure how useful this really is, but it's trivial to add and ignoring the
existing arguments supported seems like a bad UI.
2015-09-09 22:27:48 -04:00
Matt Harbison
c3b634a166 extdiff: add a --patch argument for diffing changeset deltas
One of the things I missed the most when transitioning from versioned MQ to
evolve was the loss of being able to check that rebase conflicts were properly
resolved by:

  $ hg ci --mq -m "before"
  $ hg rebase -s qbase -d tip
  $ hg bcompare --mq

The old csets stay in the tree with evolve, but a straight diff includes all of
the other changes that were pulled in, obscuring the code that was rebased.
Diffing deltas can be confusing, but unless radical changes were made during the
resolve, it is very clear when individual hunks are added, dropped or modified.
Unlike the MQ technique, this can only compare a single pair of csets/patches at
a time.  Like the MQ method, this also highlights changes in the commit comment
and other metadata.

I originally tried monkey patching from the evolve extension, but that is too
complicated given that it depends on the order the two different extensions are
loaded.  This functionality is also useful when comparing grafts however, so
implementing it in the core is more than just convenience.

The --change argument doesn't make much sense for this, but it isn't harmful so
I didn't bother blocking it.  The -I/-X options are ignored because of a
limitation of cmdutil.export().  We'll fix that next.
2015-09-09 21:07:38 -04:00
Matt Harbison
d9022f7c59 extdiff: prepare sections of dodiff() for conditionalizing
This is purely indenting under an unconditional branch, so that the actual
changes in the next patch are clear.  Feel free to fold them if desired.
2015-09-09 20:48:09 -04:00
Matt Harbison
eea8aa5335 extdiff: allow modifications in subrepos to be copied back
This check was a legacy bit from when the file data was being fetched manually
with 'ctx[wfn]', but archive() does that now.  2032c5b369f5 seems to indicate
that this avoided a problem where a merge adds a file to another branch, and
that test still passes.

Unfortunately, I don't see a way to create a test that modifies the file in the
temporary directory before the command exits.

I wonder if the os.lstat() call needs to be wrapped in an exception handler for
the case where archive didn't create a file because the file didn't exist in
that revision.  But I wasn't able to trigger a problem without it on a real
repository.
2015-07-27 17:39:09 -04:00
Matt Harbison
400240f7c1 extdiff: add support for subrepos
Git and svn subrepo support is incomplete, because they don't support archiving
the working copy.
2012-07-15 12:43:10 -04:00
Matt Harbison
6579c8c6d9 extdiff: use archiver to take snapshots of committed revisions
This is the last step before supporting extdiff -S.  It maintains the existing
behavior of diffing the largefile standins instead of the largefiles themselves.
Note however that the standins are not updated immediately upon modification, so
uncommitted largefile changes are ignored, as they previously were, even with
the diff command.
2012-07-11 20:48:51 -04:00
Augie Fackler
f95a6caba1 extensions: document that testedwith = 'internal' is special
Extension authors (notably at companies using hg) have been
cargo-culting the `testedwith = 'internal'` bit from hg's own
extensions, which then defeats our "file bugs over here" logic in
dispatch. Let's be more aggressive about trying to give extension
authors a hint about what testedwith should say.
2015-04-28 16:44:37 -04:00
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