comparison hgext/record.py @ 14597:3f1dccea9510

record: add white space diff options
author Ingo Proetel <proetel@aicas.de>
date Fri, 10 Jun 2011 10:58:10 +0200
parents 39e81b9377e6
children 351a9292e430
comparison
equal deleted inserted replaced
14596:6a0070d00bc8 14597:3f1dccea9510
14 14
15 cmdtable = {} 15 cmdtable = {}
16 command = cmdutil.command(cmdtable) 16 command = cmdutil.command(cmdtable)
17 17
18 lines_re = re.compile(r'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)') 18 lines_re = re.compile(r'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)')
19
20 diffopts = [
21 ('w', 'ignore-all-space', False,
22 _('ignore white space when comparing lines')),
23 ('b', 'ignore-space-change', None,
24 _('ignore changes in the amount of white space')),
25 ('B', 'ignore-blank-lines', None,
26 _('ignore changes whose lines are all blank')),
27 ]
19 28
20 def scanpatch(fp): 29 def scanpatch(fp):
21 """like patch.iterhunks, but yield different events 30 """like patch.iterhunks, but yield different events
22 31
23 - ('file', [header_lines + fromfile + tofile]) 32 - ('file', [header_lines + fromfile + tofile])
343 fixoffset += chunk.removed - chunk.added 352 fixoffset += chunk.removed - chunk.added
344 return sum([h for h in applied.itervalues() 353 return sum([h for h in applied.itervalues()
345 if h[0].special() or len(h) > 1], []) 354 if h[0].special() or len(h) > 1], [])
346 355
347 @command("record", 356 @command("record",
348 commands.table['^commit|ci'][1], # same options as commit 357 # same options as commit + white space diff options
358 commands.table['^commit|ci'][1][:] + diffopts,
349 _('hg record [OPTION]... [FILE]...')) 359 _('hg record [OPTION]... [FILE]...'))
350 def record(ui, repo, *pats, **opts): 360 def record(ui, repo, *pats, **opts):
351 '''interactively select changes to commit 361 '''interactively select changes to commit
352 362
353 If a list of files is omitted, all changes reported by :hg:`status` 363 If a list of files is omitted, all changes reported by :hg:`status`
433 if merge: 443 if merge:
434 raise util.Abort(_('cannot partially commit a merge ' 444 raise util.Abort(_('cannot partially commit a merge '
435 '(use "hg commit" instead)')) 445 '(use "hg commit" instead)'))
436 446
437 changes = repo.status(match=match)[:3] 447 changes = repo.status(match=match)[:3]
438 diffopts = mdiff.diffopts(git=True, nodates=True) 448 diffopts = mdiff.diffopts(git=True, nodates=True,
449 ignorews=opts.get('ignore_all_space'),
450 ignorewsamount=opts.get('ignore_space_change'),
451 ignoreblanklines=opts.get('ignore_blank_lines'))
439 chunks = patch.diff(repo, changes=changes, opts=diffopts) 452 chunks = patch.diff(repo, changes=changes, opts=diffopts)
440 fp = cStringIO.StringIO() 453 fp = cStringIO.StringIO()
441 fp.write(''.join(chunks)) 454 fp.write(''.join(chunks))
442 fp.seek(0) 455 fp.seek(0)
443 456
565 return 578 return
566 579
567 cmdtable["qrecord"] = \ 580 cmdtable["qrecord"] = \
568 (qrecord, 581 (qrecord,
569 # same options as qnew, but copy them so we don't get 582 # same options as qnew, but copy them so we don't get
570 # -i/--interactive for qrecord 583 # -i/--interactive for qrecord and add white space diff options
571 mq.cmdtable['^qnew'][1][:], 584 mq.cmdtable['^qnew'][1][:] + diffopts,
572 _('hg qrecord [OPTION]... PATCH [FILE]...')) 585 _('hg qrecord [OPTION]... PATCH [FILE]...'))
573 586
574 _wrapcmd('qnew', mq.cmdtable, qrecord, _("interactively record a new patch")) 587 _wrapcmd('qnew', mq.cmdtable, qrecord, _("interactively record a new patch"))
575 _wrapcmd('qrefresh', mq.cmdtable, qrefresh, 588 _wrapcmd('qrefresh', mq.cmdtable, qrefresh,
576 _("interactively select changes to refresh")) 589 _("interactively select changes to refresh"))