| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """This module contains utilities for managing gclient checkouts.""" | 6 """This module contains utilities for managing gclient checkouts.""" |
| 7 | 7 |
| 8 | 8 |
| 9 from common import find_depot_tools | 9 from common import find_depot_tools |
| 10 | 10 |
| 11 import os | 11 import os |
| 12 import shell_utils | 12 import shell_utils |
| 13 import subprocess | |
| 14 import time | |
| 15 | 13 |
| 16 | 14 |
| 17 GIT = 'git.bat' if os.name == 'nt' else 'git' | 15 GIT = 'git.bat' if os.name == 'nt' else 'git' |
| 18 WHICH = 'where' if os.name == 'nt' else 'which' | 16 WHICH = 'where' if os.name == 'nt' else 'which' |
| 19 SKIA_TRUNK = 'skia' | 17 SKIA_TRUNK = 'skia' |
| 20 | 18 |
| 21 | 19 |
| 22 def _GetGclientPy(): | 20 def _GetGclientPy(): |
| 23 """ Return the path to the gclient.py file. """ | 21 """ Return the path to the gclient.py file. """ |
| 24 path_to_gclient = find_depot_tools.add_depot_tools_to_path() | 22 path_to_gclient = find_depot_tools.add_depot_tools_to_path() |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 86 |
| 89 def GetCheckedOutHash(): | 87 def GetCheckedOutHash(): |
| 90 """ Determine what commit we actually got. If there are local modifications, | 88 """ Determine what commit we actually got. If there are local modifications, |
| 91 raise an exception. """ | 89 raise an exception. """ |
| 92 config = _GetLocalConfig() | 90 config = _GetLocalConfig() |
| 93 current_directory = os.path.abspath(os.curdir) | 91 current_directory = os.path.abspath(os.curdir) |
| 94 | 92 |
| 95 # Get the checked-out commit hash for the first gclient solution. | 93 # Get the checked-out commit hash for the first gclient solution. |
| 96 os.chdir(config[0]['name']) | 94 os.chdir(config[0]['name']) |
| 97 try: | 95 try: |
| 98 for i in xrange(30): | 96 # "git rev-parse HEAD" returns the commit hash for HEAD. |
| 99 # "git rev-parse HEAD" returns the commit hash for HEAD. | 97 return shell_utils.Bash([GIT, 'rev-parse', 'HEAD'], |
| 100 cmd = [GIT, 'rev-parse', 'HEAD'] | 98 log_in_real_time=False).rstrip('\n') |
| 101 print cmd | |
| 102 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, | |
| 103 stderr=subprocess.STDOUT) | |
| 104 if proc.wait() == 0: | |
| 105 commit_hash = proc.communicate()[0].rstrip('\n') | |
| 106 print commit_hash | |
| 107 if commit_hash: | |
| 108 # Break out of the retry loop if we have a non-empty commit hash. | |
| 109 break | |
| 110 else: | |
| 111 print 'Command exited with non-zero code.' | |
| 112 # Sleep for 1 second and hope the next iteration finds the commit hash. | |
| 113 print 'Could not find a non-empty commit_hash, retrying.. #%s' % (i + 1) | |
| 114 time.sleep(1) | |
| 115 finally: | 99 finally: |
| 116 os.chdir(current_directory) | 100 os.chdir(current_directory) |
| 117 return commit_hash | |
| 118 | 101 |
| 119 | 102 |
| 120 def Revert(): | 103 def Revert(): |
| 121 shell_utils.Bash([GIT, 'clean', '-f', '-d']) | 104 shell_utils.Bash([GIT, 'clean', '-f', '-d']) |
| 122 shell_utils.Bash([GIT, 'reset', '--hard', 'HEAD']) | 105 shell_utils.Bash([GIT, 'reset', '--hard', 'HEAD']) |
| OLD | NEW |