Mercurial > hg
annotate hgext/extdiff.py @ 2959:7f5fc4b347de
extdiff: make new diff commands pick up their options correctly
author | TK Soh <teekaysoh@yahoo.com> |
---|---|
date | Thu, 17 Aug 2006 15:30:45 -0500 |
parents | 05f357b70cb0 |
children | be98c5ce4022 |
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 # |
2913
05f357b70cb0
Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2906
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:
2906
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:
2906
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:
2906
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:
2906
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 # |
2913
05f357b70cb0
Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2906
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 # |
2913
05f357b70cb0
Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2906
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:
2906
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] |
2913
05f357b70cb0
Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2906
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:
2906
diff
changeset
|
24 # cmd.cdiff = gdiff |
05f357b70cb0
Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2906
diff
changeset
|
25 # opts.cdiff = -Nprc5 |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
26 # # 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
|
27 # cmd.vdiff = kdiff3 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
28 # # 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
|
29 # cmd.meld = |
2675
d99a92b7acad
extdiff : add comment on how to use vim for doing directoy diff
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
2338
diff
changeset
|
30 # # 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
|
31 # #(see http://www.vim.org/scripts/script.php?script_id=102) |
d99a92b7acad
extdiff : add comment on how to use vim for doing directoy diff
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
2338
diff
changeset
|
32 # cmd.vimdiff = LC_ALL=C gvim -f '+bdel 1 2' '+ 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
|
33 # |
2913
05f357b70cb0
Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2906
diff
changeset
|
34 # 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:
2906
diff
changeset
|
35 # 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:
2906
diff
changeset
|
36 # 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:
2906
diff
changeset
|
37 # 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:
2906
diff
changeset
|
38 # 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:
2906
diff
changeset
|
39 # |
05f357b70cb0
Tune a bit the extdiff toplevel comments/samples.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2906
diff
changeset
|
40 # 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:
2906
diff
changeset
|
41 # "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:
2906
diff
changeset
|
42 # 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:
2906
diff
changeset
|
43 # 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
|
44 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
45 from mercurial.demandload import demandload |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
46 from mercurial.i18n import gettext as _ |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
47 from mercurial.node import * |
2902
2fe4d99ae726
Update extdiff for recent refactoring
Brendan Cully <brendan@kublai.com>
parents:
2875
diff
changeset
|
48 demandload(globals(), 'mercurial:commands,cmdutil,util os shutil tempfile') |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
49 |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
50 def dodiff(ui, repo, diffcmd, diffopts, pats, opts): |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
51 def snapshot_node(files, node): |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
52 '''snapshot files as of some revision''' |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
53 changes = repo.changelog.read(node) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
54 mf = repo.manifest.read(changes[0]) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
55 dirname = '%s.%s' % (os.path.basename(repo.root), short(node)) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
56 base = os.path.join(tmproot, dirname) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
57 os.mkdir(base) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
58 if not ui.quiet: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
59 ui.write_err(_('making snapshot of %d files from rev %s\n') % |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
60 (len(files), short(node))) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
61 for fn in files: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
62 wfn = util.pconvert(fn) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
63 ui.note(' %s\n' % wfn) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
64 dest = os.path.join(base, wfn) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
65 destdir = os.path.dirname(dest) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
66 if not os.path.isdir(destdir): |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
67 os.makedirs(destdir) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
68 repo.wwrite(wfn, repo.file(fn).read(mf[fn]), open(dest, 'w')) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
69 return dirname |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
70 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
71 def snapshot_wdir(files): |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
72 '''snapshot files from working directory. |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
73 if not using snapshot, -I/-X does not work and recursive diff |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
74 in tools like kdiff3 and meld displays too many files.''' |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
75 dirname = os.path.basename(repo.root) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
76 base = os.path.join(tmproot, dirname) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
77 os.mkdir(base) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
78 if not ui.quiet: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
79 ui.write_err(_('making snapshot of %d files from working dir\n') % |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
80 (len(files))) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
81 for fn in files: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
82 wfn = util.pconvert(fn) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
83 ui.note(' %s\n' % wfn) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
84 dest = os.path.join(base, wfn) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
85 destdir = os.path.dirname(dest) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
86 if not os.path.isdir(destdir): |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
87 os.makedirs(destdir) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
88 fp = open(dest, 'w') |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
89 for chunk in util.filechunkiter(repo.wopener(wfn)): |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
90 fp.write(chunk) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
91 return dirname |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
92 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
93 node1, node2 = commands.revpair(ui, repo, opts['rev']) |
2902
2fe4d99ae726
Update extdiff for recent refactoring
Brendan Cully <brendan@kublai.com>
parents:
2875
diff
changeset
|
94 files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
2875
3d6efcbbd1c9
remove localrepository.changes.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2675
diff
changeset
|
95 modified, added, removed, deleted, unknown = repo.status( |
3d6efcbbd1c9
remove localrepository.changes.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2675
diff
changeset
|
96 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
|
97 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
|
98 return 0 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
99 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
100 tmproot = tempfile.mkdtemp(prefix='extdiff.') |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
101 try: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
102 dir1 = snapshot_node(modified + removed, node1) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
103 if node2: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
104 dir2 = snapshot_node(modified + added, node2) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
105 else: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
106 dir2 = snapshot_wdir(modified + added) |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
107 cmdline = ('%s %s %s %s' % |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
108 (util.shellquote(diffcmd), |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
109 ' '.join(map(util.shellquote, diffopts)), |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
110 util.shellquote(dir1), util.shellquote(dir2))) |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
111 ui.debug('running %r in %s\n' % (cmdline, tmproot)) |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
112 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
|
113 return 1 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
114 finally: |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
115 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
|
116 shutil.rmtree(tmproot) |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
117 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
118 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
|
119 '''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
|
120 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
121 Show differences between revisions for the specified files, using |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
122 an external program. The default program used is diff, with |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
123 default options "-Npru". |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
124 |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 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
|
129 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 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
|
134 working directory files are compared to its parent.''' |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
135 return dodiff(ui, repo, opts['program'] or 'diff', |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
136 opts['option'] or ['-Npru'], pats, opts) |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
137 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
138 cmdtable = { |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
139 "extdiff": |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
140 (extdiff, |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
141 [('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
|
142 ('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
|
143 ('r', 'rev', [], _('revision')), |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
144 ('I', 'include', [], _('include names matching the given patterns')), |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
145 ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
146 _('hg extdiff [OPT]... [FILE]...')), |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
147 } |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
148 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
149 def uisetup(ui): |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
150 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
|
151 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
|
152 cmd = cmd[4:] |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
153 if not path: path = cmd |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
154 diffopts = ui.config('extdiff', 'opts.' + cmd, '') |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
155 diffopts = diffopts and [diffopts] or [] |
2959
7f5fc4b347de
extdiff: make new diff commands pick up their options correctly
TK Soh <teekaysoh@yahoo.com>
parents:
2913
diff
changeset
|
156 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
|
157 '''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
|
158 def mydiff(ui, repo, *pats, **opts): |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
159 return dodiff(ui, repo, path, diffopts, pats, opts) |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
160 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
|
161 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
162 Show differences between revisions for the specified |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
163 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
|
164 |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 directory, and, when no revisions are specified, the |
2906
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
169 working directory files are compared to its parent.''' % { |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
170 'path': path, |
453097750fbf
extdiff: fix bugs. add test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2903
diff
changeset
|
171 } |
2333
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
172 return mydiff |
2959
7f5fc4b347de
extdiff: make new diff commands pick up their options correctly
TK Soh <teekaysoh@yahoo.com>
parents:
2913
diff
changeset
|
173 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
|
174 cmdtable['extdiff'][1][1:], |
de0c05afa511
new extension: extdiff. allows to use external diff program.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
175 _('hg %s [OPT]... [FILE]...') % cmd) |