style.py (10674:e2f9644a7738) | style.py (10691:65da28dee7cf) |
---|---|
1#! /usr/bin/env python 2# Copyright (c) 2014 ARM Limited 3# All rights reserved 4# 5# The license below extends only to copyright in the software and shall 6# not be construed as granting a license to any other intellectual 7# property including but not limited to intellectual property relating 8# to a hardware implementation of the functionality of the software --- 112 unchanged lines hidden (view full) --- 121 mod_regions &= m2 122 else: 123 mod_regions = Regions() 124 mod_regions.append(0, len(lines)) 125 126 return mod_regions 127 128class UserInterface(object): | 1#! /usr/bin/env python 2# Copyright (c) 2014 ARM Limited 3# All rights reserved 4# 5# The license below extends only to copyright in the software and shall 6# not be construed as granting a license to any other intellectual 7# property including but not limited to intellectual property relating 8# to a hardware implementation of the functionality of the software --- 112 unchanged lines hidden (view full) --- 121 mod_regions &= m2 122 else: 123 mod_regions = Regions() 124 mod_regions.append(0, len(lines)) 125 126 return mod_regions 127 128class UserInterface(object): |
129 def __init__(self, verbose=False, auto=False): 130 self.auto = auto | 129 def __init__(self, verbose=False): |
131 self.verbose = verbose 132 133 def prompt(self, prompt, results, default): | 130 self.verbose = verbose 131 132 def prompt(self, prompt, results, default): |
134 if self.auto: 135 return self.auto 136 | |
137 while True: 138 result = self.do_prompt(prompt, results, default) 139 if result in results: 140 return result 141 142class MercurialUI(UserInterface): 143 def __init__(self, ui, *args, **kwargs): 144 super(MercurialUI, self).__init__(*args, **kwargs) --- 286 unchanged lines hidden (view full) --- 431 files are checked in their entirety while only modifications of 432 modified files are checked). 433 434 The --all option can be specified to include clean files and check 435 modified files in their entirety. 436 """ 437 from mercurial import mdiff, util 438 | 133 while True: 134 result = self.do_prompt(prompt, results, default) 135 if result in results: 136 return result 137 138class MercurialUI(UserInterface): 139 def __init__(self, ui, *args, **kwargs): 140 super(MercurialUI, self).__init__(*args, **kwargs) --- 286 unchanged lines hidden (view full) --- 427 files are checked in their entirety while only modifications of 428 modified files are checked). 429 430 The --all option can be specified to include clean files and check 431 modified files in their entirety. 432 """ 433 from mercurial import mdiff, util 434 |
439 opt_fix_white = opts.get('fix_white', False) | 435 opt_fix_all = opts.get('fix_all', False) 436 if not opt_fix_all: 437 opt_fix_white = opts.get('fix_white', False) 438 opt_fix_include = opts.get('fix_include', False) 439 else: 440 opt_fix_white = True 441 opt_fix_include = True 442 |
440 opt_all = opts.get('all', False) 441 opt_no_ignore = opts.get('no_ignore', False) | 443 opt_all = opts.get('all', False) 444 opt_no_ignore = opts.get('no_ignore', False) |
442 ui = MercurialUI(hgui, hgui.verbose, opt_fix_white) | 445 ui = MercurialUI(hgui, verbose=hgui.verbose) |
443 444 def prompt(name, func, regions=all_regions): 445 result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", 'aif', 'a') 446 if result == 'a': 447 return True 448 elif result == 'f': 449 func(name, regions) 450 451 return False 452 | 446 447 def prompt(name, func, regions=all_regions): 448 result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", 'aif', 'a') 449 if result == 'a': 450 return True 451 elif result == 'f': 452 func(name, regions) 453 454 return False 455 |
456 def no_prompt(name, func, regions=all_regions): 457 func(name, regions) 458 return False |
|
453 | 459 |
460 prompt_white = prompt if not opt_fix_white else no_prompt 461 prompt_include = prompt if not opt_fix_include else no_prompt 462 |
|
454 # Import the match (repository file name matching helper) 455 # function. Different versions of Mercurial keep it in different 456 # modules and implement them differently. 457 try: 458 from mercurial import scmutil 459 m = scmutil.match(repo[None], pats, opts) 460 except ImportError: 461 from mercurial import cmdutil --- 14 unchanged lines hidden (view full) --- 476 files = [ (fn, all_regions) for fn in added + modified + clean ] 477 478 whitespace = Whitespace(ui, repo) 479 sorted_includes = SortedIncludes(ui, repo) 480 for fname, mod_regions in files: 481 if not opt_no_ignore and check_ignores(fname): 482 continue 483 | 463 # Import the match (repository file name matching helper) 464 # function. Different versions of Mercurial keep it in different 465 # modules and implement them differently. 466 try: 467 from mercurial import scmutil 468 m = scmutil.match(repo[None], pats, opts) 469 except ImportError: 470 from mercurial import cmdutil --- 14 unchanged lines hidden (view full) --- 485 files = [ (fn, all_regions) for fn in added + modified + clean ] 486 487 whitespace = Whitespace(ui, repo) 488 sorted_includes = SortedIncludes(ui, repo) 489 for fname, mod_regions in files: 490 if not opt_no_ignore and check_ignores(fname): 491 continue 492 |
484 if whitespace.apply(fname, prompt, mod_regions): | 493 if whitespace.apply(fname, prompt_white, mod_regions): |
485 return True 486 | 494 return True 495 |
487 if sorted_includes.apply(fname, prompt, mod_regions): | 496 if sorted_includes.apply(fname, prompt_include, mod_regions): |
488 return True 489 490 return False 491 492def do_check_format(hgui, repo, **args): | 497 return True 498 499 return False 500 501def do_check_format(hgui, repo, **args): |
493 ui = MercurialUI(hgui, hgui.verbose, auto) | 502 ui = MercurialUI(hgui, hgui.verbose) |
494 495 modified, added, removed, deleted, unknown, ignore, clean = repo.status() 496 497 verbose = 0 498 stats = ValidationStats() 499 for f in modified + added: 500 validate(joinpath(repo.root, f), stats, verbose, None) 501 --- 37 unchanged lines hidden (view full) --- 539 from mercurial.i18n import _ 540except ImportError: 541 def _(arg): 542 return arg 543 544cmdtable = { 545 '^m5style' : ( 546 do_check_style, [ | 503 504 modified, added, removed, deleted, unknown, ignore, clean = repo.status() 505 506 verbose = 0 507 stats = ValidationStats() 508 for f in modified + added: 509 validate(joinpath(repo.root, f), stats, verbose, None) 510 --- 37 unchanged lines hidden (view full) --- 548 from mercurial.i18n import _ 549except ImportError: 550 def _(arg): 551 return arg 552 553cmdtable = { 554 '^m5style' : ( 555 do_check_style, [ |
547 ('w', 'fix-white', False, _("automatically fix whitespace")), | 556 ('f', 'fix-all', False, _("automatically fix style issues")), 557 ('', 'fix-white', False, _("automatically fix white space issues")), 558 ('', 'fix-include', False, _("automatically fix include ordering")), |
548 ('a', 'all', False, 549 _("include clean files and unmodified parts of modified files")), 550 ('', 'no-ignore', False, _("ignore the style ignore list")), 551 ] + commands.walkopts, 552 _('hg m5style [-a] [FILE]...')), 553 '^m5format' : 554 ( do_check_format, 555 [ ], --- 57 unchanged lines hidden --- | 559 ('a', 'all', False, 560 _("include clean files and unmodified parts of modified files")), 561 ('', 'no-ignore', False, _("ignore the style ignore list")), 562 ] + commands.walkopts, 563 _('hg m5style [-a] [FILE]...')), 564 '^m5format' : 565 ( do_check_format, 566 [ ], --- 57 unchanged lines hidden --- |