Mercurial > public > mercurial-scm > hg
comparison hgext/extdiff.py @ 26228:0fd20a71abdb
extdiff: add a --patch argument for diffing changeset deltas
One of the things I missed the most when transitioning from versioned MQ to
evolve was the loss of being able to check that rebase conflicts were properly
resolved by:
$ hg ci --mq -m "before"
$ hg rebase -s qbase -d tip
$ hg bcompare --mq
The old csets stay in the tree with evolve, but a straight diff includes all of
the other changes that were pulled in, obscuring the code that was rebased.
Diffing deltas can be confusing, but unless radical changes were made during the
resolve, it is very clear when individual hunks are added, dropped or modified.
Unlike the MQ technique, this can only compare a single pair of csets/patches at
a time. Like the MQ method, this also highlights changes in the commit comment
and other metadata.
I originally tried monkey patching from the evolve extension, but that is too
complicated given that it depends on the order the two different extensions are
loaded. This functionality is also useful when comparing grafts however, so
implementing it in the core is more than just convenience.
The --change argument doesn't make much sense for this, but it isn't harmful so
I didn't bother blocking it. The -I/-X options are ignored because of a
limitation of cmdutil.export(). We'll fix that next.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 09 Sep 2015 21:07:38 -0400 |
parents | 611ba118ebfc |
children | d1530c6e8613 |
comparison
equal
deleted
inserted
replaced
26227:611ba118ebfc | 26228:0fd20a71abdb |
---|---|
145 | 145 |
146 subrepos=opts.get('subrepos') | 146 subrepos=opts.get('subrepos') |
147 | 147 |
148 matcher = scmutil.match(repo[node2], pats, opts) | 148 matcher = scmutil.match(repo[node2], pats, opts) |
149 | 149 |
150 if True: | 150 if opts.get('patch'): |
151 if subrepos: | |
152 raise util.Abort(_('--patch cannot be used with --subrepos')) | |
153 if node2 is None: | |
154 raise util.Abort(_('--patch requires two revisions')) | |
155 else: | |
151 mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher, | 156 mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher, |
152 listsubrepos=subrepos)[:3]) | 157 listsubrepos=subrepos)[:3]) |
153 if do3way: | 158 if do3way: |
154 mod_b, add_b, rem_b = map(set, | 159 mod_b, add_b, rem_b = map(set, |
155 repo.status(node1b, node2, matcher, | 160 repo.status(node1b, node2, matcher, |
161 if not common: | 166 if not common: |
162 return 0 | 167 return 0 |
163 | 168 |
164 tmproot = tempfile.mkdtemp(prefix='extdiff.') | 169 tmproot = tempfile.mkdtemp(prefix='extdiff.') |
165 try: | 170 try: |
166 if True: | 171 if not opts.get('patch'): |
167 # Always make a copy of node1a (and node1b, if applicable) | 172 # Always make a copy of node1a (and node1b, if applicable) |
168 dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a) | 173 dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a) |
169 dir1a = snapshot(ui, repo, dir1a_files, node1a, tmproot, | 174 dir1a = snapshot(ui, repo, dir1a_files, node1a, tmproot, |
170 subrepos)[0] | 175 subrepos)[0] |
171 rev1a = '@%d' % repo[node1a].rev() | 176 rev1a = '@%d' % repo[node1a].rev() |
215 label1b = common_file + rev1b | 220 label1b = common_file + rev1b |
216 if not os.path.isfile(dir1b): | 221 if not os.path.isfile(dir1b): |
217 dir1b = os.devnull | 222 dir1b = os.devnull |
218 dir2 = os.path.join(dir2root, dir2, common_file) | 223 dir2 = os.path.join(dir2root, dir2, common_file) |
219 label2 = common_file + rev2 | 224 label2 = common_file + rev2 |
225 else: | |
226 # XXX: export doesn't support -I/-X like extdiff does | |
227 template = 'hg-%h.patch' | |
228 cmdutil.export(repo, [repo[node1a].rev(), repo[node2].rev()], | |
229 template=repo.vfs.reljoin(tmproot, template)) | |
230 label1a = cmdutil.makefilename(repo, template, node1a) | |
231 label2 = cmdutil.makefilename(repo, template, node2) | |
232 dir1a = repo.vfs.reljoin(tmproot, label1a) | |
233 dir2 = repo.vfs.reljoin(tmproot, label2) | |
234 dir1b = None | |
235 label1b = None | |
236 fns_and_mtime = [] | |
220 | 237 |
221 # Function to quote file/dir names in the argument string. | 238 # Function to quote file/dir names in the argument string. |
222 # When not operating in 3-way mode, an empty string is | 239 # When not operating in 3-way mode, an empty string is |
223 # returned for parent2 | 240 # returned for parent2 |
224 replace = {'parent': dir1a, 'parent1': dir1a, 'parent2': dir1b, | 241 replace = {'parent': dir1a, 'parent1': dir1a, 'parent2': dir1b, |
258 _('comparison program to run'), _('CMD')), | 275 _('comparison program to run'), _('CMD')), |
259 ('o', 'option', [], | 276 ('o', 'option', [], |
260 _('pass option to comparison program'), _('OPT')), | 277 _('pass option to comparison program'), _('OPT')), |
261 ('r', 'rev', [], _('revision'), _('REV')), | 278 ('r', 'rev', [], _('revision'), _('REV')), |
262 ('c', 'change', '', _('change made by revision'), _('REV')), | 279 ('c', 'change', '', _('change made by revision'), _('REV')), |
280 ('', 'patch', None, _('compare patches for two revisions')) | |
263 ] + commands.walkopts + commands.subrepoopts, | 281 ] + commands.walkopts + commands.subrepoopts, |
264 _('hg extdiff [OPT]... [FILE]...'), | 282 _('hg extdiff [OPT]... [FILE]...'), |
265 inferrepo=True) | 283 inferrepo=True) |
266 def extdiff(ui, repo, *pats, **opts): | 284 def extdiff(ui, repo, *pats, **opts): |
267 '''use external program to diff repository (or selected files) | 285 '''use external program to diff repository (or selected files) |