Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/scm/git.py

Issue 2305143003: webkitpy: Make all regex strings use raw string literals. (Closed)
Patch Set: Make all regex strings raw strings. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2009, 2010, 2011 Google Inc. All rights reserved. 1 # Copyright (c) 2009, 2010, 2011 Google Inc. All rights reserved.
2 # Copyright (c) 2009 Apple Inc. All rights reserved. 2 # Copyright (c) 2009 Apple Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 def display_name(self): 194 def display_name(self):
195 return "git" 195 return "git"
196 196
197 def most_recent_log_matching(self, grep_str, path): 197 def most_recent_log_matching(self, grep_str, path):
198 # We use '--grep=' + foo rather than '--grep', foo because 198 # We use '--grep=' + foo rather than '--grep', foo because
199 # git 1.7.0.4 (and earlier) didn't support the separate arg. 199 # git 1.7.0.4 (and earlier) didn't support the separate arg.
200 return self._run_git(['log', '-1', '--grep=' + grep_str, '--date=iso', s elf.find_checkout_root(path)]) 200 return self._run_git(['log', '-1', '--grep=' + grep_str, '--date=iso', s elf.find_checkout_root(path)])
201 201
202 def _commit_position_from_git_log(self, git_log): 202 def _commit_position_from_git_log(self, git_log):
203 match = re.search("^\s*Cr-Commit-Position:.*@\{#(?P<commit_position>\d+) \}", git_log, re.MULTILINE) 203 match = re.search(r"^\s*Cr-Commit-Position:.*@\{#(?P<commit_position>\d+ )\}", git_log, re.MULTILINE)
204 if not match: 204 if not match:
205 return "" 205 return ""
206 return int(match.group('commit_position')) 206 return int(match.group('commit_position'))
207 207
208 def commit_position(self, path): 208 def commit_position(self, path):
209 git_log = self.most_recent_log_matching('Cr-Commit-Position:', path) 209 git_log = self.most_recent_log_matching('Cr-Commit-Position:', path)
210 return self._commit_position_from_git_log(git_log) 210 return self._commit_position_from_git_log(git_log)
211 211
212 def _commit_position_regex_for_timestamp(self): 212 def _commit_position_regex_for_timestamp(self):
213 return 'Cr-Commit-Position:.*@{#%s}' 213 return 'Cr-Commit-Position:.*@{#%s}'
214 214
215 def timestamp_of_revision(self, path, revision): 215 def timestamp_of_revision(self, path, revision):
216 git_log = self.most_recent_log_matching(self._commit_position_regex_for_ timestamp() % revision, path) 216 git_log = self.most_recent_log_matching(self._commit_position_regex_for_ timestamp() % revision, path)
217 match = re.search("^Date:\s*(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{ 2}) ([+-])(\d{2})(\d{2})$", git_log, re.MULTILINE) 217 match = re.search(r"^Date:\s*(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d {2}) ([+-])(\d{2})(\d{2})$", git_log, re.MULTILINE)
218 if not match: 218 if not match:
219 return "" 219 return ""
220 220
221 # Manually modify the timezone since Git doesn't have an option to show it in UTC. 221 # Manually modify the timezone since Git doesn't have an option to show it in UTC.
222 # Git also truncates milliseconds but we're going to ignore that for now . 222 # Git also truncates milliseconds but we're going to ignore that for now .
223 time_with_timezone = datetime.datetime(int(match.group(1)), int(match.gr oup(2)), int(match.group(3)), 223 time_with_timezone = datetime.datetime(int(match.group(1)), int(match.gr oup(2)), int(match.group(3)),
224 int(match.group(4)), int(match.gr oup(5)), int(match.group(6)), 0) 224 int(match.group(4)), int(match.gr oup(5)), int(match.group(6)), 0)
225 225
226 sign = 1 if match.group(7) == '+' else -1 226 sign = 1 if match.group(7) == '+' else -1
227 time_without_timezone = time_with_timezone - \ 227 time_without_timezone = time_with_timezone - \
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 if format: 301 if format:
302 args.append('--format=' + format) 302 args.append('--format=' + format)
303 return self._run_git(args) 303 return self._run_git(args)
304 304
305 def affected_files(self, commit): 305 def affected_files(self, commit):
306 output = self._run_git(['log', '-1', '--format=', '--name-only', commit] ) 306 output = self._run_git(['log', '-1', '--format=', '--name-only', commit] )
307 return output.strip().split('\n') 307 return output.strip().split('\n')
308 308
309 def _branch_tracking_remote_master(self): 309 def _branch_tracking_remote_master(self):
310 origin_info = self._run_git(['remote', 'show', 'origin', '-n']) 310 origin_info = self._run_git(['remote', 'show', 'origin', '-n'])
311 match = re.search("^\s*(?P<branch_name>\S+)\s+merges with remote master$ ", origin_info, re.MULTILINE) 311 match = re.search(r"^\s*(?P<branch_name>\S+)\s+merges with remote master $", origin_info, re.MULTILINE)
312 if not match: 312 if not match:
313 raise ScriptError(message="Unable to find local branch tracking orig in/master.") 313 raise ScriptError(message="Unable to find local branch tracking orig in/master.")
314 branch = str(match.group("branch_name")) 314 branch = str(match.group("branch_name"))
315 return self._branch_from_ref(self._run_git(['rev-parse', '--symbolic-ful l-name', branch]).strip()) 315 return self._branch_from_ref(self._run_git(['rev-parse', '--symbolic-ful l-name', branch]).strip())
316 316
317 def is_cleanly_tracking_remote_master(self): 317 def is_cleanly_tracking_remote_master(self):
318 if self.has_working_directory_changes(): 318 if self.has_working_directory_changes():
319 return False 319 return False
320 if self.current_branch() != self._branch_tracking_remote_master(): 320 if self.current_branch() != self._branch_tracking_remote_master():
321 return False 321 return False
322 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: 322 if len(self._local_commits(self._branch_tracking_remote_master())) > 0:
323 return False 323 return False
324 return True 324 return True
325 325
326 def ensure_cleanly_tracking_remote_master(self): 326 def ensure_cleanly_tracking_remote_master(self):
327 self._discard_working_directory_changes() 327 self._discard_working_directory_changes()
328 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) 328 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()])
329 self._discard_local_commits() 329 self._discard_local_commits()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698