##// END OF EJS Templates
Minor typo change to reflect actual values used.
"Daniel Santa Cruz " -
r2338:391c5d0f default
parent child Browse files
Show More
@@ -1,150 +1,150 b''
1 1 # extdiff.py - external diff program support for mercurial
2 2 #
3 3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7 #
8 8 # allow to use external programs to compare revisions, or revision
9 9 # with working dir. program is called with two arguments: paths to
10 10 # directories containing snapshots of files to compare.
11 11 #
12 12 # to enable:
13 13 #
14 14 # [extensions]
15 15 # hgext.extdiff =
16 16 #
17 17 # also allows to configure new diff commands, so you do not need to
18 18 # type "hg extdiff -p kdiff3" always.
19 19 #
20 20 # [extdiff]
21 21 # # add new command called vdiff, runs kdiff3
22 22 # cmd.vdiff = kdiff3
23 23 # # add new command called meld, runs meld (no need to name twice)
24 24 # cmd.meld =
25 25 #
26 26 # you can use -I/-X and list of file or directory names like normal
27 27 # "hg diff" command. extdiff makes snapshots of only needed files, so
28 28 # compare program will be fast.
29 29
30 30 from mercurial.demandload import demandload
31 31 from mercurial.i18n import gettext as _
32 32 from mercurial.node import *
33 33 demandload(globals(), 'mercurial:commands,util os shutil tempfile')
34 34
35 35 def dodiff(ui, repo, diffcmd, pats, opts):
36 36 def snapshot_node(files, node):
37 37 '''snapshot files as of some revision'''
38 38 changes = repo.changelog.read(node)
39 39 mf = repo.manifest.read(changes[0])
40 40 dirname = '%s.%s' % (os.path.basename(repo.root), short(node))
41 41 base = os.path.join(tmproot, dirname)
42 42 os.mkdir(base)
43 43 if not ui.quiet:
44 44 ui.write_err(_('making snapshot of %d files from rev %s\n') %
45 45 (len(files), short(node)))
46 46 for fn in files:
47 47 wfn = util.pconvert(fn)
48 48 ui.note(' %s\n' % wfn)
49 49 dest = os.path.join(base, wfn)
50 50 destdir = os.path.dirname(dest)
51 51 if not os.path.isdir(destdir):
52 52 os.makedirs(destdir)
53 53 repo.wwrite(wfn, repo.file(fn).read(mf[fn]), open(dest, 'w'))
54 54 return dirname
55 55
56 56 def snapshot_wdir(files):
57 57 '''snapshot files from working directory.
58 58 if not using snapshot, -I/-X does not work and recursive diff
59 59 in tools like kdiff3 and meld displays too many files.'''
60 60 dirname = os.path.basename(repo.root)
61 61 base = os.path.join(tmproot, dirname)
62 62 os.mkdir(base)
63 63 if not ui.quiet:
64 64 ui.write_err(_('making snapshot of %d files from working dir\n') %
65 65 (len(files)))
66 66 for fn in files:
67 67 wfn = util.pconvert(fn)
68 68 ui.note(' %s\n' % wfn)
69 69 dest = os.path.join(base, wfn)
70 70 destdir = os.path.dirname(dest)
71 71 if not os.path.isdir(destdir):
72 72 os.makedirs(destdir)
73 73 fp = open(dest, 'w')
74 74 for chunk in util.filechunkiter(repo.wopener(wfn)):
75 75 fp.write(chunk)
76 76 return dirname
77 77
78 78 node1, node2 = commands.revpair(ui, repo, opts['rev'])
79 79 files, matchfn, anypats = commands.matchpats(repo, pats, opts)
80 80 modified, added, removed, deleted, unknown = repo.changes(
81 81 node1, node2, files, match=matchfn)
82 82 if not (modified or added or removed):
83 83 return 0
84 84
85 85 tmproot = tempfile.mkdtemp(prefix='extdiff.')
86 86 try:
87 87 dir1 = snapshot_node(modified + removed, node1)
88 88 if node2:
89 89 dir2 = snapshot_node(modified + added, node2)
90 90 else:
91 91 dir2 = snapshot_wdir(modified + added)
92 92 util.system('%s %s "%s" "%s"' %
93 93 (diffcmd, ' '.join(opts['option']), dir1, dir2),
94 94 cwd=tmproot)
95 95 return 1
96 96 finally:
97 97 ui.note(_('cleaning up temp directory\n'))
98 98 shutil.rmtree(tmproot)
99 99
100 100 def extdiff(ui, repo, *pats, **opts):
101 101 '''use external program to diff repository (or selected files)
102 102
103 103 Show differences between revisions for the specified files, using
104 an external program. The default program used is "diff -Pnru".
104 an external program. The default program used is "diff -Npru".
105 105 To select a different program, use the -p option. The program
106 106 will be passed the names of two directories to compare. To pass
107 107 additional options to the program, use the -o option. These will
108 108 be passed before the names of the directories to compare.
109 109
110 110 When two revision arguments are given, then changes are
111 111 shown between those revisions. If only one revision is
112 112 specified then that revision is compared to the working
113 113 directory, and, when no revisions are specified, the
114 114 working directory files are compared to its parent.'''
115 115 return dodiff(ui, repo, opts['program'] or 'diff -Npru', pats, opts)
116 116
117 117 cmdtable = {
118 118 "extdiff":
119 119 (extdiff,
120 120 [('p', 'program', '', _('comparison program to run')),
121 121 ('o', 'option', [], _('pass option to comparison program')),
122 122 ('r', 'rev', [], _('revision')),
123 123 ('I', 'include', [], _('include names matching the given patterns')),
124 124 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
125 125 _('hg extdiff [OPT]... [FILE]...')),
126 126 }
127 127
128 128 def uisetup(ui):
129 129 for cmd, path in ui.configitems('extdiff'):
130 130 if not cmd.startswith('cmd.'): continue
131 131 cmd = cmd[4:]
132 132 if not path: path = cmd
133 133 def save(cmd, path):
134 134 '''use closure to save diff command to use'''
135 135 def mydiff(ui, repo, *pats, **opts):
136 136 return dodiff(ui, repo, path, pats, opts)
137 137 mydiff.__doc__ = '''use %s to diff repository (or selected files)
138 138
139 139 Show differences between revisions for the specified
140 140 files, using the %s program.
141 141
142 142 When two revision arguments are given, then changes are
143 143 shown between those revisions. If only one revision is
144 144 specified then that revision is compared to the working
145 145 directory, and, when no revisions are specified, the
146 146 working directory files are compared to its parent.''' % (cmd, cmd)
147 147 return mydiff
148 148 cmdtable[cmd] = (save(cmd, path),
149 149 cmdtable['extdiff'][1][1:],
150 150 _('hg %s [OPT]... [FILE]...') % cmd)
General Comments 0
You need to be logged in to leave comments. Login now