# HG changeset patch # User Vadim Gelfer # Date 1155750384 25200 # Node ID ef8ee4477019da03a39add4be5a471b3b7263600 # Parent b70740aefa4df12bd0c86d7093c39c139171ba82# Parent 8743188f4d2ed4ef5f2329ff0eaf3d30f6802b7c merge with mpm. diff --git a/hgext/extdiff.py b/hgext/extdiff.py --- a/hgext/extdiff.py +++ b/hgext/extdiff.py @@ -5,19 +5,24 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. # -# allow to use external programs to compare revisions, or revision -# with working dir. program is called with two arguments: paths to -# directories containing snapshots of files to compare. +# The `extdiff' Mercurial extension allows you to use external programs +# to compare revisions, or revision with working dir. 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. # -# to enable: +# To enable this extension: # # [extensions] # hgext.extdiff = # -# also allows to configure new diff commands, so you do not need to -# type "hg extdiff -p kdiff3" always. +# The `extdiff' extension also allows to configure new diff commands, so +# you do not need to type "hg extdiff -p kdiff3" always. # # [extdiff] +# # add new command that runs GNU diff(1) in 'context diff' mode +# cmd.cdiff = gdiff +# opts.cdiff = -Nprc5 # # add new command called vdiff, runs kdiff3 # cmd.vdiff = kdiff3 # # add new command called meld, runs meld (no need to name twice) @@ -26,16 +31,23 @@ # #(see http://www.vim.org/scripts/script.php?script_id=102) # cmd.vimdiff = LC_ALL=C gvim -f '+bdel 1 2' '+ execute "DirDiff ".argv(0)." ".argv(1)' # -# you can use -I/-X and list of file or directory names like normal -# "hg diff" command. extdiff makes snapshots of only needed files, so -# compare program will be fast. +# Each custom diff commands can have two parts: a `cmd' and an `opts' +# part. The cmd.xxx option defines the name of an executable program +# that will be run, and opts.xxx defines a set of command-line options +# which will be inserted to the command between the program name and +# the files/directories to diff (i.e. the cdiff example above). +# +# 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). from mercurial.demandload import demandload from mercurial.i18n import gettext as _ from mercurial.node import * -demandload(globals(), 'mercurial:commands,util os shutil tempfile') +demandload(globals(), 'mercurial:commands,cmdutil,util os shutil tempfile') -def dodiff(ui, repo, diffcmd, pats, opts): +def dodiff(ui, repo, diffcmd, diffopts, pats, opts): def snapshot_node(files, node): '''snapshot files as of some revision''' changes = repo.changelog.read(node) @@ -79,7 +91,7 @@ def dodiff(ui, repo, diffcmd, pats, opts return dirname node1, node2 = commands.revpair(ui, repo, opts['rev']) - files, matchfn, anypats = commands.matchpats(repo, pats, opts) + files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) modified, added, removed, deleted, unknown = repo.status( node1, node2, files, match=matchfn)[:5] if not (modified or added or removed): @@ -92,9 +104,12 @@ def dodiff(ui, repo, diffcmd, pats, opts dir2 = snapshot_node(modified + added, node2) else: dir2 = snapshot_wdir(modified + added) - util.system('%s %s "%s" "%s"' % - (diffcmd, ' '.join(opts['option']), dir1, dir2), - cwd=tmproot) + cmdline = ('%s %s %s %s' % + (util.shellquote(diffcmd), + ' '.join(map(util.shellquote, diffopts)), + util.shellquote(dir1), util.shellquote(dir2))) + ui.debug('running %r in %s\n' % (cmdline, tmproot)) + util.system(cmdline, cwd=tmproot) return 1 finally: ui.note(_('cleaning up temp directory\n')) @@ -104,7 +119,9 @@ def extdiff(ui, repo, *pats, **opts): '''use external program to diff repository (or selected files) Show differences between revisions for the specified files, using - an external program. The default program used is "diff -Npru". + an external program. The default program used is diff, with + default options "-Npru". + To select a different program, use the -p option. The program will be passed the names of two directories to compare. To pass additional options to the program, use the -o option. These will @@ -115,7 +132,8 @@ def extdiff(ui, repo, *pats, **opts): 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.''' - return dodiff(ui, repo, opts['program'] or 'diff -Npru', pats, opts) + return dodiff(ui, repo, opts['program'] or 'diff', + opts['option'] or ['-Npru'], pats, opts) cmdtable = { "extdiff": @@ -133,20 +151,24 @@ def uisetup(ui): if not cmd.startswith('cmd.'): continue cmd = cmd[4:] if not path: path = cmd + diffopts = ui.config('extdiff', 'opts.' + cmd, '') + diffopts = diffopts and [diffopts] or [] def save(cmd, path): '''use closure to save diff command to use''' def mydiff(ui, repo, *pats, **opts): - return dodiff(ui, repo, path, pats, opts) - mydiff.__doc__ = '''use %s to diff repository (or selected files) + return dodiff(ui, repo, path, diffopts, pats, opts) + mydiff.__doc__ = '''use %(path)r to diff repository (or selected files) Show differences between revisions for the specified - files, using the %s program. + files, using the %(path)r program. 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.''' % (cmd, cmd) + working directory files are compared to its parent.''' % { + 'path': path, + } return mydiff cmdtable[cmd] = (save(cmd, path), cmdtable['extdiff'][1][1:], diff --git a/hgext/hgk.py b/hgext/hgk.py --- a/hgext/hgk.py +++ b/hgext/hgk.py @@ -5,8 +5,9 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import time, sys, signal, os -from mercurial import hg, mdiff, fancyopts, commands, ui, util +from mercurial.demandload import * +demandload(globals(), 'time sys signal os') +demandload(globals(), 'mercurial:hg,mdiff,fancyopts,commands,ui,util') def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, changes=None, text=False): diff --git a/hgext/mq.py b/hgext/mq.py diff --git a/mercurial/commands.py b/mercurial/commands.py diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -23,6 +23,7 @@ class diffopts(object): '''context is the number of context lines text treats all files as text showfunc enables diff -p output + git enables the git extended patch format ignorews ignores all whitespace changes in the diff ignorewsamount ignores changes in the amount of whitespace ignoreblanklines ignores changes whose lines are all blank''' @@ -31,6 +32,7 @@ class diffopts(object): 'context': 3, 'text': False, 'showfunc': True, + 'git': False, 'ignorews': False, 'ignorewsamount': False, 'ignoreblanklines': False, diff --git a/mercurial/patch.py b/mercurial/patch.py diff --git a/mercurial/ui.py b/mercurial/ui.py diff --git a/tests/test-extdiff b/tests/test-extdiff new file mode 100755 --- /dev/null +++ b/tests/test-extdiff @@ -0,0 +1,26 @@ +#!/bin/sh + +HGRCPATH=$HGTMP/.hgrc; export HGRCPATH +echo "[extensions]" >> $HGTMP/.hgrc +echo "extdiff=" >> $HGTMP/.hgrc + +hg init a +cd a +echo a > a +hg add +hg extdiff -o -Nr + +echo "[extdiff]" >> $HGTMP/.hgrc +echo "cmd.falabala=echo" >> $HGTMP/.hgrc +echo "opts.falabala=diffing" >> $HGTMP/.hgrc + +hg falabala + +hg help falabala + +hg ci -d '0 0' -mtest1 + +echo b >> a +hg ci -d '1 0' -mtest2 + +hg falabala -r 0:1 || echo "diff-like tools yield a non-zero exit code" diff --git a/tests/test-extdiff.out b/tests/test-extdiff.out new file mode 100644 --- /dev/null +++ b/tests/test-extdiff.out @@ -0,0 +1,32 @@ +adding a +making snapshot of 0 files from rev 000000000000 +making snapshot of 1 files from working dir +diff -Nr a.000000000000/a a/a +0a1 +> a +making snapshot of 0 files from rev 000000000000 +making snapshot of 1 files from working dir +diffing a.000000000000 a +hg falabala [OPT]... [FILE]... + +use 'echo' to diff repository (or selected files) + + Show differences between revisions for the specified + files, using the 'echo' program. + + 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. + +options: + + -o --option pass option to comparison program + -r --rev revision + -I --include include names matching the given patterns + -X --exclude exclude names matching the given patterns +making snapshot of 1 files from rev e27a2475d60a +making snapshot of 1 files from rev 5e49ec8d3f05 +diffing a.e27a2475d60a a.5e49ec8d3f05 +diff-like tools yield a non-zero exit code diff --git a/tests/test-git-export b/tests/test-git-export new file mode 100755 --- /dev/null +++ b/tests/test-git-export @@ -0,0 +1,46 @@ +#!/bin/sh + +hg init a +cd a + +echo start > start +hg ci -Amstart -d '0 0' +echo new > new +hg ci -Amnew -d '0 0' +echo '% new file' +hg diff --git -r 0 | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" + +hg cp new copy +hg ci -mcopy -d '0 0' +echo '% copy' +hg diff --git -r 1:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" + +hg mv copy rename +hg ci -mrename -d '0 0' +echo '% rename' +hg diff --git -r 2:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" + +hg rm rename +hg ci -mdelete -d '0 0' +echo '% delete' +hg diff --git -r 3:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" + +cat > src <> dst +hg ci -mrenamemod -d '0 0' +echo '% rename+mod+chmod' +hg diff --git -r 6:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" diff --git a/tests/test-git-export.out b/tests/test-git-export.out new file mode 100644 --- /dev/null +++ b/tests/test-git-export.out @@ -0,0 +1,42 @@ +adding start +adding new +% new file +diff --git a/new b/new +new file mode 100644 +--- /dev/null ++++ b/new +@@ -0,0 +1,1 @@ ++new +% copy +diff --git a/new b/copy +copy from new +copy to copy +% rename +diff --git a/copy b/rename +rename from copy +rename to rename +% delete +diff --git a/rename b/rename +deleted file mode 100644 +--- a/rename ++++ /dev/null +@@ -1,1 +0,0 @@ +-new +adding src +% chmod 644 +diff --git a/src b/src +old mode 100644 +new mode 100755 +% rename+mod+chmod +diff --git a/src b/dst +old mode 100755 +new mode 100644 +rename from src +rename to dst +--- a/dst ++++ b/dst +@@ -3,3 +3,4 @@ 3 + 3 + 4 + 5 ++a diff --git a/tests/test-git-import.out b/tests/test-git-import.out --- a/tests/test-git-import.out +++ b/tests/test-git-import.out @@ -1,6 +1,5 @@ % new file applying patch from stdin -patching file new % chmod +x applying patch from stdin % copy @@ -14,15 +13,12 @@ new rename % delete applying patch from stdin -patching file copyx new rename % regular diff applying patch from stdin -patching file rename % copy and modify applying patch from stdin -patching file copy2 a a b @@ -30,7 +26,6 @@ a a % rename and modify applying patch from stdin -patching file rename2 copy2: No such file or directory a a diff --git a/tests/test-help.out b/tests/test-help.out --- a/tests/test-help.out +++ b/tests/test-help.out @@ -176,6 +176,7 @@ options: -r --rev revision -a --text treat all files as text -p --show-function show which function each change is in + -g --git use git extended diff format -w --ignore-all-space ignore white space when comparing lines -b --ignore-space-change ignore changes in the amount of white space -B --ignore-blank-lines ignore changes whose lines are all blank diff --git a/tests/test-import.out b/tests/test-import.out --- a/tests/test-import.out +++ b/tests/test-import.out @@ -8,7 +8,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../tip.patch -patching file a % message should be same summary: second change % committer should be same @@ -21,7 +20,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../tip.patch -patching file a transaction abort! rollback completed % import of plain diff should be ok with message @@ -32,7 +30,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../tip.patch -patching file a % import from stdin requesting all changes adding changesets @@ -41,7 +38,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a % override commit message requesting all changes adding changesets @@ -50,7 +46,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a summary: override % plain diff in email, subject, message body requesting all changes @@ -60,7 +55,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../msg.patch -patching file a user: email patcher summary: email patch % plain diff in email, no subject, message body @@ -71,7 +65,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a % plain diff in email, subject, no message body requesting all changes adding changesets @@ -80,7 +73,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a % plain diff in email, no subject, no message body, should fail requesting all changes adding changesets @@ -89,7 +81,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a transaction abort! rollback completed % hg export in email, should use patch header @@ -100,7 +91,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a summary: second change % hg import in a subdirectory requesting all changes @@ -110,7 +100,6 @@ adding file changes added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../../../tip.patch -patching file a % message should be 'subdir change' summary: subdir change % committer should be 'someoneelse' diff --git a/tests/test-log b/tests/test-log --- a/tests/test-log +++ b/tests/test-log @@ -63,3 +63,6 @@ hg ci -Amb1.1 -d'1 0' echo % log --follow-first hg log --follow-first + +echo % log -P 2 +hg log -P 2 diff --git a/tests/test-log.out b/tests/test-log.out --- a/tests/test-log.out +++ b/tests/test-log.out @@ -149,3 +149,29 @@ user: test date: Thu Jan 01 00:00:01 1970 +0000 summary: base +% log -P 2 +changeset: 6:2404bbcab562 +tag: tip +user: test +date: Thu Jan 01 00:00:01 1970 +0000 +summary: b1.1 + +changeset: 5:302e9dd6890d +parent: 3:e62f78d544b4 +parent: 4:ddb82e70d1a1 +user: test +date: Thu Jan 01 00:00:01 1970 +0000 +summary: m12 + +changeset: 4:ddb82e70d1a1 +parent: 0:67e992f2c4f3 +user: test +date: Thu Jan 01 00:00:01 1970 +0000 +summary: b2 + +changeset: 3:e62f78d544b4 +parent: 1:3d5bf5654eda +user: test +date: Thu Jan 01 00:00:01 1970 +0000 +summary: b1 + diff --git a/tests/test-merge-default b/tests/test-merge-default new file mode 100755 --- /dev/null +++ b/tests/test-merge-default @@ -0,0 +1,40 @@ +#!/bin/sh + +hg init +echo a > a +hg commit -A -ma + +echo a >> a +hg commit -mb + +echo a >> a +hg commit -mc + +hg up 1 +echo a >> a +hg commit -md + +hg up 1 +echo a >> a +hg commit -me + +hg up 1 +echo % should fail because not at a head +hg merge + +hg up +echo % should fail because \> 2 heads +hg merge + +echo % should succeed +hg merge 2 +hg commit -mm1 + +echo % should succeed - 2 heads +hg merge +hg commit -mm2 + +echo % should fail because 1 head +hg merge + +true diff --git a/tests/test-merge-default.out b/tests/test-merge-default.out new file mode 100644 --- /dev/null +++ b/tests/test-merge-default.out @@ -0,0 +1,17 @@ +adding a +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +% should fail because not at a head +abort: repo has 3 heads - please merge with an explicit rev +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +% should fail because > 2 heads +abort: repo has 3 heads - please merge with an explicit rev +% should succeed +0 files updated, 0 files merged, 0 files removed, 0 files unresolved +(branch merge, don't forget to commit) +% should succeed - 2 heads +0 files updated, 0 files merged, 0 files removed, 0 files unresolved +(branch merge, don't forget to commit) +% should fail because 1 head +abort: there is nothing to merge - use "hg update" instead diff --git a/tests/test-mq-qdiff b/tests/test-mq-qdiff new file mode 100755 --- /dev/null +++ b/tests/test-mq-qdiff @@ -0,0 +1,28 @@ +#!/bin/sh + +HGRCPATH=$HGTMP/.hgrc; export HGRCPATH +echo "[extensions]" >> $HGTMP/.hgrc +echo "mq=" >> $HGTMP/.hgrc + +echo % init +hg init a +cd a + +echo % commit +echo 'base' > base +hg ci -Ambase -d '1 0' + +echo % qnew mqbase +hg qnew -mmqbase mqbase + +echo % qrefresh +echo 'patched' > base +hg qrefresh + +echo % qdiff +hg qdiff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ + -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" + +echo % qdiff dirname +hg qdiff . | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ + -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" diff --git a/tests/test-mq-qdiff.out b/tests/test-mq-qdiff.out new file mode 100644 --- /dev/null +++ b/tests/test-mq-qdiff.out @@ -0,0 +1,19 @@ +% init +% commit +adding base +% qnew mqbase +% qrefresh +% qdiff +diff -r 67e992f2c4f3 base +--- a/base ++++ b/base +@@ -1,1 +1,1 @@ base +-base ++patched +% qdiff dirname +diff -r 67e992f2c4f3 base +--- a/base ++++ b/base +@@ -1,1 +1,1 @@ base +-base ++patched diff --git a/tests/test-mq.out b/tests/test-mq.out --- a/tests/test-mq.out +++ b/tests/test-mq.out @@ -27,7 +27,7 @@ list of commands (use "hg help -v mq" to qapplied print the patches already applied qclone clone main and patch repository at same time qcommit commit changes in the queue repository - qdelete remove a patch from the series file + qdelete remove patches from queue qdiff diff of the current patch qfold fold the named patches into the current patch qguard set or print guards for a patch diff --git a/tests/test-up-local-change.out b/tests/test-up-local-change.out --- a/tests/test-up-local-change.out +++ b/tests/test-up-local-change.out @@ -43,7 +43,7 @@ user: test date: Mon Jan 12 13:46:40 1970 +0000 summary: 1 -abort: there is nothing to merge, just use 'hg update' or look at 'hg heads' +abort: there is nothing to merge - use "hg update" instead failed changeset: 0:33aaa84a386b user: test