style.py (6846:60e0df8086f0) | style.py (6868:c7eb55c68529) |
---|---|
1#! /usr/bin/env python 2# Copyright (c) 2006 The Regents of The University of Michigan 3# Copyright (c) 2007 The Hewlett-Packard Development Company 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 51 unchanged lines hidden (view full) --- 60whitespace_types = ('C', 'C++', 'swig', 'python', 'asm', 'isa') 61def whitespace_file(filename): 62 if file_type(filename) in whitespace_types: 63 return True 64 65 if filename.startswith("SCons"): 66 return True 67 | 1#! /usr/bin/env python 2# Copyright (c) 2006 The Regents of The University of Michigan 3# Copyright (c) 2007 The Hewlett-Packard Development Company 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 51 unchanged lines hidden (view full) --- 60whitespace_types = ('C', 'C++', 'swig', 'python', 'asm', 'isa') 61def whitespace_file(filename): 62 if file_type(filename) in whitespace_types: 63 return True 64 65 if filename.startswith("SCons"): 66 return True 67 |
68 return True | 68 return False |
69 70format_types = ( 'C', 'C++' ) 71def format_file(filename): 72 if file_type(filename) in format_types: 73 return True 74 75 return True 76 77def checkwhite_line(line): 78 match = lead.search(line) 79 if match and match.group(1).find('\t') != -1: | 69 70format_types = ( 'C', 'C++' ) 71def format_file(filename): 72 if file_type(filename) in format_types: 73 return True 74 75 return True 76 77def checkwhite_line(line): 78 match = lead.search(line) 79 if match and match.group(1).find('\t') != -1: |
80 return True | 80 return False |
81 82 match = trail.search(line) 83 if match: | 81 82 match = trail.search(line) 83 if match: |
84 return True | 84 return False |
85 86 return True 87 88def checkwhite(filename): 89 if not whitespace_file(filename): 90 return 91 92 try: --- 177 unchanged lines hidden (view full) --- 270 271 def skip(name): 272 return files and name in files 273 274 def prompt(name, fixonly=None): 275 if args.get('auto', False): 276 result = 'f' 277 else: | 85 86 return True 87 88def checkwhite(filename): 89 if not whitespace_file(filename): 90 return 91 92 try: --- 177 unchanged lines hidden (view full) --- 270 271 def skip(name): 272 return files and name in files 273 274 def prompt(name, fixonly=None): 275 if args.get('auto', False): 276 result = 'f' 277 else: |
278 result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", "^[aif]$", "a") | 278 while True: 279 result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", default='a') 280 if result in 'aif': 281 break 282 |
279 if result == 'a': 280 return True | 283 if result == 'a': 284 return True |
281 elif result == 'i': 282 pass | |
283 elif result == 'f': 284 fixwhite(repo.wjoin(name), args['tabsize'], fixonly) | 285 elif result == 'f': 286 fixwhite(repo.wjoin(name), args['tabsize'], fixonly) |
285 else: 286 raise util.Abort(_("Invalid response: '%s'") % result) | |
287 288 return False 289 290 modified, added, removed, deleted, unknown, ignore, clean = repo.status() 291 292 for fname in added: 293 if skip(fname): 294 continue --- 26 unchanged lines hidden (view full) --- 321 pctx = fctx.parents() 322 323 file_data = fctx.data() 324 lines = mdiff.splitnewlines(file_data) 325 if len(pctx) in (1, 2): 326 mod_lines = modified_lines(pctx[0].data(), file_data, len(lines)) 327 if len(pctx) == 2: 328 m2 = modified_lines(pctx[1].data(), file_data, len(lines)) | 287 288 return False 289 290 modified, added, removed, deleted, unknown, ignore, clean = repo.status() 291 292 for fname in added: 293 if skip(fname): 294 continue --- 26 unchanged lines hidden (view full) --- 321 pctx = fctx.parents() 322 323 file_data = fctx.data() 324 lines = mdiff.splitnewlines(file_data) 325 if len(pctx) in (1, 2): 326 mod_lines = modified_lines(pctx[0].data(), file_data, len(lines)) 327 if len(pctx) == 2: 328 m2 = modified_lines(pctx[1].data(), file_data, len(lines)) |
329 mod_lines = mod_lines & m2 # only the lines that are new in both | 329 # only the lines that are new in both 330 mod_lines = mod_lines & m2 |
330 else: 331 mod_lines = xrange(0, len(lines)) 332 333 fixonly = set() 334 for i,line in enumerate(lines): 335 if i not in mod_lines: 336 continue 337 --- 10 unchanged lines hidden (view full) --- 348 return True 349 350def check_whitespace(ui, repo, hooktype, node, parent1, parent2, **kwargs): 351 if hooktype != 'pretxncommit': 352 raise AttributeError, \ 353 "This hook is only meant for pretxncommit, not %s" % hooktype 354 355 args = { 'tabsize' : 8 } | 331 else: 332 mod_lines = xrange(0, len(lines)) 333 334 fixonly = set() 335 for i,line in enumerate(lines): 336 if i not in mod_lines: 337 continue 338 --- 10 unchanged lines hidden (view full) --- 349 return True 350 351def check_whitespace(ui, repo, hooktype, node, parent1, parent2, **kwargs): 352 if hooktype != 'pretxncommit': 353 raise AttributeError, \ 354 "This hook is only meant for pretxncommit, not %s" % hooktype 355 356 args = { 'tabsize' : 8 } |
356 do_check_whitespace(ui, repo, **args) | 357 return do_check_whitespace(ui, repo, **args) |
357 358def check_format(ui, repo, hooktype, node, parent1, parent2, **kwargs): 359 if hooktype != 'pretxncommit': 360 raise AttributeError, \ 361 "This hook is only meant for pretxncommit, not %s" % hooktype 362 363 modified, added, removed, deleted, unknown, ignore, clean = repo.status() 364 --- 86 unchanged lines hidden --- | 358 359def check_format(ui, repo, hooktype, node, parent1, parent2, **kwargs): 360 if hooktype != 'pretxncommit': 361 raise AttributeError, \ 362 "This hook is only meant for pretxncommit, not %s" % hooktype 363 364 modified, added, removed, deleted, unknown, ignore, clean = repo.status() 365 --- 86 unchanged lines hidden --- |