# HG changeset patch # User Stephen Darnell # Date 2006-09-25 23:05:24 # Node ID 096f1c73cdc333779ec21e32482a5323da6d446f # Parent a32f65549b9e3f1d50bbfd10c856914f9a3c6e11 Add -D/--nodates options to hg diff/export that removes dates from diff headers and replace uses of sed in the tests with --nodates. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2852,6 +2852,7 @@ table = { ('p', 'show-function', None, _('show which function each change is in')), ('g', 'git', None, _('use git extended diff format')), + ('D', 'nodates', None, _("don't include dates in diff headers")), ('w', 'ignore-all-space', None, _('ignore white space when comparing lines')), ('b', 'ignore-space-change', None, @@ -2865,6 +2866,7 @@ table = { [('o', 'output', '', _('print output to file with formatted name')), ('a', 'text', None, _('treat all files as text')), ('g', 'git', None, _('use git extended diff format')), + ('D', 'nodates', None, _("don't include dates in diff headers")), ('', 'switch-parent', None, _('diff against the second parent'))], _('hg export [-a] [-o OUTFILESPEC] REV...')), "debugforget|forget": diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -24,6 +24,7 @@ class diffopts(object): text treats all files as text showfunc enables diff -p output git enables the git extended patch format + nodates removes dates from diff headers ignorews ignores all whitespace changes in the diff ignorewsamount ignores changes in the amount of whitespace ignoreblanklines ignores changes whose lines are all blank''' @@ -33,6 +34,7 @@ class diffopts(object): 'text': False, 'showfunc': True, 'git': False, + 'nodates': False, 'ignorews': False, 'ignorewsamount': False, 'ignoreblanklines': False, @@ -51,7 +53,7 @@ defaultopts = diffopts() def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts): def datetag(date): - return opts.git and '\n' or '\t%s\n' % date + return (opts.git or opts.nodates) and '\n' or '\t%s\n' % date if not a and not b: return "" epoch = util.datestr((0, 0)) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -291,6 +291,8 @@ def diffopts(ui, opts={}): text=opts.get('text'), git=(opts.get('git') or ui.configbool('diff', 'git', None)), + nodates=(opts.get('nodates') or + ui.configbool('diff', 'nodates', None)), showfunc=(opts.get('show_function') or ui.configbool('diff', 'showfunc', None)), ignorews=(opts.get('ignore_all_space') or diff --git a/tests/README b/tests/README --- a/tests/README +++ b/tests/README @@ -26,11 +26,9 @@ writing tests: use commit -m "test" -u test -d "1000000 0" -- diff will show the current time +- diff and export may show the current time - use hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" - to strip dates + use -D/--nodates to strip the dates - You can append your own hgrc settings to the file that the environment variable HGRCPATH points to. This file is cleared before running a test. diff --git a/tests/test-diff-ignore-whitespace b/tests/test-diff-ignore-whitespace --- a/tests/test-diff-ignore-whitespace +++ b/tests/test-diff-ignore-whitespace @@ -3,8 +3,7 @@ # GNU diff is the reference for all of these results. hgdiff() { - hg diff "$@" | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" + hg diff --nodates "$@" } test_added_blank_lines() { diff --git a/tests/test-diff-subdir b/tests/test-diff-subdir --- a/tests/test-diff-subdir +++ b/tests/test-diff-subdir @@ -14,14 +14,11 @@ echo 1 > alpha/one echo 2 > beta/two echo EVERYTHING -hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates echo BETA ONLY -hg diff beta | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates beta echo INSIDE BETA cd beta -hg diff . | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates . diff --git a/tests/test-diffdir b/tests/test-diffdir --- a/tests/test-diffdir +++ b/tests/test-diffdir @@ -7,12 +7,9 @@ hg ci -m "a" -d "1000000 0" echo 123 > b hg add b -hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates -hg diff -r tip | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates -r tip echo foo > a -hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates diff --git a/tests/test-git-export b/tests/test-git-export --- a/tests/test-git-export +++ b/tests/test-git-export @@ -8,26 +8,22 @@ hg ci -Amstart -d '0 0' echo new > new hg ci -Amnew -d '0 0' echo '% new file' -hg diff --git -r 0 | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --git -r 0 hg cp new copy hg ci -mcopy -d '0 0' echo '% copy' -hg diff --git -r 1:tip | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --git -r 1:tip hg mv copy rename hg ci -mrename -d '0 0' echo '% rename' -hg diff --git -r 2:tip | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --git -r 2:tip hg rm rename hg ci -mdelete -d '0 0' echo '% delete' -hg diff --git -r 3:tip | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --git -r 3:tip cat > src <> dst hg ci -mrenamemod -d '0 0' echo '% rename+mod+chmod' -hg diff --git -r 6:tip | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --git -r 6:tip echo '% nonexistent in tip+chmod' -hg diff --git -r 5:6 | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --git -r 5:6 diff --git a/tests/test-help.out b/tests/test-help.out --- a/tests/test-help.out +++ b/tests/test-help.out @@ -179,6 +179,7 @@ options: -a --text treat all files as text -p --show-function show which function each change is in -g --git use git extended diff format + -D --nodates don't include dates in diff headers -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-merge-revert2 b/tests/test-merge-revert2 --- a/tests/test-merge-revert2 +++ b/tests/test-merge-revert2 @@ -27,8 +27,8 @@ hg id hg update -C 0 echo "changed file1 different" >> file1 HGMERGE=merge hg update -hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" -e "s/\(<<<<<<<\) .*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" -e "s/\(>>>>>>>\) .*/\1/" +#hg diff --nodates | sed -e "s/\(<<<<<<<\) .*/\1/" -e "s/\(>>>>>>>\) .*/\1/" +hg diff --nodates | sed -e "s/\(<<<<<<<\|>>>>>>>\) .*/\1/" hg status hg id hg revert --no-backup --all diff --git a/tests/test-remove b/tests/test-remove --- a/tests/test-remove +++ b/tests/test-remove @@ -13,8 +13,8 @@ hg revert --all rm foo hg remove --after hg commit -m 2 -d "1000000 0" -hg export 0 -hg export 1 +hg export --nodates 0 +hg export --nodates 1 hg log -p -r 0 hg log -p -r 1 diff --git a/tests/test-remove.out b/tests/test-remove.out --- a/tests/test-remove.out +++ b/tests/test-remove.out @@ -10,8 +10,8 @@ removing foo 1 diff -r 000000000000 -r 8ba83d44753d foo ---- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/foo Mon Jan 12 13:46:40 1970 +0000 +--- /dev/null ++++ b/foo @@ -0,0 +1,1 @@ +a # HG changeset patch @@ -22,8 +22,8 @@ diff -r 000000000000 -r 8ba83d44753d foo 2 diff -r 8ba83d44753d -r a1fce69c50d9 foo ---- a/foo Mon Jan 12 13:46:40 1970 +0000 -+++ /dev/null Thu Jan 01 00:00:00 1970 +0000 +--- a/foo ++++ /dev/null @@ -1,1 +0,0 @@ -a changeset: 0:8ba83d44753d diff --git a/tests/test-up-local-change b/tests/test-up-local-change --- a/tests/test-up-local-change +++ b/tests/test-up-local-change @@ -12,8 +12,7 @@ hg clone . ../r2 cd ../r2 hg up echo abc > a -hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates cd ../r1 echo b > b @@ -34,8 +33,7 @@ hg parents hg --debug up hg parents hg -v history -hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates # create a second head cd ../r1 @@ -53,8 +51,7 @@ hg --debug up || echo failed hg --debug merge || echo failed hg --debug merge -f hg parents -hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ - -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" +hg diff --nodates # test a local add cd ..