comparison hgext/extdiff.py @ 5245:a1efa71f3ece

Improve extdiff configuration. In addition to the old cmd.foo, opts.foo hgrc entries, allow a more simple alias = command [opts]... form. For example: [extdiff] cdiff = colordiff -uprN
author Brendan Cully <brendan@kublai.com>
date Sat, 25 Aug 2007 12:25:53 -0700
parents c80af96943aa
children 32ec518ee3cb
comparison
equal deleted inserted replaced
5244:79279b5583c6 5245:a1efa71f3ece
2 # 2 #
3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> 3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
4 # 4 #
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 # 7
8 # The `extdiff' Mercurial extension allows you to use external programs 8 '''
9 # to compare revisions, or revision with working dir. The external diff 9 The `extdiff' Mercurial extension allows you to use external programs
10 # programs are called with a configurable set of options and two 10 to compare revisions, or revision with working dir. The external diff
11 # non-option arguments: paths to directories containing snapshots of 11 programs are called with a configurable set of options and two
12 # files to compare. 12 non-option arguments: paths to directories containing snapshots of
13 # 13 files to compare.
14 # To enable this extension: 14
15 # 15 To enable this extension:
16 # [extensions] 16
17 # hgext.extdiff = 17 [extensions]
18 # 18 hgext.extdiff =
19 # The `extdiff' extension also allows to configure new diff commands, so 19
20 # you do not need to type "hg extdiff -p kdiff3" always. 20 The `extdiff' extension also allows to configure new diff commands, so
21 # 21 you do not need to type "hg extdiff -p kdiff3" always.
22 # [extdiff] 22
23 # # add new command that runs GNU diff(1) in 'context diff' mode 23 [extdiff]
24 # cmd.cdiff = gdiff 24 # add new command that runs GNU diff(1) in 'context diff' mode
25 # opts.cdiff = -Nprc5 25 cdiff = gdiff -Nprc5
26 26 ## or the old way:
27 # # add new command called vdiff, runs kdiff3 27 #cmd.cdiff = gdiff
28 # cmd.vdiff = kdiff3 28 #opts.cdiff = -Nprc5
29 29
30 # # add new command called meld, runs meld (no need to name twice) 30 # add new command called vdiff, runs kdiff3
31 # cmd.meld = 31 vdiff = kdiff3
32 32
33 # # add new command called vimdiff, runs gvimdiff with DirDiff plugin 33 # add new command called meld, runs meld (no need to name twice)
34 # #(see http://www.vim.org/scripts/script.php?script_id=102) 34 meld =
35 # # Non english user, be sure to put "let g:DirDiffDynamicDiffText = 1" in 35
36 # # your .vimrc 36 # add new command called vimdiff, runs gvimdiff with DirDiff plugin
37 # cmd.vimdiff = gvim 37 #(see http://www.vim.org/scripts/script.php?script_id=102)
38 # opts.vimdiff = -f '+next' '+execute "DirDiff" argv(0) argv(1)' 38 # Non english user, be sure to put "let g:DirDiffDynamicDiffText = 1" in
39 # 39 # your .vimrc
40 # Each custom diff commands can have two parts: a `cmd' and an `opts' 40 vimdiff = gvim -f '+next' '+execute "DirDiff" argv(0) argv(1)'
41 # part. The cmd.xxx option defines the name of an executable program 41
42 # that will be run, and opts.xxx defines a set of command-line options 42 You can use -I/-X and list of file or directory names like normal
43 # which will be inserted to the command between the program name and 43 "hg diff" command. The `extdiff' extension makes snapshots of only
44 # the files/directories to diff (i.e. the cdiff example above). 44 needed files, so running the external diff program will actually be
45 # 45 pretty fast (at least faster than having to compare the entire tree).
46 # You can use -I/-X and list of file or directory names like normal 46 '''
47 # "hg diff" command. The `extdiff' extension makes snapshots of only
48 # needed files, so running the external diff program will actually be
49 # pretty fast (at least faster than having to compare the entire tree).
50 47
51 from mercurial.i18n import _ 48 from mercurial.i18n import _
52 from mercurial.node import * 49 from mercurial.node import *
53 from mercurial import cmdutil, util, commands 50 from mercurial import cmdutil, util, commands
54 import os, shutil, tempfile 51 import os, shlex, shutil, tempfile
55
56 52
57 def snapshot_node(ui, repo, files, node, tmproot): 53 def snapshot_node(ui, repo, files, node, tmproot):
58 '''snapshot files as of some revision''' 54 '''snapshot files as of some revision'''
59 mf = repo.changectx(node).manifest() 55 mf = repo.changectx(node).manifest()
60 dirname = os.path.basename(repo.root) 56 dirname = os.path.basename(repo.root)
185 _('hg extdiff [OPT]... [FILE]...')), 181 _('hg extdiff [OPT]... [FILE]...')),
186 } 182 }
187 183
188 def uisetup(ui): 184 def uisetup(ui):
189 for cmd, path in ui.configitems('extdiff'): 185 for cmd, path in ui.configitems('extdiff'):
190 if not cmd.startswith('cmd.'): continue 186 if cmd.startswith('cmd.'):
191 cmd = cmd[4:] 187 cmd = cmd[4:]
192 if not path: path = cmd 188 if not path: path = cmd
193 diffopts = ui.config('extdiff', 'opts.' + cmd, '') 189 diffopts = ui.config('extdiff', 'opts.' + cmd, '')
194 diffopts = diffopts and [diffopts] or [] 190 diffopts = diffopts and [diffopts] or []
191 elif cmd.startswith('opts.'):
192 continue
193 else:
194 # command = path opts
195 if path:
196 diffopts = shlex.split(path)
197 path = diffopts.pop(0)
198 else:
199 path, diffopts = cmd, []
195 def save(cmd, path, diffopts): 200 def save(cmd, path, diffopts):
196 '''use closure to save diff command to use''' 201 '''use closure to save diff command to use'''
197 def mydiff(ui, repo, *pats, **opts): 202 def mydiff(ui, repo, *pats, **opts):
198 return dodiff(ui, repo, path, diffopts, pats, opts) 203 return dodiff(ui, repo, path, diffopts, pats, opts)
199 mydiff.__doc__ = '''use %(path)r to diff repository (or selected files) 204 mydiff.__doc__ = '''use %(path)r to diff repository (or selected files)