Changeset 127507 in webkit


Ignore:
Timestamp:
Sep 4, 2012 2:23:01 PM (12 years ago)
Author:
satish@chromium.org
Message:

Run git commands within the checkout directory
https://bugs.webkit.org/show_bug.cgi?id=95742

Reviewed by Eric Seidel.

git commands run from scm/git.py are sometimes run with cwd set to the
checkout_root and other times with whatever directory was the default cwd.
Instead all these should run with the checkout root set as the cwd
(except where we explicitly need a different path)

  • Scripts/webkitpy/common/checkout/scm/git.py:

(Git._run_git):
(Git.find_checkout_root):
(Git.discard_local_commits):
(Git.local_commits):
(Git.working_directory_is_clean):
(Git.clean_working_directory):
(Git.add_list):
(Git.delete_list):
(Git.exists):
(Git._current_branch):
(Git._changes_files_for_commit):
(Git.revisions_changing_file):
(Git.svn_revision):
(Git._run_git_svn_find_rev):
(Git.contents_at_revision):
(Git.diff_for_file):
(Git.show_head):
(Git.committer_email_for_revision):
(Git.apply_reverse_diff):
(Git.revert_files):
(Git.commit_with_message):
(Git._commit_on_branch):
(Git.svn_commit_log):
(Git.last_svn_commit_log):
(Git.svn_blame):
(Git._branch_ref_exists):
(Git.delete_branch):
(Git.remote_merge_base):
(Git.commit_locally_with_message):
(Git.push_local_commits_to_server):
(Git.commit_ids_from_commitish_arguments):
(Git.commit_message_for_local_commit):
(Git.files_changed_summary_for_commit):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r127501 r127507  
     12012-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
    1482012-09-04  Tommy Widenflycht  <tommyw@google.com>
    249
  • trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py

    r127302 r127507  
    9999        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))
    100100
     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
    101108    @classmethod
    102109    def in_working_directory(cls, path, executive=None):
     
    110117    def find_checkout_root(self, path):
    111118        # "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()
    113120        if not self._filesystem.isabs(checkout_root):  # Sometimes git returns relative paths
    114121            checkout_root = self._filesystem.join(path, checkout_root)
     
    134141
    135142    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()])
    138144
    139145    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()
    141147
    142148    def rebase_in_progress(self):
     
    144150
    145151    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']) == ""
    147153
    148154    def clean_working_directory(self):
    149         # FIXME: These should probably use cwd=self.checkout_root.
    150155        # 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'])
    152157        # Aborting rebase even though this does not match working_directory_is_clean
    153158        if self.rebase_in_progress():
    154             self.run([self.executable_name, 'rebase', '--abort'])
     159            self._run_git(['rebase', '--abort'])
    155160
    156161    def status_command(self):
     
    163168
    164169    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)
    166171
    167172    def delete_list(self, paths):
    168         return self.run([self.executable_name, "rm", "-f"] + paths)
     173        return self._run_git(["rm", "-f"] + paths)
    169174
    170175    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)
    172177        return return_code != self.ERROR_FILE_IS_MISSING
    173178
     
    176181
    177182    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())
    179184
    180185    def _upstream_branch(self):
     
    210215    def _changes_files_for_commit(self, git_commit):
    211216        # --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()
    213218        # instead it just prints a blank line at the top, so we skip the blank line:
    214219        return changed_files[1:]
     
    224229
    225230        # 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()
    227232        return filter(lambda revision: revision, map(self.svn_revision_from_git_commit, commit_ids))
    228233
     
    248253    def svn_revision(self, path):
    249254        _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])
    251256        match = re.search("^\s*git-svn-id:.*@(?P<svn_revision>\d+)\ ", git_log, re.MULTILINE)
    252257        if not match:
     
    281286    def _run_git_svn_find_rev(self, arg):
    282287        # 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()
    284289
    285290    def _string_to_int_or_none(self, string):
     
    305310        """Returns a byte array (str()) containing the contents
    306311        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)
    308313
    309314    def diff_for_revision(self, revision):
     
    312317
    313318    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])
    315320
    316321    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)
    318323
    319324    def committer_email_for_revision(self, revision):
    320325        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])
    322327        # Git adds an extra @repository_hash to the end of every committer email, remove it:
    323328        return committer_email.rsplit("@", 1)[0]
     
    327332        git_commit = self.git_commit_from_svn_revision(revision)
    328333        # 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)
    330335
    331336    def revert_files(self, file_paths):
    332         self.run([self.executable_name, 'checkout', 'HEAD'] + file_paths)
     337        self._run_git(['checkout', 'HEAD'] + file_paths)
    333338
    334339    def _assert_can_squash(self, working_directory_is_clean):
     
    364369        if not force_squash:
    365370            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()])
    367372        self.commit_locally_with_message(message)
    368373        return self.push_local_commits_to_server(username=username, password=password)
     
    387392        commit_succeeded = True
    388393        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()])
    390395
    391396            for commit in commit_ids:
     
    394399                # FIXME: Once changed_files and create_patch are modified to separately handle each
    395400                # 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])
    399404            output = self.push_local_commits_to_server(username=username, password=password)
    400405        except Exception, e:
     
    405410            # And then swap back to the original branch and clean up.
    406411            self.clean_working_directory()
    407             self.run([self.executable_name, 'checkout', '-q', branch_name])
     412            self._run_git(['checkout', '-q', branch_name])
    408413            self.delete_branch(MERGE_BRANCH_NAME)
    409414
     
    412417    def svn_commit_log(self, svn_revision):
    413418        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])
    415420
    416421    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'])
    418423
    419424    def svn_blame(self, path):
    420         return self.run([self.executable_name, 'svn', 'blame', path])
     425        return self._run_git(['svn', 'blame', path])
    421426
    422427    # Git-specific methods:
    423428    def _branch_ref_exists(self, branch_ref):
    424         return self.run([self.executable_name, 'show-ref', '--quiet', '--verify', branch_ref], return_exit_code=True) == 0
     429        return self._run_git(['show-ref', '--quiet', '--verify', branch_ref], return_exit_code=True) == 0
    425430
    426431    def delete_branch(self, branch_name):
    427432        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])
    429434
    430435    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()
    432437
    433438    def remote_branch_ref(self):
     
    446451
    447452    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)
    449454
    450455    def push_local_commits_to_server(self, username=None, password=None):
    451         dcommit_command = [self.executable_name, 'svn', 'dcommit']
     456        dcommit_command = ['svn', 'dcommit']
    452457        if (not username or not password) and not self.has_authorization_for_realm(SVN.svn_server_realm):
    453458            raise AuthenticationError(SVN.svn_server_host, prompt_for_password=True)
    454459        if username:
    455460            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)
    457462        return output
    458463
     
    471476                raise ScriptError(message="'...' is not supported (found in '%s'). Did you mean '..'?" % commitish)
    472477            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())
    474479            else:
    475480                # 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()
    477482        return commit_ids
    478483
    479484    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()
    481486
    482487        # Skip the git headers.
     
    489494
    490495    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.