blob: 6ec7158dcd948a36f6fa7b6d1b3aa5d3107f977d [file] [log] [blame]
David Pursehouse8898e2f2012-11-14 07:51:03 +09001#!/usr/bin/env python
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07002#
3# Copyright (C) 2008 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Sarah Owenscecd1d82012-11-01 22:59:27 -070017from __future__ import print_function
JoonCheol Parke9860722012-10-11 02:31:44 +090018import getpass
Conley Owensc9129d92012-10-01 16:12:28 -070019import imp
Shawn O. Pearcebd0312a2011-09-19 10:04:23 -070020import netrc
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070021import optparse
22import os
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070023import sys
Shawn O. Pearce3a0e7822011-09-22 17:06:41 -070024import time
David Pursehouse59bbb582013-05-17 10:49:33 +090025
26from pyversion import is_python3
27if is_python3():
Sarah Owens1f7627f2012-10-31 09:21:55 -070028 import urllib.request
29else:
David Pursehouse59bbb582013-05-17 10:49:33 +090030 import urllib2
Sarah Owens1f7627f2012-10-31 09:21:55 -070031 urllib = imp.new_module('urllib')
32 urllib.request = urllib2
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070033
Shawn O. Pearcead3193a2009-04-18 09:54:51 -070034from trace import SetTrace
Shawn O. Pearce334851e2011-09-19 08:05:31 -070035from git_command import git, GitCommand
Doug Anderson0048b692010-12-21 13:39:23 -080036from git_config import init_ssh, close_ssh
Shawn O. Pearcec95583b2009-03-03 17:47:06 -080037from command import InteractiveCommand
38from command import MirrorSafeCommand
Shawn O. Pearceecff4f12011-11-29 15:01:33 -080039from subcmds.version import Version
Shawn O. Pearce7965f9f2008-10-29 15:20:02 -070040from editor import Editor
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -070041from error import DownloadError
Shawn O. Pearce559b8462009-03-02 12:56:08 -080042from error import ManifestInvalidRevisionError
David Pursehouse0b8df7b2012-11-13 09:51:57 +090043from error import ManifestParseError
Conley Owens75ee0572012-11-15 17:33:11 -080044from error import NoManifestException
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070045from error import NoSuchProjectError
46from error import RepoChangedException
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -070047from manifest_xml import XmlManifest
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070048from pager import RunPager
Conley Owens094cdbe2014-01-30 15:09:59 -080049from wrapper import WrapperPath, Wrapper
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070050
David Pursehouse5c6eeac2012-10-11 16:44:48 +090051from subcmds import all_commands
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070052
David Pursehouse59bbb582013-05-17 10:49:33 +090053if not is_python3():
54 # pylint:disable=W0622
Chirayu Desai217ea7d2013-03-01 19:14:38 +053055 input = raw_input
David Pursehouse59bbb582013-05-17 10:49:33 +090056 # pylint:enable=W0622
Chirayu Desai217ea7d2013-03-01 19:14:38 +053057
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070058global_options = optparse.OptionParser(
59 usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]"
60 )
61global_options.add_option('-p', '--paginate',
62 dest='pager', action='store_true',
63 help='display command output in the pager')
64global_options.add_option('--no-pager',
65 dest='no_pager', action='store_true',
66 help='disable the pager')
Shawn O. Pearce0ed2bd12009-03-09 18:26:31 -070067global_options.add_option('--trace',
68 dest='trace', action='store_true',
69 help='trace git command execution')
Shawn O. Pearce3a0e7822011-09-22 17:06:41 -070070global_options.add_option('--time',
71 dest='time', action='store_true',
72 help='time repo command execution')
Shawn O. Pearce47c1a632009-03-02 18:24:23 -080073global_options.add_option('--version',
74 dest='show_version', action='store_true',
75 help='display this version of repo')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070076
77class _Repo(object):
78 def __init__(self, repodir):
79 self.repodir = repodir
80 self.commands = all_commands
Mike Lockwood2bf9db02009-07-14 15:23:39 -040081 # add 'branch' as an alias for 'branches'
82 all_commands['branch'] = all_commands['branches']
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070083
84 def _Run(self, argv):
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -040085 result = 0
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070086 name = None
87 glob = []
88
Sarah Owensa6053d52012-11-01 13:36:50 -070089 for i in range(len(argv)):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070090 if not argv[i].startswith('-'):
91 name = argv[i]
92 if i > 0:
93 glob = argv[:i]
94 argv = argv[i + 1:]
95 break
96 if not name:
97 glob = argv
98 name = 'help'
99 argv = []
David Pursehouse8a68ff92012-09-24 12:15:13 +0900100 gopts, _gargs = global_options.parse_args(glob)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700101
Shawn O. Pearce0ed2bd12009-03-09 18:26:31 -0700102 if gopts.trace:
Shawn O. Pearcead3193a2009-04-18 09:54:51 -0700103 SetTrace()
Shawn O. Pearce47c1a632009-03-02 18:24:23 -0800104 if gopts.show_version:
105 if name == 'help':
106 name = 'version'
107 else:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700108 print('fatal: invalid usage of --version', file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400109 return 1
Shawn O. Pearce47c1a632009-03-02 18:24:23 -0800110
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700111 try:
112 cmd = self.commands[name]
113 except KeyError:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700114 print("repo: '%s' is not a repo command. See 'repo help'." % name,
115 file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400116 return 1
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700117
118 cmd.repodir = self.repodir
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -0700119 cmd.manifest = XmlManifest(cmd.repodir)
Shawn O. Pearce7965f9f2008-10-29 15:20:02 -0700120 Editor.globalConfig = cmd.manifest.globalConfig
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700121
Shawn O. Pearcec95583b2009-03-03 17:47:06 -0800122 if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700123 print("fatal: '%s' requires a working directory" % name,
124 file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400125 return 1
Shawn O. Pearcec95583b2009-03-03 17:47:06 -0800126
Shawn O. Pearcedb45da12009-04-18 13:49:13 -0700127 copts, cargs = cmd.OptionParser.parse_args(argv)
David Pursehouseb148ac92012-11-16 09:33:39 +0900128 copts = cmd.ReadEnvironmentOptions(copts)
Shawn O. Pearcedb45da12009-04-18 13:49:13 -0700129
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700130 if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
131 config = cmd.manifest.globalConfig
132 if gopts.pager:
133 use_pager = True
134 else:
135 use_pager = config.GetBoolean('pager.%s' % name)
136 if use_pager is None:
Shawn O. Pearcedb45da12009-04-18 13:49:13 -0700137 use_pager = cmd.WantPager(copts)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700138 if use_pager:
139 RunPager(config)
140
Conley Owens7ba25be2012-11-14 14:18:06 -0800141 start = time.time()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700142 try:
Conley Owens7ba25be2012-11-14 14:18:06 -0800143 result = cmd.Execute(copts, cargs)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700144 except DownloadError as e:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700145 print('error: %s' % str(e), file=sys.stderr)
Conley Owens7ba25be2012-11-14 14:18:06 -0800146 result = 1
Sarah Owensa5be53f2012-09-09 15:37:57 -0700147 except ManifestInvalidRevisionError as e:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700148 print('error: %s' % str(e), file=sys.stderr)
Conley Owens7ba25be2012-11-14 14:18:06 -0800149 result = 1
Conley Owens75ee0572012-11-15 17:33:11 -0800150 except NoManifestException as e:
151 print('error: manifest required for this command -- please run init',
152 file=sys.stderr)
153 result = 1
Sarah Owensa5be53f2012-09-09 15:37:57 -0700154 except NoSuchProjectError as e:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700155 if e.name:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700156 print('error: project %s not found' % e.name, file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700157 else:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700158 print('error: no project in current directory', file=sys.stderr)
Conley Owens7ba25be2012-11-14 14:18:06 -0800159 result = 1
160 finally:
161 elapsed = time.time() - start
162 hours, remainder = divmod(elapsed, 3600)
163 minutes, seconds = divmod(remainder, 60)
164 if gopts.time:
165 if hours == 0:
166 print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr)
167 else:
168 print('real\t%dh%dm%.3fs' % (hours, minutes, seconds),
169 file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400170
171 return result
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700172
Conley Owens094cdbe2014-01-30 15:09:59 -0800173
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700174def _MyRepoPath():
175 return os.path.dirname(__file__)
176
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700177
178def _CheckWrapperVersion(ver, repo_path):
179 if not repo_path:
180 repo_path = '~/bin/repo'
181
182 if not ver:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700183 print('no --wrapper-version argument', file=sys.stderr)
David Pursehouse8a68ff92012-09-24 12:15:13 +0900184 sys.exit(1)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700185
Conley Owens094cdbe2014-01-30 15:09:59 -0800186 exp = Wrapper().VERSION
David Pursehouse7e6dd2d2012-10-25 12:40:51 +0900187 ver = tuple(map(int, ver.split('.')))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700188 if len(ver) == 1:
189 ver = (0, ver[0])
190
David Pursehouse7e6dd2d2012-10-25 12:40:51 +0900191 exp_str = '.'.join(map(str, exp))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700192 if exp[0] > ver[0] or ver < (0, 4):
Sarah Owenscecd1d82012-11-01 22:59:27 -0700193 print("""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700194!!! A new repo command (%5s) is available. !!!
195!!! You must upgrade before you can continue: !!!
196
197 cp %s %s
Conley Owens094cdbe2014-01-30 15:09:59 -0800198""" % (exp_str, WrapperPath(), repo_path), file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700199 sys.exit(1)
200
201 if exp > ver:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700202 print("""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700203... A new repo command (%5s) is available.
204... You should upgrade soon:
205
206 cp %s %s
Conley Owens094cdbe2014-01-30 15:09:59 -0800207""" % (exp_str, WrapperPath(), repo_path), file=sys.stderr)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700208
Mickaël Salaün2f6ab7f2012-09-30 00:37:55 +0200209def _CheckRepoDir(repo_dir):
210 if not repo_dir:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700211 print('no --repo-dir argument', file=sys.stderr)
David Pursehouse8a68ff92012-09-24 12:15:13 +0900212 sys.exit(1)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700213
214def _PruneOptions(argv, opt):
215 i = 0
216 while i < len(argv):
217 a = argv[i]
218 if a == '--':
219 break
220 if a.startswith('--'):
221 eq = a.find('=')
222 if eq > 0:
223 a = a[0:eq]
224 if not opt.has_option(a):
225 del argv[i]
226 continue
227 i += 1
228
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700229_user_agent = None
230
231def _UserAgent():
232 global _user_agent
233
234 if _user_agent is None:
235 py_version = sys.version_info
236
237 os_name = sys.platform
238 if os_name == 'linux2':
239 os_name = 'Linux'
240 elif os_name == 'win32':
241 os_name = 'Win32'
242 elif os_name == 'cygwin':
243 os_name = 'Cygwin'
244 elif os_name == 'darwin':
245 os_name = 'Darwin'
246
247 p = GitCommand(
248 None, ['describe', 'HEAD'],
249 cwd = _MyRepoPath(),
250 capture_stdout = True)
251 if p.Wait() == 0:
252 repo_version = p.stdout
253 if len(repo_version) > 0 and repo_version[-1] == '\n':
254 repo_version = repo_version[0:-1]
255 if len(repo_version) > 0 and repo_version[0] == 'v':
256 repo_version = repo_version[1:]
257 else:
258 repo_version = 'unknown'
259
260 _user_agent = 'git-repo/%s (%s) git/%s Python/%d.%d.%d' % (
261 repo_version,
262 os_name,
David Pursehouse7e6dd2d2012-10-25 12:40:51 +0900263 '.'.join(map(str, git.version_tuple())),
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700264 py_version[0], py_version[1], py_version[2])
265 return _user_agent
266
Sarah Owens1f7627f2012-10-31 09:21:55 -0700267class _UserAgentHandler(urllib.request.BaseHandler):
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700268 def http_request(self, req):
269 req.add_header('User-Agent', _UserAgent())
270 return req
271
272 def https_request(self, req):
273 req.add_header('User-Agent', _UserAgent())
274 return req
275
JoonCheol Parke9860722012-10-11 02:31:44 +0900276def _AddPasswordFromUserInput(handler, msg, req):
David Pursehousec1b86a22012-11-14 11:36:51 +0900277 # If repo could not find auth info from netrc, try to get it from user input
278 url = req.get_full_url()
279 user, password = handler.passwd.find_user_password(None, url)
280 if user is None:
281 print(msg)
282 try:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530283 user = input('User: ')
David Pursehousec1b86a22012-11-14 11:36:51 +0900284 password = getpass.getpass()
285 except KeyboardInterrupt:
286 return
287 handler.passwd.add_password(None, url, user, password)
JoonCheol Parke9860722012-10-11 02:31:44 +0900288
Sarah Owens1f7627f2012-10-31 09:21:55 -0700289class _BasicAuthHandler(urllib.request.HTTPBasicAuthHandler):
JoonCheol Parke9860722012-10-11 02:31:44 +0900290 def http_error_401(self, req, fp, code, msg, headers):
291 _AddPasswordFromUserInput(self, msg, req)
Sarah Owens1f7627f2012-10-31 09:21:55 -0700292 return urllib.request.HTTPBasicAuthHandler.http_error_401(
JoonCheol Parke9860722012-10-11 02:31:44 +0900293 self, req, fp, code, msg, headers)
294
Shawn O. Pearcefab96c62011-10-11 12:00:38 -0700295 def http_error_auth_reqed(self, authreq, host, req, headers):
296 try:
Shawn O. Pearcedf5ee522011-10-11 14:05:21 -0700297 old_add_header = req.add_header
298 def _add_header(name, val):
299 val = val.replace('\n', '')
300 old_add_header(name, val)
301 req.add_header = _add_header
Sarah Owens1f7627f2012-10-31 09:21:55 -0700302 return urllib.request.AbstractBasicAuthHandler.http_error_auth_reqed(
Shawn O. Pearcefab96c62011-10-11 12:00:38 -0700303 self, authreq, host, req, headers)
304 except:
Shawn O. Pearcedf5ee522011-10-11 14:05:21 -0700305 reset = getattr(self, 'reset_retry_count', None)
306 if reset is not None:
307 reset()
Shawn O. Pearceb6605392011-10-11 15:58:07 -0700308 elif getattr(self, 'retried', None):
309 self.retried = 0
Shawn O. Pearcefab96c62011-10-11 12:00:38 -0700310 raise
311
Sarah Owens1f7627f2012-10-31 09:21:55 -0700312class _DigestAuthHandler(urllib.request.HTTPDigestAuthHandler):
JoonCheol Parke9860722012-10-11 02:31:44 +0900313 def http_error_401(self, req, fp, code, msg, headers):
314 _AddPasswordFromUserInput(self, msg, req)
Sarah Owens1f7627f2012-10-31 09:21:55 -0700315 return urllib.request.HTTPDigestAuthHandler.http_error_401(
JoonCheol Parke9860722012-10-11 02:31:44 +0900316 self, req, fp, code, msg, headers)
317
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800318 def http_error_auth_reqed(self, auth_header, host, req, headers):
319 try:
320 old_add_header = req.add_header
321 def _add_header(name, val):
322 val = val.replace('\n', '')
323 old_add_header(name, val)
324 req.add_header = _add_header
Sarah Owens1f7627f2012-10-31 09:21:55 -0700325 return urllib.request.AbstractDigestAuthHandler.http_error_auth_reqed(
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800326 self, auth_header, host, req, headers)
327 except:
328 reset = getattr(self, 'reset_retry_count', None)
329 if reset is not None:
330 reset()
331 elif getattr(self, 'retried', None):
332 self.retried = 0
333 raise
334
Shawn O. Pearce014d0602011-09-11 12:57:15 -0700335def init_http():
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700336 handlers = [_UserAgentHandler()]
337
Sarah Owens1f7627f2012-10-31 09:21:55 -0700338 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
Shawn O. Pearcebd0312a2011-09-19 10:04:23 -0700339 try:
340 n = netrc.netrc()
341 for host in n.hosts:
342 p = n.hosts[host]
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800343 mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
344 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
Shawn O. Pearcebd0312a2011-09-19 10:04:23 -0700345 except netrc.NetrcParseError:
346 pass
Shawn O. Pearce7b947de2011-09-23 11:50:31 -0700347 except IOError:
348 pass
Shawn O. Pearcefab96c62011-10-11 12:00:38 -0700349 handlers.append(_BasicAuthHandler(mgr))
Xiaodong Xuae0a36c2012-01-31 11:10:09 +0800350 handlers.append(_DigestAuthHandler(mgr))
Shawn O. Pearcebd0312a2011-09-19 10:04:23 -0700351
Shawn O. Pearce014d0602011-09-11 12:57:15 -0700352 if 'http_proxy' in os.environ:
353 url = os.environ['http_proxy']
Sarah Owens1f7627f2012-10-31 09:21:55 -0700354 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
Shawn O. Pearce334851e2011-09-19 08:05:31 -0700355 if 'REPO_CURL_VERBOSE' in os.environ:
Sarah Owens1f7627f2012-10-31 09:21:55 -0700356 handlers.append(urllib.request.HTTPHandler(debuglevel=1))
357 handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
358 urllib.request.install_opener(urllib.request.build_opener(*handlers))
Shawn O. Pearce014d0602011-09-11 12:57:15 -0700359
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700360def _Main(argv):
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400361 result = 0
362
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700363 opt = optparse.OptionParser(usage="repo wrapperinfo -- ...")
364 opt.add_option("--repo-dir", dest="repodir",
365 help="path to .repo/")
366 opt.add_option("--wrapper-version", dest="wrapper_version",
367 help="version of the wrapper script")
368 opt.add_option("--wrapper-path", dest="wrapper_path",
369 help="location of the wrapper script")
370 _PruneOptions(argv, opt)
371 opt, argv = opt.parse_args(argv)
372
373 _CheckWrapperVersion(opt.wrapper_version, opt.wrapper_path)
374 _CheckRepoDir(opt.repodir)
375
Shawn O. Pearceecff4f12011-11-29 15:01:33 -0800376 Version.wrapper_version = opt.wrapper_version
377 Version.wrapper_path = opt.wrapper_path
378
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700379 repo = _Repo(opt.repodir)
380 try:
Shawn O. Pearcefb231612009-04-10 18:53:46 -0700381 try:
Doug Anderson0048b692010-12-21 13:39:23 -0800382 init_ssh()
Shawn O. Pearce014d0602011-09-11 12:57:15 -0700383 init_http()
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400384 result = repo._Run(argv) or 0
Shawn O. Pearcefb231612009-04-10 18:53:46 -0700385 finally:
386 close_ssh()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700387 except KeyboardInterrupt:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700388 print('aborted by user', file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400389 result = 1
David Pursehouse0b8df7b2012-11-13 09:51:57 +0900390 except ManifestParseError as mpe:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700391 print('fatal: %s' % mpe, file=sys.stderr)
David Pursehouse0b8df7b2012-11-13 09:51:57 +0900392 result = 1
Sarah Owensa5be53f2012-09-09 15:37:57 -0700393 except RepoChangedException as rce:
Shawn O. Pearcec9ef7442008-11-03 10:32:09 -0800394 # If repo changed, re-exec ourselves.
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700395 #
Shawn O. Pearcec9ef7442008-11-03 10:32:09 -0800396 argv = list(sys.argv)
397 argv.extend(rce.extra_args)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700398 try:
Shawn O. Pearcec9ef7442008-11-03 10:32:09 -0800399 os.execv(__file__, argv)
Sarah Owensa5be53f2012-09-09 15:37:57 -0700400 except OSError as e:
Sarah Owenscecd1d82012-11-01 22:59:27 -0700401 print('fatal: cannot restart repo after upgrade', file=sys.stderr)
402 print('fatal: %s' % e, file=sys.stderr)
Daniel Sandler3ce2a6b2011-04-29 09:59:12 -0400403 result = 128
404
405 sys.exit(result)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700406
407if __name__ == '__main__':
408 _Main(sys.argv[1:])