Chromium Code Reviews| Index: checkout.py |
| diff --git a/checkout.py b/checkout.py |
| index 450b37973c0e0c702fe328e8f2759986b8b08fcf..aaad9099c2badd0d6b4523cde06a7fd9a4887bb3 100644 |
| --- a/checkout.py |
| +++ b/checkout.py |
| @@ -571,57 +571,33 @@ class GitCheckout(CheckoutBase): |
| Checks it out if not present and deletes the working branch. |
| """ |
| - assert self.remote_branch |
| assert self.git_url |
| + assert self.remote_branch |
| + |
| + self._check_call_git( |
| + ['cache', 'populate', self.git_url], timeout=FETCH_TIMEOUT) |
|
rmistry
2014/02/25 13:23:14
Disclaimer: I have never used git cache before.
D
|
| + cache_path = self._check_output_git( |
| + ['cache', 'exists', self.git_url]).strip() |
| if not os.path.isdir(self.project_path): |
| # Clone the repo if the directory is not present. |
| - logging.info( |
| - 'Checking out %s in %s', self.project_name, self.project_path) |
| self._check_call_git( |
| - ['clone', self.git_url, '-b', self.remote_branch, self.project_path], |
| + ['clone', '--shared', cache_path, self.project_path], |
| cwd=None, timeout=FETCH_TIMEOUT) |
| - else: |
| - # Throw away all uncommitted changes in the existing checkout. |
| - self._check_call_git(['checkout', self.remote_branch]) |
| - self._check_call_git( |
| - ['reset', '--hard', '--quiet', |
| - '%s/%s' % (self.remote, self.remote_branch)]) |
| - if revision: |
| - try: |
| - # Look if the commit hash already exist. If so, we can skip a |
| - # 'git fetch' call. |
| - revision = self._check_output_git(['rev-parse', revision]) |
| - except subprocess.CalledProcessError: |
| - self._check_call_git( |
| - ['fetch', self.remote, self.remote_branch, '--quiet']) |
| - revision = self._check_output_git(['rev-parse', revision]) |
| - self._check_call_git(['checkout', '--force', '--quiet', revision]) |
| - else: |
| - branches, active = self._branches() |
| - if active != self.master_branch: |
| - self._check_call_git( |
| - ['checkout', '--force', '--quiet', self.master_branch]) |
| - self._sync_remote_branch() |
| - |
| - if self.working_branch in branches: |
| - self._call_git(['branch', '-D', self.working_branch]) |
| - return self._get_head_commit_hash() |
| + if not revision: |
| + revision = self.remote_branch |
| - def _sync_remote_branch(self): |
| - """Syncs the remote branch.""" |
| - # We do a 'git pull origin master:refs/remotes/origin/master' instead of |
| - # 'git pull origin master' because from the manpage for git-pull: |
| - # A parameter <ref> without a colon is equivalent to <ref>: when |
| - # pulling/fetching, so it merges <ref> into the current branch without |
| - # storing the remote branch anywhere locally. |
| - remote_tracked_path = 'refs/remotes/%s/%s' % ( |
| - self.remote, self.remote_branch) |
| - self._check_call_git( |
| - ['pull', self.remote, |
| - '%s:%s' % (self.remote_branch, remote_tracked_path), |
| - '--quiet']) |
| + self._check_call_git(['fetch', self.remote, revision]) |
| + |
| + self._check_call_git(['checkout', '--force', '--quiet', revision]) |
| + self._call_git(['clean', '-fdx']) |
| + |
| + branches, _ = self._branches() |
| + if self.working_branch in branches: |
| + self._call_git(['branch', '-D', self.working_branch]) |
| + |
| + return self._get_head_commit_hash() |
| def _get_head_commit_hash(self): |
| """Gets the current revision (in unicode) from the local branch.""" |
| @@ -724,7 +700,7 @@ class GitCheckout(CheckoutBase): |
| current_branch = self._check_output_git( |
| ['rev-parse', '--abbrev-ref', 'HEAD']).strip() |
| assert current_branch == self.working_branch |
| - |
| + |
| commit_cmd = ['commit', '--amend', '-m', commit_message] |
| if user and user != self.commit_user: |
| # We do not have the first or last name of the user, grab the username |