OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import collections | 5 import collections |
6 import errno | 6 import errno |
7 import fnmatch | 7 import fnmatch |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import subprocess | 10 import subprocess |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 assert 'stdin' not in kwargs | 129 assert 'stdin' not in kwargs |
130 kwargs['stdin'] = subprocess.PIPE | 130 kwargs['stdin'] = subprocess.PIPE |
131 ok_ret = kwargs.pop('ok_ret', {0}) | 131 ok_ret = kwargs.pop('ok_ret', {0}) |
132 cmd = ('git',) + args | 132 cmd = ('git',) + args |
133 | 133 |
134 self._log.debug('Running %r', cmd) | 134 self._log.debug('Running %r', cmd) |
135 started = time.time() | 135 started = time.time() |
136 process = subprocess.Popen(cmd, **kwargs) | 136 process = subprocess.Popen(cmd, **kwargs) |
137 output, errout = process.communicate(indata) | 137 output, errout = process.communicate(indata) |
138 retcode = process.poll() | 138 retcode = process.poll() |
139 self._log.debug('Finished in %.1f sec', time.time() - started) | 139 dt = time.time() - started |
| 140 if dt > 1: # pragma: no cover |
| 141 self._log.debug('Finished in %.1f sec', dt) |
140 if retcode not in ok_ret: | 142 if retcode not in ok_ret: |
141 raise CalledProcessError(retcode, cmd, output, errout) | 143 raise CalledProcessError(retcode, cmd, output, errout) |
142 | 144 |
143 if errout: | 145 if errout: |
144 sys.stderr.write(errout) | 146 sys.stderr.write(errout) |
145 return output | 147 return output |
146 | 148 |
147 def intern(self, data, typ='blob'): | 149 def intern(self, data, typ='blob'): |
148 return self.run( | 150 return self.run( |
149 'hash-object', '-w', '-t', typ, '--stdin', indata=str(data)).strip() | 151 'hash-object', '-w', '-t', typ, '--stdin', indata=str(data)).strip() |
| 152 |
| 153 def fast_forward_push(self, refs_and_commits): |
| 154 """Push commits to refs on the remote, and also update refs' local copies. |
| 155 |
| 156 Refs names are specified as refs on remote, i.e. push to |
| 157 Ref('refs/heads/master') would update 'refs/heads/master' on remote (and on |
| 158 local repo mirror), no ref name translation is happening. |
| 159 |
| 160 Args: |
| 161 refs_and_commits: dict {Ref object -> Commit to push to the ref}. |
| 162 """ |
| 163 refspec = [ |
| 164 '%s:%s' % (c.hsh, r.ref) |
| 165 for r, c in refs_and_commits.iteritems() |
| 166 ] |
| 167 self.run('push', 'origin', *refspec) |
| 168 for r, c in refs_and_commits.iteritems(): |
| 169 r.update_to(c) |
OLD | NEW |