Changeset 127507 in webkit
- Timestamp:
- Sep 4, 2012 2:23:01 PM (12 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r127501 r127507 1 2012-09-04 Satish Sampath <satish@chromium.org> 2 3 Run git commands within the checkout directory 4 https://bugs.webkit.org/show_bug.cgi?id=95742 5 6 Reviewed by Eric Seidel. 7 8 git commands run from scm/git.py are sometimes run with cwd set to the 9 checkout_root and other times with whatever directory was the default cwd. 10 Instead all these should run with the checkout root set as the cwd 11 (except where we explicitly need a different path) 12 13 * Scripts/webkitpy/common/checkout/scm/git.py: 14 (Git._run_git): 15 (Git.find_checkout_root): 16 (Git.discard_local_commits): 17 (Git.local_commits): 18 (Git.working_directory_is_clean): 19 (Git.clean_working_directory): 20 (Git.add_list): 21 (Git.delete_list): 22 (Git.exists): 23 (Git._current_branch): 24 (Git._changes_files_for_commit): 25 (Git.revisions_changing_file): 26 (Git.svn_revision): 27 (Git._run_git_svn_find_rev): 28 (Git.contents_at_revision): 29 (Git.diff_for_file): 30 (Git.show_head): 31 (Git.committer_email_for_revision): 32 (Git.apply_reverse_diff): 33 (Git.revert_files): 34 (Git.commit_with_message): 35 (Git._commit_on_branch): 36 (Git.svn_commit_log): 37 (Git.last_svn_commit_log): 38 (Git.svn_blame): 39 (Git._branch_ref_exists): 40 (Git.delete_branch): 41 (Git.remote_merge_base): 42 (Git.commit_locally_with_message): 43 (Git.push_local_commits_to_server): 44 (Git.commit_ids_from_commitish_arguments): 45 (Git.commit_message_for_local_commit): 46 (Git.files_changed_summary_for_commit): 47 1 48 2012-09-04 Tommy Widenflycht <tommyw@google.com> 2 49 -
trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py
r127302 r127507 99 99 log("Warning: This machine is 64-bit, but the git binary (%s) does not support 64-bit.\nInstall a 64-bit git for better performance, see:\n%s\n" % (git_path, webkit_dev_thread_url)) 100 100 101 def _run_git(self, command_args, **kwargs): 102 full_command_args = [self.executable_name] + command_args 103 full_kwargs = kwargs 104 if not 'cwd' in full_kwargs: 105 full_kwargs['cwd'] = self.checkout_root 106 return self.run(full_command_args, **full_kwargs) 107 101 108 @classmethod 102 109 def in_working_directory(cls, path, executive=None): … … 110 117 def find_checkout_root(self, path): 111 118 # "git rev-parse --show-cdup" would be another way to get to the root 112 checkout_root = self._ executive.run_command([self.executable_name,'rev-parse', '--show-toplevel'], cwd=(path or "./")).strip()119 checkout_root = self._run_git(['rev-parse', '--show-toplevel'], cwd=(path or "./")).strip() 113 120 if not self._filesystem.isabs(checkout_root): # Sometimes git returns relative paths 114 121 checkout_root = self._filesystem.join(path, checkout_root) … … 134 141 135 142 def discard_local_commits(self): 136 # FIXME: This should probably use cwd=self.checkout_root 137 self.run([self.executable_name, 'reset', '--hard', self.remote_branch_ref()]) 143 self._run_git(['reset', '--hard', self.remote_branch_ref()]) 138 144 139 145 def local_commits(self): 140 return self. run([self.executable_name, 'log', '--pretty=oneline', 'HEAD...' + self.remote_branch_ref()], cwd=self.checkout_root).splitlines()146 return self._run_git(['log', '--pretty=oneline', 'HEAD...' + self.remote_branch_ref()]).splitlines() 141 147 142 148 def rebase_in_progress(self): … … 144 150 145 151 def working_directory_is_clean(self): 146 return self. run([self.executable_name, 'diff', 'HEAD', '--no-renames', '--name-only'], cwd=self.checkout_root) == ""152 return self._run_git(['diff', 'HEAD', '--no-renames', '--name-only']) == "" 147 153 148 154 def clean_working_directory(self): 149 # FIXME: These should probably use cwd=self.checkout_root.150 155 # Could run git clean here too, but that wouldn't match working_directory_is_clean 151 self. run([self.executable_name,'reset', '--hard', 'HEAD'])156 self._run_git(['reset', '--hard', 'HEAD']) 152 157 # Aborting rebase even though this does not match working_directory_is_clean 153 158 if self.rebase_in_progress(): 154 self. run([self.executable_name,'rebase', '--abort'])159 self._run_git(['rebase', '--abort']) 155 160 156 161 def status_command(self): … … 163 168 164 169 def add_list(self, paths, return_exit_code=False): 165 return self. run([self.executable_name,"add"] + paths, return_exit_code=return_exit_code)170 return self._run_git(["add"] + paths, return_exit_code=return_exit_code) 166 171 167 172 def delete_list(self, paths): 168 return self. run([self.executable_name,"rm", "-f"] + paths)173 return self._run_git(["rm", "-f"] + paths) 169 174 170 175 def exists(self, path): 171 return_code = self. run([self.executable_name,"show", "HEAD:%s" % path], return_exit_code=True, decode_output=False)176 return_code = self._run_git(["show", "HEAD:%s" % path], return_exit_code=True, decode_output=False) 172 177 return return_code != self.ERROR_FILE_IS_MISSING 173 178 … … 176 181 177 182 def _current_branch(self): 178 return self._branch_from_ref(self. run([self.executable_name, 'symbolic-ref', '-q', 'HEAD'], cwd=self.checkout_root).strip())183 return self._branch_from_ref(self._run_git(['symbolic-ref', '-q', 'HEAD']).strip()) 179 184 180 185 def _upstream_branch(self): … … 210 215 def _changes_files_for_commit(self, git_commit): 211 216 # --pretty="format:" makes git show not print the commit log header, 212 changed_files = self. run([self.executable_name,"show", "--pretty=format:", "--name-only", git_commit]).splitlines()217 changed_files = self._run_git(["show", "--pretty=format:", "--name-only", git_commit]).splitlines() 213 218 # instead it just prints a blank line at the top, so we skip the blank line: 214 219 return changed_files[1:] … … 224 229 225 230 # git rev-list head --remove-empty --limit=5 -- path would be equivalent. 226 commit_ids = self. run([self.executable_name,"log", "--remove-empty", "--pretty=format:%H", "-%s" % limit, "--", path]).splitlines()231 commit_ids = self._run_git(["log", "--remove-empty", "--pretty=format:%H", "-%s" % limit, "--", path]).splitlines() 227 232 return filter(lambda revision: revision, map(self.svn_revision_from_git_commit, commit_ids)) 228 233 … … 248 253 def svn_revision(self, path): 249 254 _log.debug('Running git.head_svn_revision... (Temporary logging message)') 250 git_log = self. run([self.executable_name,'log', '-25', path])255 git_log = self._run_git(['log', '-25', path]) 251 256 match = re.search("^\s*git-svn-id:.*@(?P<svn_revision>\d+)\ ", git_log, re.MULTILINE) 252 257 if not match: … … 281 286 def _run_git_svn_find_rev(self, arg): 282 287 # git svn find-rev always exits 0, even when the revision or commit is not found. 283 return self. run([self.executable_name, 'svn', 'find-rev', arg], cwd=self.checkout_root).rstrip()288 return self._run_git(['svn', 'find-rev', arg]).rstrip() 284 289 285 290 def _string_to_int_or_none(self, string): … … 305 310 """Returns a byte array (str()) containing the contents 306 311 of path @ revision in the repository.""" 307 return self. run([self.executable_name,"show", "%s:%s" % (self.git_commit_from_svn_revision(revision), path)], decode_output=False)312 return self._run_git(["show", "%s:%s" % (self.git_commit_from_svn_revision(revision), path)], decode_output=False) 308 313 309 314 def diff_for_revision(self, revision): … … 312 317 313 318 def diff_for_file(self, path, log=None): 314 return self. run([self.executable_name, 'diff', 'HEAD', '--no-renames', '--', path], cwd=self.checkout_root)319 return self._run_git(['diff', 'HEAD', '--no-renames', '--', path]) 315 320 316 321 def show_head(self, path): 317 return self. run([self.executable_name,'show', 'HEAD:' + self.to_object_name(path)], decode_output=False)322 return self._run_git(['show', 'HEAD:' + self.to_object_name(path)], decode_output=False) 318 323 319 324 def committer_email_for_revision(self, revision): 320 325 git_commit = self.git_commit_from_svn_revision(revision) 321 committer_email = self. run([self.executable_name,"log", "-1", "--pretty=format:%ce", git_commit])326 committer_email = self._run_git(["log", "-1", "--pretty=format:%ce", git_commit]) 322 327 # Git adds an extra @repository_hash to the end of every committer email, remove it: 323 328 return committer_email.rsplit("@", 1)[0] … … 327 332 git_commit = self.git_commit_from_svn_revision(revision) 328 333 # I think this will always fail due to ChangeLogs. 329 self. run([self.executable_name,'revert', '--no-commit', git_commit], error_handler=Executive.ignore_error)334 self._run_git(['revert', '--no-commit', git_commit], error_handler=Executive.ignore_error) 330 335 331 336 def revert_files(self, file_paths): 332 self. run([self.executable_name,'checkout', 'HEAD'] + file_paths)337 self._run_git(['checkout', 'HEAD'] + file_paths) 333 338 334 339 def _assert_can_squash(self, working_directory_is_clean): … … 364 369 if not force_squash: 365 370 self._assert_can_squash(working_directory_is_clean) 366 self. run([self.executable_name, 'reset', '--soft', self.remote_merge_base()], cwd=self.checkout_root)371 self._run_git(['reset', '--soft', self.remote_merge_base()]) 367 372 self.commit_locally_with_message(message) 368 373 return self.push_local_commits_to_server(username=username, password=password) … … 387 392 commit_succeeded = True 388 393 try: 389 self. run([self.executable_name,'checkout', '-q', '-b', MERGE_BRANCH_NAME, self.remote_branch_ref()])394 self._run_git(['checkout', '-q', '-b', MERGE_BRANCH_NAME, self.remote_branch_ref()]) 390 395 391 396 for commit in commit_ids: … … 394 399 # FIXME: Once changed_files and create_patch are modified to separately handle each 395 400 # commit in a commit range, commit each cherry pick so they'll get dcommitted separately. 396 self. run([self.executable_name,'cherry-pick', '--no-commit', commit])397 398 self. run([self.executable_name,'commit', '-m', message])401 self._run_git(['cherry-pick', '--no-commit', commit]) 402 403 self._run_git(['commit', '-m', message]) 399 404 output = self.push_local_commits_to_server(username=username, password=password) 400 405 except Exception, e: … … 405 410 # And then swap back to the original branch and clean up. 406 411 self.clean_working_directory() 407 self. run([self.executable_name,'checkout', '-q', branch_name])412 self._run_git(['checkout', '-q', branch_name]) 408 413 self.delete_branch(MERGE_BRANCH_NAME) 409 414 … … 412 417 def svn_commit_log(self, svn_revision): 413 418 svn_revision = self.strip_r_from_svn_revision(svn_revision) 414 return self. run([self.executable_name,'svn', 'log', '-r', svn_revision])419 return self._run_git(['svn', 'log', '-r', svn_revision]) 415 420 416 421 def last_svn_commit_log(self): 417 return self. run([self.executable_name,'svn', 'log', '--limit=1'])422 return self._run_git(['svn', 'log', '--limit=1']) 418 423 419 424 def svn_blame(self, path): 420 return self. run([self.executable_name,'svn', 'blame', path])425 return self._run_git(['svn', 'blame', path]) 421 426 422 427 # Git-specific methods: 423 428 def _branch_ref_exists(self, branch_ref): 424 return self. run([self.executable_name,'show-ref', '--quiet', '--verify', branch_ref], return_exit_code=True) == 0429 return self._run_git(['show-ref', '--quiet', '--verify', branch_ref], return_exit_code=True) == 0 425 430 426 431 def delete_branch(self, branch_name): 427 432 if self._branch_ref_exists('refs/heads/' + branch_name): 428 self. run([self.executable_name,'branch', '-D', branch_name])433 self._run_git(['branch', '-D', branch_name]) 429 434 430 435 def remote_merge_base(self): 431 return self. run([self.executable_name, 'merge-base', self.remote_branch_ref(), 'HEAD'], cwd=self.checkout_root).strip()436 return self._run_git(['merge-base', self.remote_branch_ref(), 'HEAD']).strip() 432 437 433 438 def remote_branch_ref(self): … … 446 451 447 452 def commit_locally_with_message(self, message): 448 self. run([self.executable_name, 'commit', '--all', '-F', '-'], input=message, cwd=self.checkout_root)453 self._run_git(['commit', '--all', '-F', '-'], input=message) 449 454 450 455 def push_local_commits_to_server(self, username=None, password=None): 451 dcommit_command = [ self.executable_name,'svn', 'dcommit']456 dcommit_command = ['svn', 'dcommit'] 452 457 if (not username or not password) and not self.has_authorization_for_realm(SVN.svn_server_realm): 453 458 raise AuthenticationError(SVN.svn_server_host, prompt_for_password=True) 454 459 if username: 455 460 dcommit_command.extend(["--username", username]) 456 output = self. run(dcommit_command, error_handler=commit_error_handler, input=password, cwd=self.checkout_root)461 output = self._run_git(dcommit_command, error_handler=commit_error_handler, input=password) 457 462 return output 458 463 … … 471 476 raise ScriptError(message="'...' is not supported (found in '%s'). Did you mean '..'?" % commitish) 472 477 elif '..' in commitish: 473 commit_ids += reversed(self. run([self.executable_name,'rev-list', commitish]).splitlines())478 commit_ids += reversed(self._run_git(['rev-list', commitish]).splitlines()) 474 479 else: 475 480 # Turn single commits or branch or tag names into commit ids. 476 commit_ids += self. run([self.executable_name,'rev-parse', '--revs-only', commitish]).splitlines()481 commit_ids += self._run_git(['rev-parse', '--revs-only', commitish]).splitlines() 477 482 return commit_ids 478 483 479 484 def commit_message_for_local_commit(self, commit_id): 480 commit_lines = self. run([self.executable_name,'cat-file', 'commit', commit_id]).splitlines()485 commit_lines = self._run_git(['cat-file', 'commit', commit_id]).splitlines() 481 486 482 487 # Skip the git headers. … … 489 494 490 495 def files_changed_summary_for_commit(self, commit_id): 491 return self. run([self.executable_name,'diff-tree', '--shortstat', '--no-renames', '--no-commit-id', commit_id])496 return self._run_git(['diff-tree', '--shortstat', '--no-renames', '--no-commit-id', commit_id])
Note: See TracChangeset
for help on using the changeset viewer.