2006-05-22 10:39:07 +04:00
|
|
|
# extdiff.py - external diff program support for mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2007-08-25 23:25:53 +04:00
|
|
|
|
2009-06-24 15:42:02 +04:00
|
|
|
'''command to allow external programs to compare revisions
|
2009-06-21 18:45:47 +04:00
|
|
|
|
2009-07-31 03:40:45 +04:00
|
|
|
The extdiff Mercurial extension allows you to use external programs
|
2009-07-26 03:45:36 +04:00
|
|
|
to compare revisions, or revision with working directory. The external
|
|
|
|
diff programs are called with a configurable set of options and two
|
|
|
|
non-option arguments: paths to directories containing snapshots of
|
|
|
|
files to compare.
|
2007-08-25 23:25:53 +04:00
|
|
|
|
2011-05-15 21:00:22 +04:00
|
|
|
The extdiff extension also allows you to configure new diff commands, so
|
2010-05-18 01:11:27 +04:00
|
|
|
you do not need to type :hg:`extdiff -p kdiff3` always. ::
|
2007-08-25 23:25:53 +04:00
|
|
|
|
|
|
|
[extdiff]
|
|
|
|
# add new command that runs GNU diff(1) in 'context diff' mode
|
|
|
|
cdiff = gdiff -Nprc5
|
|
|
|
## or the old way:
|
|
|
|
#cmd.cdiff = gdiff
|
|
|
|
#opts.cdiff = -Nprc5
|
|
|
|
|
2014-11-01 04:34:55 +03:00
|
|
|
# add new command called meld, runs meld (no need to name twice). If
|
|
|
|
# the meld executable is not available, the meld tool in [merge-tools]
|
|
|
|
# will be used, if available
|
2007-08-25 23:25:53 +04:00
|
|
|
meld =
|
|
|
|
|
2009-07-26 03:45:36 +04:00
|
|
|
# add new command called vimdiff, runs gvimdiff with DirDiff plugin
|
|
|
|
# (see http://www.vim.org/scripts/script.php?script_id=102) Non
|
|
|
|
# English user, be sure to put "let g:DirDiffDynamicDiffText = 1" in
|
|
|
|
# your .vimrc
|
2012-03-12 12:39:30 +04:00
|
|
|
vimdiff = gvim -f "+next" \\
|
|
|
|
"+execute 'DirDiff' fnameescape(argv(0)) fnameescape(argv(1))"
|
2007-08-25 23:25:53 +04:00
|
|
|
|
2010-05-18 01:11:27 +04:00
|
|
|
Tool arguments can include variables that are expanded at runtime::
|
2010-01-08 07:19:05 +03:00
|
|
|
|
|
|
|
$parent1, $plabel1 - filename, descriptive label of first parent
|
|
|
|
$child, $clabel - filename, descriptive label of child revision
|
|
|
|
$parent2, $plabel2 - filename, descriptive label of second parent
|
2011-04-28 05:55:46 +04:00
|
|
|
$root - repository root
|
2010-01-08 07:19:05 +03:00
|
|
|
$parent is an alias for $parent1.
|
|
|
|
|
|
|
|
The extdiff extension will look in your [diff-tools] and [merge-tools]
|
|
|
|
sections for diff tool arguments, when none are specified in [extdiff].
|
|
|
|
|
2010-05-18 01:11:27 +04:00
|
|
|
::
|
|
|
|
|
2010-01-08 07:19:05 +03:00
|
|
|
[extdiff]
|
2010-05-18 01:11:27 +04:00
|
|
|
kdiff3 =
|
2010-01-08 07:19:05 +03:00
|
|
|
|
|
|
|
[diff-tools]
|
|
|
|
kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child
|
|
|
|
|
2010-05-18 01:11:27 +04:00
|
|
|
You can use -I/-X and list of file or directory names like normal
|
|
|
|
:hg:`diff` command. The extdiff extension makes snapshots of only
|
|
|
|
needed files, so running the external diff program will actually be
|
|
|
|
pretty fast (at least faster than having to compare the entire tree).
|
2007-08-25 23:25:53 +04:00
|
|
|
'''
|
2006-05-22 10:39:07 +04:00
|
|
|
|
2016-04-16 23:45:05 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import tempfile
|
2006-12-15 05:25:19 +03:00
|
|
|
from mercurial.i18n import _
|
2016-04-16 23:45:05 +03:00
|
|
|
from mercurial.node import (
|
|
|
|
nullid,
|
|
|
|
short,
|
|
|
|
)
|
|
|
|
from mercurial import (
|
|
|
|
archival,
|
|
|
|
cmdutil,
|
|
|
|
commands,
|
|
|
|
error,
|
|
|
|
filemerge,
|
2016-12-25 00:36:55 +03:00
|
|
|
pycompat,
|
2016-04-16 23:45:05 +03:00
|
|
|
scmutil,
|
|
|
|
util,
|
|
|
|
)
|
2006-05-22 10:39:07 +04:00
|
|
|
|
2014-05-05 08:54:01 +04:00
|
|
|
cmdtable = {}
|
|
|
|
command = cmdutil.command(cmdtable)
|
2016-08-23 18:26:08 +03:00
|
|
|
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
|
2015-04-28 23:44:37 +03:00
|
|
|
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
|
|
|
|
# be specifying the version(s) of Mercurial they are tested with, or
|
|
|
|
# leave the attribute unspecified.
|
2016-08-23 18:26:08 +03:00
|
|
|
testedwith = 'ships-with-hg-core'
|
2012-05-15 23:37:49 +04:00
|
|
|
|
2012-07-15 20:43:10 +04:00
|
|
|
def snapshot(ui, repo, files, node, tmproot, listsubrepos):
|
2009-04-13 23:21:01 +04:00
|
|
|
'''snapshot files as of some revision
|
2007-08-07 01:32:23 +04:00
|
|
|
if not using snapshot, -I/-X does not work and recursive diff
|
|
|
|
in tools like kdiff3 and meld displays too many files.'''
|
2009-01-03 00:53:33 +03:00
|
|
|
dirname = os.path.basename(repo.root)
|
2007-08-07 01:32:23 +04:00
|
|
|
if dirname == "":
|
|
|
|
dirname = "root"
|
2009-04-13 23:21:01 +04:00
|
|
|
if node is not None:
|
|
|
|
dirname = '%s.%s' % (dirname, short(node))
|
2007-08-07 01:32:23 +04:00
|
|
|
base = os.path.join(tmproot, dirname)
|
|
|
|
os.mkdir(base)
|
2012-07-12 04:48:51 +04:00
|
|
|
fns_and_mtime = []
|
|
|
|
|
2009-04-13 23:21:01 +04:00
|
|
|
if node is not None:
|
|
|
|
ui.note(_('making snapshot of %d files from rev %s\n') %
|
|
|
|
(len(files), short(node)))
|
|
|
|
else:
|
2009-04-13 23:57:17 +04:00
|
|
|
ui.note(_('making snapshot of %d files from working directory\n') %
|
2007-08-07 12:28:43 +04:00
|
|
|
(len(files)))
|
2012-07-12 04:48:51 +04:00
|
|
|
|
|
|
|
if files:
|
|
|
|
repo.ui.setconfig("ui", "archivemeta", False)
|
|
|
|
|
|
|
|
archival.archive(repo, base, node, 'files',
|
2012-07-15 20:43:10 +04:00
|
|
|
matchfn=scmutil.matchfiles(repo, files),
|
|
|
|
subrepos=listsubrepos)
|
2012-07-12 04:48:51 +04:00
|
|
|
|
|
|
|
for fn in sorted(files):
|
|
|
|
wfn = util.pconvert(fn)
|
|
|
|
ui.note(' %s\n' % wfn)
|
|
|
|
|
|
|
|
if node is None:
|
|
|
|
dest = os.path.join(base, wfn)
|
|
|
|
|
|
|
|
fns_and_mtime.append((dest, repo.wjoin(fn),
|
|
|
|
os.lstat(dest).st_mtime))
|
2007-08-27 04:31:18 +04:00
|
|
|
return dirname, fns_and_mtime
|
2007-08-07 12:28:43 +04:00
|
|
|
|
2014-12-25 17:33:26 +03:00
|
|
|
def dodiff(ui, repo, cmdline, pats, opts):
|
2012-08-16 00:38:42 +04:00
|
|
|
'''Do the actual diff:
|
2007-08-27 04:31:18 +04:00
|
|
|
|
|
|
|
- copy to a temp structure if diffing 2 internal revisions
|
|
|
|
- copy to a temp structure if diffing working revision with
|
|
|
|
another one and more than 1 file is changed
|
|
|
|
- just invoke the diff for a single file in the working dir
|
|
|
|
'''
|
2009-02-07 21:41:05 +03:00
|
|
|
|
|
|
|
revs = opts.get('rev')
|
|
|
|
change = opts.get('change')
|
2014-12-25 17:33:26 +03:00
|
|
|
do3way = '$parent2' in cmdline
|
2009-02-07 21:41:05 +03:00
|
|
|
|
|
|
|
if revs and change:
|
|
|
|
msg = _('cannot specify --rev and --change at the same time')
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg)
|
2009-02-07 21:41:05 +03:00
|
|
|
elif change:
|
2011-05-13 23:06:28 +04:00
|
|
|
node2 = scmutil.revsingle(repo, change, None).node()
|
2009-09-17 23:12:32 +04:00
|
|
|
node1a, node1b = repo.changelog.parents(node2)
|
2009-02-07 21:41:05 +03:00
|
|
|
else:
|
2011-05-13 23:06:28 +04:00
|
|
|
node1a, node2 = scmutil.revpair(repo, revs)
|
2009-09-17 23:12:32 +04:00
|
|
|
if not revs:
|
2011-04-05 01:21:59 +04:00
|
|
|
node1b = repo.dirstate.p2()
|
2009-09-17 23:12:32 +04:00
|
|
|
else:
|
|
|
|
node1b = nullid
|
|
|
|
|
|
|
|
# Disable 3-way merge if there is only one parent
|
|
|
|
if do3way:
|
|
|
|
if node1b == nullid:
|
|
|
|
do3way = False
|
2009-02-07 21:41:05 +03:00
|
|
|
|
2012-07-15 20:43:10 +04:00
|
|
|
subrepos=opts.get('subrepos')
|
|
|
|
|
2011-06-19 01:52:51 +04:00
|
|
|
matcher = scmutil.match(repo[node2], pats, opts)
|
2015-09-10 03:48:09 +03:00
|
|
|
|
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-10 04:07:38 +03:00
|
|
|
if opts.get('patch'):
|
|
|
|
if subrepos:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('--patch cannot be used with --subrepos'))
|
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-10 04:07:38 +03:00
|
|
|
if node2 is None:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('--patch requires two revisions'))
|
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-10 04:07:38 +03:00
|
|
|
else:
|
2015-09-10 03:48:09 +03:00
|
|
|
mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher,
|
2012-07-15 20:43:10 +04:00
|
|
|
listsubrepos=subrepos)[:3])
|
2015-09-10 03:48:09 +03:00
|
|
|
if do3way:
|
|
|
|
mod_b, add_b, rem_b = map(set,
|
|
|
|
repo.status(node1b, node2, matcher,
|
|
|
|
listsubrepos=subrepos)[:3])
|
|
|
|
else:
|
|
|
|
mod_b, add_b, rem_b = set(), set(), set()
|
|
|
|
modadd = mod_a | add_a | mod_b | add_b
|
|
|
|
common = modadd | rem_a | rem_b
|
|
|
|
if not common:
|
|
|
|
return 0
|
2006-05-22 10:39:07 +04:00
|
|
|
|
|
|
|
tmproot = tempfile.mkdtemp(prefix='extdiff.')
|
|
|
|
try:
|
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-10 04:07:38 +03:00
|
|
|
if not opts.get('patch'):
|
2015-09-10 03:48:09 +03:00
|
|
|
# Always make a copy of node1a (and node1b, if applicable)
|
|
|
|
dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a)
|
|
|
|
dir1a = snapshot(ui, repo, dir1a_files, node1a, tmproot,
|
2012-07-15 20:43:10 +04:00
|
|
|
subrepos)[0]
|
2015-09-10 03:48:09 +03:00
|
|
|
rev1a = '@%d' % repo[node1a].rev()
|
2009-09-17 23:12:32 +04:00
|
|
|
if do3way:
|
2015-09-10 03:48:09 +03:00
|
|
|
dir1b_files = mod_b | rem_b | ((mod_a | add_a) - add_b)
|
|
|
|
dir1b = snapshot(ui, repo, dir1b_files, node1b, tmproot,
|
|
|
|
subrepos)[0]
|
|
|
|
rev1b = '@%d' % repo[node1b].rev()
|
|
|
|
else:
|
|
|
|
dir1b = None
|
|
|
|
rev1b = ''
|
|
|
|
|
|
|
|
fns_and_mtime = []
|
|
|
|
|
|
|
|
# If node2 in not the wc or there is >1 change, copy it
|
|
|
|
dir2root = ''
|
|
|
|
rev2 = ''
|
|
|
|
if node2:
|
|
|
|
dir2 = snapshot(ui, repo, modadd, node2, tmproot, subrepos)[0]
|
|
|
|
rev2 = '@%d' % repo[node2].rev()
|
|
|
|
elif len(common) > 1:
|
|
|
|
#we only actually need to get the files to copy back to
|
|
|
|
#the working dir in this case (because the other cases
|
|
|
|
#are: diffing 2 revisions or single file -- in which case
|
|
|
|
#the file is already directly passed to the diff tool).
|
|
|
|
dir2, fns_and_mtime = snapshot(ui, repo, modadd, None, tmproot,
|
|
|
|
subrepos)
|
|
|
|
else:
|
|
|
|
# This lets the diff tool open the changed file directly
|
|
|
|
dir2 = ''
|
|
|
|
dir2root = repo.root
|
|
|
|
|
|
|
|
label1a = rev1a
|
|
|
|
label1b = rev1b
|
|
|
|
label2 = rev2
|
|
|
|
|
|
|
|
# If only one change, diff the files instead of the directories
|
|
|
|
# Handle bogus modifies correctly by checking if the files exist
|
|
|
|
if len(common) == 1:
|
|
|
|
common_file = util.localpath(common.pop())
|
|
|
|
dir1a = os.path.join(tmproot, dir1a, common_file)
|
|
|
|
label1a = common_file + rev1a
|
|
|
|
if not os.path.isfile(dir1a):
|
|
|
|
dir1a = os.devnull
|
|
|
|
if do3way:
|
|
|
|
dir1b = os.path.join(tmproot, dir1b, common_file)
|
|
|
|
label1b = common_file + rev1b
|
|
|
|
if not os.path.isfile(dir1b):
|
|
|
|
dir1b = os.devnull
|
|
|
|
dir2 = os.path.join(dir2root, dir2, common_file)
|
|
|
|
label2 = common_file + rev2
|
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-10 04:07:38 +03:00
|
|
|
else:
|
|
|
|
template = 'hg-%h.patch'
|
|
|
|
cmdutil.export(repo, [repo[node1a].rev(), repo[node2].rev()],
|
2015-09-10 05:27:48 +03:00
|
|
|
template=repo.vfs.reljoin(tmproot, template),
|
|
|
|
match=matcher)
|
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-10 04:07:38 +03:00
|
|
|
label1a = cmdutil.makefilename(repo, template, node1a)
|
|
|
|
label2 = cmdutil.makefilename(repo, template, node2)
|
|
|
|
dir1a = repo.vfs.reljoin(tmproot, label1a)
|
|
|
|
dir2 = repo.vfs.reljoin(tmproot, label2)
|
|
|
|
dir1b = None
|
|
|
|
label1b = None
|
|
|
|
fns_and_mtime = []
|
2009-09-17 23:12:32 +04:00
|
|
|
|
2009-11-27 01:10:59 +03:00
|
|
|
# Function to quote file/dir names in the argument string.
|
|
|
|
# When not operating in 3-way mode, an empty string is
|
|
|
|
# returned for parent2
|
2014-03-12 21:13:42 +04:00
|
|
|
replace = {'parent': dir1a, 'parent1': dir1a, 'parent2': dir1b,
|
|
|
|
'plabel1': label1a, 'plabel2': label1b,
|
|
|
|
'clabel': label2, 'child': dir2,
|
|
|
|
'root': repo.root}
|
2009-09-17 23:12:32 +04:00
|
|
|
def quote(match):
|
2015-01-28 04:28:39 +03:00
|
|
|
pre = match.group(2)
|
|
|
|
key = match.group(3)
|
2009-09-17 23:12:32 +04:00
|
|
|
if not do3way and key == 'parent2':
|
2015-01-28 04:28:39 +03:00
|
|
|
return pre
|
|
|
|
return pre + util.shellquote(replace[key])
|
2009-09-17 23:12:32 +04:00
|
|
|
|
|
|
|
# Match parent2 first, so 'parent1?' will match both parent1 and parent
|
2015-01-28 04:28:39 +03:00
|
|
|
regex = (r'''(['"]?)([^\s'"$]*)'''
|
|
|
|
r'\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)\1')
|
2014-12-25 17:33:26 +03:00
|
|
|
if not do3way and not re.search(regex, cmdline):
|
|
|
|
cmdline += ' $parent1 $child'
|
|
|
|
cmdline = re.sub(regex, quote, cmdline)
|
2009-09-17 23:12:32 +04:00
|
|
|
|
2009-09-19 03:15:38 +04:00
|
|
|
ui.debug('running %r in %s\n' % (cmdline, tmproot))
|
2014-11-08 07:06:22 +03:00
|
|
|
ui.system(cmdline, cwd=tmproot)
|
2007-08-27 04:31:18 +04:00
|
|
|
|
|
|
|
for copy_fn, working_fn, mtime in fns_and_mtime:
|
2011-04-29 10:04:46 +04:00
|
|
|
if os.lstat(copy_fn).st_mtime != mtime:
|
2009-09-19 03:15:38 +04:00
|
|
|
ui.debug('file changed while diffing. '
|
|
|
|
'Overwriting: %s (src: %s)\n' % (working_fn, copy_fn))
|
2007-08-27 04:31:18 +04:00
|
|
|
util.copyfile(copy_fn, working_fn)
|
|
|
|
|
2006-05-22 10:39:07 +04:00
|
|
|
return 1
|
|
|
|
finally:
|
|
|
|
ui.note(_('cleaning up temp directory\n'))
|
|
|
|
shutil.rmtree(tmproot)
|
|
|
|
|
2016-01-04 16:13:46 +03:00
|
|
|
extdiffopts = [
|
2014-05-05 08:54:01 +04:00
|
|
|
('o', 'option', [],
|
|
|
|
_('pass option to comparison program'), _('OPT')),
|
|
|
|
('r', 'rev', [], _('revision'), _('REV')),
|
|
|
|
('c', 'change', '', _('change made by revision'), _('REV')),
|
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-10 04:07:38 +03:00
|
|
|
('', 'patch', None, _('compare patches for two revisions'))
|
2016-01-04 16:13:46 +03:00
|
|
|
] + commands.walkopts + commands.subrepoopts
|
|
|
|
|
|
|
|
@command('extdiff',
|
|
|
|
[('p', 'program', '', _('comparison program to run'), _('CMD')),
|
|
|
|
] + extdiffopts,
|
2014-05-05 09:29:27 +04:00
|
|
|
_('hg extdiff [OPT]... [FILE]...'),
|
|
|
|
inferrepo=True)
|
2006-05-22 10:39:07 +04:00
|
|
|
def extdiff(ui, repo, *pats, **opts):
|
|
|
|
'''use external program to diff repository (or selected files)
|
|
|
|
|
2009-07-26 03:45:36 +04:00
|
|
|
Show differences between revisions for the specified files, using
|
|
|
|
an external program. The default program used is diff, with
|
|
|
|
default options "-Npru".
|
2006-08-15 02:51:35 +04:00
|
|
|
|
2009-07-26 03:45:36 +04:00
|
|
|
To select a different program, use the -p/--program option. The
|
|
|
|
program will be passed the names of two directories to compare. To
|
|
|
|
pass additional options to the program, use -o/--option. These
|
|
|
|
will be passed before the names of the directories to compare.
|
2006-05-22 10:39:07 +04:00
|
|
|
|
2009-07-26 03:45:36 +04:00
|
|
|
When two revision arguments are given, then changes are shown
|
|
|
|
between those revisions. If only one revision is specified then
|
|
|
|
that revision is compared to the working directory, and, when no
|
|
|
|
revisions are specified, the working directory files are compared
|
|
|
|
to its parent.'''
|
2009-10-01 10:50:10 +04:00
|
|
|
program = opts.get('program')
|
|
|
|
option = opts.get('option')
|
|
|
|
if not program:
|
|
|
|
program = 'diff'
|
|
|
|
option = option or ['-Npru']
|
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 17:33:26 +03:00
|
|
|
cmdline = ' '.join(map(util.shellquote, [program] + option))
|
|
|
|
return dodiff(ui, repo, cmdline, pats, opts)
|
2006-05-22 10:39:07 +04:00
|
|
|
|
2016-07-27 15:40:42 +03:00
|
|
|
class savedcmd(object):
|
2016-07-27 15:44:49 +03:00
|
|
|
"""use external program to diff repository (or selected files)
|
2016-07-27 15:40:42 +03:00
|
|
|
|
|
|
|
Show differences between revisions for the specified files, using
|
2016-07-27 15:44:49 +03:00
|
|
|
the following program::
|
|
|
|
|
|
|
|
%(path)s
|
2016-07-27 15:40:42 +03:00
|
|
|
|
|
|
|
When two revision arguments are given, then changes are shown
|
|
|
|
between those revisions. If only one revision is specified then
|
|
|
|
that revision is compared to the working directory, and, when no
|
|
|
|
revisions are specified, the working directory files are compared
|
|
|
|
to its parent.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, path, cmdline):
|
|
|
|
# We can't pass non-ASCII through docstrings (and path is
|
|
|
|
# in an unknown encoding anyway)
|
|
|
|
docpath = path.encode("string-escape")
|
|
|
|
self.__doc__ = self.__doc__ % {'path': util.uirepr(docpath)}
|
|
|
|
self._cmdline = cmdline
|
|
|
|
|
|
|
|
def __call__(self, ui, repo, *pats, **opts):
|
|
|
|
options = ' '.join(map(util.shellquote, opts['option']))
|
|
|
|
if options:
|
|
|
|
options = ' ' + options
|
|
|
|
return dodiff(ui, repo, self._cmdline + options, pats, opts)
|
|
|
|
|
2006-05-22 10:39:07 +04:00
|
|
|
def uisetup(ui):
|
|
|
|
for cmd, path in ui.configitems('extdiff'):
|
2015-02-28 01:35:07 +03:00
|
|
|
path = util.expandpath(path)
|
2007-08-25 23:25:53 +04:00
|
|
|
if cmd.startswith('cmd.'):
|
|
|
|
cmd = cmd[4:]
|
2010-01-25 09:05:27 +03:00
|
|
|
if not path:
|
2014-11-01 04:34:55 +03:00
|
|
|
path = util.findexe(cmd)
|
|
|
|
if path is None:
|
|
|
|
path = filemerge.findexternaltool(ui, cmd) or cmd
|
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 17:33:26 +03:00
|
|
|
diffopts = ui.config('extdiff', 'opts.' + cmd, '')
|
|
|
|
cmdline = util.shellquote(path)
|
|
|
|
if diffopts:
|
|
|
|
cmdline += ' ' + diffopts
|
2007-08-25 23:25:53 +04:00
|
|
|
elif cmd.startswith('opts.'):
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if path:
|
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 17:33:26 +03:00
|
|
|
# case "cmd = path opts"
|
|
|
|
cmdline = path
|
2016-12-25 00:36:55 +03:00
|
|
|
diffopts = len(pycompat.shlexsplit(cmdline)) > 1
|
2007-08-25 23:25:53 +04:00
|
|
|
else:
|
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 17:33:26 +03:00
|
|
|
# case "cmd ="
|
|
|
|
path = util.findexe(cmd)
|
2014-11-01 04:34:55 +03:00
|
|
|
if path is None:
|
|
|
|
path = filemerge.findexternaltool(ui, cmd) or cmd
|
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 17:33:26 +03:00
|
|
|
cmdline = util.shellquote(path)
|
|
|
|
diffopts = False
|
2010-01-08 07:19:05 +03:00
|
|
|
# look for diff arguments in [diff-tools] then [merge-tools]
|
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 17:33:26 +03:00
|
|
|
if not diffopts:
|
2010-01-08 07:19:05 +03:00
|
|
|
args = ui.config('diff-tools', cmd+'.diffargs') or \
|
|
|
|
ui.config('merge-tools', cmd+'.diffargs')
|
|
|
|
if args:
|
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 17:33:26 +03:00
|
|
|
cmdline += ' ' + args
|
2016-01-01 16:35:34 +03:00
|
|
|
command(cmd, extdiffopts[:], _('hg %s [OPTION]... [FILE]...') % cmd,
|
2016-07-27 15:40:42 +03:00
|
|
|
inferrepo=True)(savedcmd(path, cmdline))
|
2016-07-27 15:42:24 +03:00
|
|
|
|
|
|
|
# tell hggettext to extract docstrings from these functions:
|
|
|
|
i18nfunctions = [savedcmd]
|