annotate hgext/extdiff.py @ 5192:33015dac5df5

convert: fix mercurial_sink.putcommit Changeset 4ebc8693ce72 added some code to putcommit to avoid creating a revision that touches no files, but this can break regular conversions from some repositories: - conceptually, since we're converting a repo, we should try to make the new hg repo as similar as possible to the original repo - we should create a new changeset, even if the original revision didn't touch any files (maybe the commit message had some important bit); - even if a "regular" revision that doesn't touch any file may seem weird (and maybe even broken), it's completely legitimate for a merge revision to not touch any file, and, if we just skip it, the converted repo will end up with wrong history and possibly an extra head. As an example, say the crew and main hg repos are sync'ed. Somebody sends an important patch to the mailing list. Matt quickly applies and pushes it. But at the same time somebody also applies it to crew and pushes it. Suppose the commit message ended up being a bit different (say, there was a typo and somebody didn't fix it) or that the date ended up being different (because of different patch-applying scripts): the changeset hashes will be different, but the manifests will be the same. Since both changesets were pushed to public repos, it's hard to recall them. If both are merged, the manifest from the resulting merge revision will have the exact same contents as its parents - i.e. the merge revision really doesn't touch any file at all. To keep the file filtering stuff "working", the generic code was changed to skip empty revisions if we're filtering the repo, fixing a bug in the process (we want parents[0] instead of tip).
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Fri, 17 Aug 2007 20:18:05 -0300
parents c80af96943aa
children a1efa71f3ece
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
1 # extdiff.py - external diff program support for mercurial
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
2 #
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
4 #
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
6 # of the GNU General Public License, incorporated herein by reference.
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
7 #
2901
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
8 # The `extdiff' Mercurial extension allows you to use external programs
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
9 # to compare revisions, or revision with working dir. The external diff
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
10 # programs are called with a configurable set of options and two
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
11 # non-option arguments: paths to directories containing snapshots of
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
12 # files to compare.
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
13 #
2901
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
14 # To enable this extension:
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
15 #
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
16 # [extensions]
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
17 # hgext.extdiff =
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
18 #
2901
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
19 # The `extdiff' extension also allows to configure new diff commands, so
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
20 # you do not need to type "hg extdiff -p kdiff3" always.
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
21 #
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
22 # [extdiff]
2901
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
23 # # add new command that runs GNU diff(1) in 'context diff' mode
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
24 # cmd.cdiff = gdiff
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
25 # opts.cdiff = -Nprc5
3094
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3087
diff changeset
26
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
27 # # add new command called vdiff, runs kdiff3
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
28 # cmd.vdiff = kdiff3
3094
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3087
diff changeset
29
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
30 # # add new command called meld, runs meld (no need to name twice)
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
31 # cmd.meld =
3094
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3087
diff changeset
32
2675
d99a92b7acad extdiff : add comment on how to use vim for doing directoy diff
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2338
diff changeset
33 # # add new command called vimdiff, runs gvimdiff with DirDiff plugin
d99a92b7acad extdiff : add comment on how to use vim for doing directoy diff
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2338
diff changeset
34 # #(see http://www.vim.org/scripts/script.php?script_id=102)
3094
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3087
diff changeset
35 # # Non english user, be sure to put "let g:DirDiffDynamicDiffText = 1" in
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3087
diff changeset
36 # # your .vimrc
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3087
diff changeset
37 # cmd.vimdiff = gvim
8e8deb8035a4 Update [extdiff] configuration sample for vimdiff,
Mathieu Clabaut <mathieu.clabaut@systerel.fr>
parents: 3087
diff changeset
38 # opts.vimdiff = -f '+next' '+execute "DirDiff" argv(0) argv(1)'
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
39 #
2901
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
40 # Each custom diff commands can have two parts: a `cmd' and an `opts'
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
41 # part. The cmd.xxx option defines the name of an executable program
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
42 # that will be run, and opts.xxx defines a set of command-line options
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
43 # which will be inserted to the command between the program name and
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
44 # the files/directories to diff (i.e. the cdiff example above).
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
45 #
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
46 # You can use -I/-X and list of file or directory names like normal
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
47 # "hg diff" command. The `extdiff' extension makes snapshots of only
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
48 # needed files, so running the external diff program will actually be
05f357b70cb0 Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2891
diff changeset
49 # pretty fast (at least faster than having to compare the entire tree).
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
50
3893
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3886
diff changeset
51 from mercurial.i18n import _
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
52 from mercurial.node import *
5122
c80af96943aa refactor options from cmdtable
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5117
diff changeset
53 from mercurial import cmdutil, util, commands
3886
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3707
diff changeset
54 import os, shutil, tempfile
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
55
5108
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
56
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
57 def snapshot_node(ui, repo, files, node, tmproot):
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
58 '''snapshot files as of some revision'''
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
59 mf = repo.changectx(node).manifest()
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
60 dirname = os.path.basename(repo.root)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
61 if dirname == "":
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
62 dirname = "root"
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
63 dirname = '%s.%s' % (dirname, short(node))
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
64 base = os.path.join(tmproot, dirname)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
65 os.mkdir(base)
5109
841568ccc09d extdiff: made it less chatty in non-verbose mode
Brad Schick <schickb@gmail.com>
parents: 5108
diff changeset
66 ui.note(_('making snapshot of %d files from rev %s\n') %
5117
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5110
diff changeset
67 (len(files), short(node)))
5108
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
68 for fn in files:
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
69 if not fn in mf:
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
70 # skipping new file after a merge ?
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
71 continue
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
72 wfn = util.pconvert(fn)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
73 ui.note(' %s\n' % wfn)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
74 dest = os.path.join(base, wfn)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
75 destdir = os.path.dirname(dest)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
76 if not os.path.isdir(destdir):
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
77 os.makedirs(destdir)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
78 data = repo.wwritedata(wfn, repo.file(wfn).read(mf[wfn]))
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
79 open(dest, 'wb').write(data)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
80 return dirname
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
81
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
82
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
83 def snapshot_wdir(ui, repo, files, tmproot):
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
84 '''snapshot files from working directory.
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
85 if not using snapshot, -I/-X does not work and recursive diff
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
86 in tools like kdiff3 and meld displays too many files.'''
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
87 dirname = os.path.basename(repo.root)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
88 if dirname == "":
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
89 dirname = "root"
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
90 base = os.path.join(tmproot, dirname)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
91 os.mkdir(base)
5109
841568ccc09d extdiff: made it less chatty in non-verbose mode
Brad Schick <schickb@gmail.com>
parents: 5108
diff changeset
92 ui.note(_('making snapshot of %d files from working dir\n') %
5117
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5110
diff changeset
93 (len(files)))
5108
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
94 for fn in files:
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
95 wfn = util.pconvert(fn)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
96 ui.note(' %s\n' % wfn)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
97 dest = os.path.join(base, wfn)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
98 destdir = os.path.dirname(dest)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
99 if not os.path.isdir(destdir):
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
100 os.makedirs(destdir)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
101 fp = open(dest, 'wb')
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
102 for chunk in util.filechunkiter(repo.wopener(wfn)):
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
103 fp.write(chunk)
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
104 return dirname
5117
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5110
diff changeset
105
5108
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
106
2891
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
107 def dodiff(ui, repo, diffcmd, diffopts, pats, opts):
3707
67f44b825784 Removed unused ui parameter from revpair/revrange and fix its users.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
108 node1, node2 = cmdutil.revpair(repo, opts['rev'])
2887
2fe4d99ae726 Update extdiff for recent refactoring
Brendan Cully <brendan@kublai.com>
parents: 2874
diff changeset
109 files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
2874
3d6efcbbd1c9 remove localrepository.changes.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2675
diff changeset
110 modified, added, removed, deleted, unknown = repo.status(
3d6efcbbd1c9 remove localrepository.changes.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2675
diff changeset
111 node1, node2, files, match=matchfn)[:5]
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
112 if not (modified or added or removed):
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
113 return 0
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
114
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
115 tmproot = tempfile.mkdtemp(prefix='extdiff.')
5110
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
116 dir2root = ''
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
117 try:
5110
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
118 # Always make a copy of node1
5108
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
119 dir1 = snapshot_node(ui, repo, modified + removed, node1, tmproot)
5110
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
120 changes = len(modified) + len(removed) + len(added)
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
121
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
122 # If node2 in not the wc or there is >1 change, copy it
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
123 if node2:
5108
1830bc7676ee extdiff: un-nested two functions
Brad Schick <schickb@gmail.com>
parents: 4730
diff changeset
124 dir2 = snapshot_node(ui, repo, modified + added, node2, tmproot)
5110
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
125 elif changes > 1:
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
126 dir2 = snapshot_wdir(ui, repo, modified + added, tmproot)
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
127 else:
5110
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
128 # This lets the diff tool open the changed file directly
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
129 dir2 = ''
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
130 dir2root = repo.root
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
131
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
132 # If only one change, diff the files instead of the directories
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
133 if changes == 1 :
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
134 if len(modified):
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
135 dir1 = os.path.join(dir1, util.localpath(modified[0]))
5117
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5110
diff changeset
136 dir2 = os.path.join(dir2root, dir2, util.localpath(modified[0]))
5110
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
137 elif len(removed) :
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
138 dir1 = os.path.join(dir1, util.localpath(removed[0]))
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
139 dir2 = os.devnull
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
140 else:
2be225ea5722 extdiff: do single file diffs from the wc with no copy
Brad Schick <schickb@gmail.com>
parents: 5109
diff changeset
141 dir1 = os.devnull
5117
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5110
diff changeset
142 dir2 = os.path.join(dir2root, dir2, util.localpath(added[0]))
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5110
diff changeset
143
2891
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
144 cmdline = ('%s %s %s %s' %
3071
be98c5ce4022 extdiff: do not shell-quote options to new commands
TK Soh <teekaysoh@yahoo.com>
parents: 2959
diff changeset
145 (util.shellquote(diffcmd), ' '.join(diffopts),
2891
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
146 util.shellquote(dir1), util.shellquote(dir2)))
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
147 ui.debug('running %r in %s\n' % (cmdline, tmproot))
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
148 util.system(cmdline, cwd=tmproot)
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
149 return 1
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
150 finally:
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
151 ui.note(_('cleaning up temp directory\n'))
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
152 shutil.rmtree(tmproot)
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
153
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
154 def extdiff(ui, repo, *pats, **opts):
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
155 '''use external program to diff repository (or selected files)
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
156
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
157 Show differences between revisions for the specified files, using
2891
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
158 an external program. The default program used is diff, with
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
159 default options "-Npru".
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
160
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
161 To select a different program, use the -p option. The program
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
162 will be passed the names of two directories to compare. To pass
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
163 additional options to the program, use the -o option. These will
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
164 be passed before the names of the directories to compare.
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
165
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
166 When two revision arguments are given, then changes are
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
167 shown between those revisions. If only one revision is
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
168 specified then that revision is compared to the working
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
169 directory, and, when no revisions are specified, the
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
170 working directory files are compared to its parent.'''
3124
f145d04899d2 extdiff: use the default option only if the default program is used
TK Soh <teekaysoh@yahoo.com>
parents: 3094
diff changeset
171 program = opts['program'] or 'diff'
f145d04899d2 extdiff: use the default option only if the default program is used
TK Soh <teekaysoh@yahoo.com>
parents: 3094
diff changeset
172 if opts['program']:
f145d04899d2 extdiff: use the default option only if the default program is used
TK Soh <teekaysoh@yahoo.com>
parents: 3094
diff changeset
173 option = opts['option']
f145d04899d2 extdiff: use the default option only if the default program is used
TK Soh <teekaysoh@yahoo.com>
parents: 3094
diff changeset
174 else:
f145d04899d2 extdiff: use the default option only if the default program is used
TK Soh <teekaysoh@yahoo.com>
parents: 3094
diff changeset
175 option = opts['option'] or ['-Npru']
f145d04899d2 extdiff: use the default option only if the default program is used
TK Soh <teekaysoh@yahoo.com>
parents: 3094
diff changeset
176 return dodiff(ui, repo, program, option, pats, opts)
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
177
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
178 cmdtable = {
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
179 "extdiff":
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
180 (extdiff,
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
181 [('p', 'program', '', _('comparison program to run')),
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
182 ('o', 'option', [], _('pass option to comparison program')),
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
183 ('r', 'rev', [], _('revision')),
5122
c80af96943aa refactor options from cmdtable
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5117
diff changeset
184 ] + commands.walkopts,
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
185 _('hg extdiff [OPT]... [FILE]...')),
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
186 }
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
187
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
188 def uisetup(ui):
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
189 for cmd, path in ui.configitems('extdiff'):
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
190 if not cmd.startswith('cmd.'): continue
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
191 cmd = cmd[4:]
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
192 if not path: path = cmd
2891
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
193 diffopts = ui.config('extdiff', 'opts.' + cmd, '')
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
194 diffopts = diffopts and [diffopts] or []
2959
7f5fc4b347de extdiff: make new diff commands pick up their options correctly
TK Soh <teekaysoh@yahoo.com>
parents: 2901
diff changeset
195 def save(cmd, path, diffopts):
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
196 '''use closure to save diff command to use'''
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
197 def mydiff(ui, repo, *pats, **opts):
2891
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
198 return dodiff(ui, repo, path, diffopts, pats, opts)
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
199 mydiff.__doc__ = '''use %(path)r to diff repository (or selected files)
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
200
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
201 Show differences between revisions for the specified
2891
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
202 files, using the %(path)r program.
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
203
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
204 When two revision arguments are given, then changes are
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
205 shown between those revisions. If only one revision is
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
206 specified then that revision is compared to the working
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
207 directory, and, when no revisions are specified, the
2891
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
208 working directory files are compared to its parent.''' % {
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
209 'path': path,
453097750fbf extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2888
diff changeset
210 }
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
211 return mydiff
2959
7f5fc4b347de extdiff: make new diff commands pick up their options correctly
TK Soh <teekaysoh@yahoo.com>
parents: 2901
diff changeset
212 cmdtable[cmd] = (save(cmd, path, diffopts),
2333
de0c05afa511 new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
213 cmdtable['extdiff'][1][1:],
4730
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4096
diff changeset
214 _('hg %s [OPTION]... [FILE]...') % cmd)