Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: Tools/scripts/patchcheck.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Tools/msi/msi.py ('k') | Tools/scripts/reindent.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import re 1 import re
2 import sys 2 import sys
3 import shutil 3 import shutil
4 import os.path 4 import os.path
5 import subprocess 5 import subprocess
6 6
7 import reindent 7 import reindent
8 import untabify 8 import untabify
9 9
10 10
(...skipping 18 matching lines...) Expand all
29 return result 29 return result
30 return call_fxn 30 return call_fxn
31 return decorated_fxn 31 return decorated_fxn
32 32
33 33
34 @status("Getting the list of files that have been added/changed", 34 @status("Getting the list of files that have been added/changed",
35 info=lambda x: n_files_str(len(x))) 35 info=lambda x: n_files_str(len(x)))
36 def changed_files(): 36 def changed_files():
37 """Get the list of changed or added files from the VCS.""" 37 """Get the list of changed or added files from the VCS."""
38 if os.path.isdir('.hg'): 38 if os.path.isdir('.hg'):
39 vcs = 'hg'
39 cmd = 'hg status --added --modified --no-status' 40 cmd = 'hg status --added --modified --no-status'
41 elif os.path.isdir('.svn'):
42 vcs = 'svn'
43 cmd = 'svn status --quiet --non-interactive --ignore-externals'
40 else: 44 else:
41 sys.exit('need a checkout to get modified files') 45 sys.exit('need a checkout to get modified files')
42 46
43 st = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) 47 st = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
44 try: 48 try:
45 st.wait() 49 st.wait()
46 return [x.decode().rstrip() for x in st.stdout] 50 if vcs == 'hg':
51 return [x.decode().rstrip() for x in st.stdout]
52 else:
53 output = (x.decode().rstrip().rsplit(None, 1)[-1]
54 for x in st.stdout if x[0] in b'AM')
55 return set(path for path in output if os.path.isfile(path))
47 finally: 56 finally:
48 st.stdout.close() 57 st.stdout.close()
49 58
50 59
51 def report_modified_files(file_paths): 60 def report_modified_files(file_paths):
52 count = len(file_paths) 61 count = len(file_paths)
53 if count == 0: 62 if count == 0:
54 return n_files_str(count) 63 return n_files_str(count)
55 else: 64 else:
56 lines = ["{}:".format(n_files_str(count))] 65 lines = ["{}:".format(n_files_str(count))]
57 for path in file_paths: 66 for path in file_paths:
58 lines.append(" {}".format(path)) 67 lines.append(" {}".format(path))
59 return "\n".join(lines) 68 return "\n".join(lines)
60 69
61 70
62 @status("Fixing whitespace", info=report_modified_files) 71 @status("Fixing whitespace", info=report_modified_files)
63 def normalize_whitespace(file_paths): 72 def normalize_whitespace(file_paths):
64 """Make sure that the whitespace for .py files have been normalized.""" 73 """Make sure that the whitespace for .py files have been normalized."""
65 reindent.makebackup = False # No need to create backups. 74 reindent.makebackup = False # No need to create backups.
66 fixed = [path for path in file_paths if path.endswith('.py') and 75 fixed = []
67 reindent.check(path)] 76 for path in (x for x in file_paths if x.endswith('.py')):
77 if reindent.check(path):
78 fixed.append(path)
68 return fixed 79 return fixed
69 80
70 81
71 @status("Fixing C file whitespace", info=report_modified_files) 82 @status("Fixing C file whitespace", info=report_modified_files)
72 def normalize_c_whitespace(file_paths): 83 def normalize_c_whitespace(file_paths):
73 """Report if any C files """ 84 """Report if any C files """
74 fixed = [] 85 fixed = []
75 for path in file_paths: 86 for path in file_paths:
76 with open(path, 'r') as f: 87 with open(path, 'r') as f:
77 if '\t' not in f.read(): 88 if '\t' not in f.read():
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 # Misc/NEWS changed. 149 # Misc/NEWS changed.
139 reported_news(special_files) 150 reported_news(special_files)
140 151
141 # Test suite run and passed. 152 # Test suite run and passed.
142 print() 153 print()
143 print("Did you run the test suite?") 154 print("Did you run the test suite?")
144 155
145 156
146 if __name__ == '__main__': 157 if __name__ == '__main__':
147 main() 158 main()
OLDNEW
« no previous file with comments | « Tools/msi/msi.py ('k') | Tools/scripts/reindent.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+