The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 16 | from __future__ import print_function |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 17 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 18 | import os |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 19 | import pickle |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | import re |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 21 | import subprocess |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | import sys |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 23 | try: |
| 24 | import threading as _threading |
| 25 | except ImportError: |
| 26 | import dummy_threading as _threading |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 27 | import time |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 28 | |
| 29 | from pyversion import is_python3 |
| 30 | if is_python3(): |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 31 | import urllib.request |
| 32 | import urllib.error |
| 33 | else: |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 34 | import urllib2 |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 35 | import imp |
| 36 | urllib = imp.new_module('urllib') |
| 37 | urllib.request = urllib2 |
| 38 | urllib.error = urllib2 |
Shawn O. Pearce | f00e0ce | 2009-08-22 18:39:49 -0700 | [diff] [blame] | 39 | |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 40 | from signal import SIGTERM |
Shawn O. Pearce | b54a392 | 2009-01-05 16:18:58 -0800 | [diff] [blame] | 41 | from error import GitError, UploadError |
Shawn O. Pearce | ad3193a | 2009-04-18 09:54:51 -0700 | [diff] [blame] | 42 | from trace import Trace |
David Pursehouse | ecf8f2b | 2013-05-24 12:12:23 +0900 | [diff] [blame^] | 43 | if is_python3(): |
| 44 | from http.client import HTTPException |
| 45 | else: |
| 46 | from httplib import HTTPException |
Shawn O. Pearce | ca8c32c | 2010-05-11 18:21:33 -0700 | [diff] [blame] | 47 | |
| 48 | from git_command import GitCommand |
| 49 | from git_command import ssh_sock |
| 50 | from git_command import terminate_ssh_clients |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 51 | |
| 52 | R_HEADS = 'refs/heads/' |
| 53 | R_TAGS = 'refs/tags/' |
David Pursehouse | 1d947b3 | 2012-10-25 12:23:11 +0900 | [diff] [blame] | 54 | ID_RE = re.compile(r'^[0-9a-f]{40}$') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 55 | |
Shawn O. Pearce | 146fe90 | 2009-03-25 14:06:43 -0700 | [diff] [blame] | 56 | REVIEW_CACHE = dict() |
| 57 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 58 | def IsId(rev): |
| 59 | return ID_RE.match(rev) |
| 60 | |
Shawn O. Pearce | f8e3273 | 2009-04-17 11:00:31 -0700 | [diff] [blame] | 61 | def _key(name): |
| 62 | parts = name.split('.') |
| 63 | if len(parts) < 2: |
| 64 | return name.lower() |
| 65 | parts[ 0] = parts[ 0].lower() |
| 66 | parts[-1] = parts[-1].lower() |
| 67 | return '.'.join(parts) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 68 | |
| 69 | class GitConfig(object): |
Shawn O. Pearce | 90be5c0 | 2008-10-29 15:21:24 -0700 | [diff] [blame] | 70 | _ForUser = None |
| 71 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 72 | @classmethod |
| 73 | def ForUser(cls): |
Shawn O. Pearce | 90be5c0 | 2008-10-29 15:21:24 -0700 | [diff] [blame] | 74 | if cls._ForUser is None: |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 75 | cls._ForUser = cls(configfile = os.path.expanduser('~/.gitconfig')) |
Shawn O. Pearce | 90be5c0 | 2008-10-29 15:21:24 -0700 | [diff] [blame] | 76 | return cls._ForUser |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | |
| 78 | @classmethod |
| 79 | def ForRepository(cls, gitdir, defaults=None): |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 80 | return cls(configfile = os.path.join(gitdir, 'config'), |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 81 | defaults = defaults) |
| 82 | |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 83 | def __init__(self, configfile, defaults=None, pickleFile=None): |
| 84 | self.file = configfile |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 85 | self.defaults = defaults |
| 86 | self._cache_dict = None |
Shawn O. Pearce | accc56d | 2009-04-18 14:45:51 -0700 | [diff] [blame] | 87 | self._section_dict = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 88 | self._remotes = {} |
| 89 | self._branches = {} |
Shawn O. Pearce | 1b34c91 | 2009-05-21 18:52:49 -0700 | [diff] [blame] | 90 | |
| 91 | if pickleFile is None: |
| 92 | self._pickle = os.path.join( |
| 93 | os.path.dirname(self.file), |
| 94 | '.repopickle_' + os.path.basename(self.file)) |
| 95 | else: |
| 96 | self._pickle = pickleFile |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 97 | |
| 98 | def Has(self, name, include_defaults = True): |
| 99 | """Return true if this configuration file has the key. |
| 100 | """ |
Shawn O. Pearce | f8e3273 | 2009-04-17 11:00:31 -0700 | [diff] [blame] | 101 | if _key(name) in self._cache: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 102 | return True |
| 103 | if include_defaults and self.defaults: |
| 104 | return self.defaults.Has(name, include_defaults = True) |
| 105 | return False |
| 106 | |
| 107 | def GetBoolean(self, name): |
| 108 | """Returns a boolean from the configuration file. |
| 109 | None : The value was not defined, or is not a boolean. |
| 110 | True : The value was set to true or yes. |
| 111 | False: The value was set to false or no. |
| 112 | """ |
| 113 | v = self.GetString(name) |
| 114 | if v is None: |
| 115 | return None |
| 116 | v = v.lower() |
| 117 | if v in ('true', 'yes'): |
| 118 | return True |
| 119 | if v in ('false', 'no'): |
| 120 | return False |
| 121 | return None |
| 122 | |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 123 | def GetString(self, name, all_keys=False): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 124 | """Get the first value for a key, or None if it is not defined. |
| 125 | |
| 126 | This configuration file is used first, if the key is not |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 127 | defined or all_keys = True then the defaults are also searched. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 128 | """ |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 129 | try: |
Shawn O. Pearce | f8e3273 | 2009-04-17 11:00:31 -0700 | [diff] [blame] | 130 | v = self._cache[_key(name)] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 131 | except KeyError: |
| 132 | if self.defaults: |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 133 | return self.defaults.GetString(name, all_keys = all_keys) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | v = [] |
| 135 | |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 136 | if not all_keys: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 137 | if v: |
| 138 | return v[0] |
| 139 | return None |
| 140 | |
| 141 | r = [] |
| 142 | r.extend(v) |
| 143 | if self.defaults: |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 144 | r.extend(self.defaults.GetString(name, all_keys = True)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 145 | return r |
| 146 | |
| 147 | def SetString(self, name, value): |
| 148 | """Set the value(s) for a key. |
| 149 | Only this configuration file is modified. |
| 150 | |
| 151 | The supplied value should be either a string, |
| 152 | or a list of strings (to store multiple values). |
| 153 | """ |
Shawn O. Pearce | f8e3273 | 2009-04-17 11:00:31 -0700 | [diff] [blame] | 154 | key = _key(name) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 155 | |
| 156 | try: |
Shawn O. Pearce | f8e3273 | 2009-04-17 11:00:31 -0700 | [diff] [blame] | 157 | old = self._cache[key] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 158 | except KeyError: |
| 159 | old = [] |
| 160 | |
| 161 | if value is None: |
| 162 | if old: |
Shawn O. Pearce | f8e3273 | 2009-04-17 11:00:31 -0700 | [diff] [blame] | 163 | del self._cache[key] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 164 | self._do('--unset-all', name) |
| 165 | |
| 166 | elif isinstance(value, list): |
| 167 | if len(value) == 0: |
| 168 | self.SetString(name, None) |
| 169 | |
| 170 | elif len(value) == 1: |
| 171 | self.SetString(name, value[0]) |
| 172 | |
| 173 | elif old != value: |
Shawn O. Pearce | f8e3273 | 2009-04-17 11:00:31 -0700 | [diff] [blame] | 174 | self._cache[key] = list(value) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 175 | self._do('--replace-all', name, value[0]) |
Sarah Owens | a6053d5 | 2012-11-01 13:36:50 -0700 | [diff] [blame] | 176 | for i in range(1, len(value)): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 177 | self._do('--add', name, value[i]) |
| 178 | |
| 179 | elif len(old) != 1 or old[0] != value: |
Shawn O. Pearce | f8e3273 | 2009-04-17 11:00:31 -0700 | [diff] [blame] | 180 | self._cache[key] = [value] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 181 | self._do('--replace-all', name, value) |
| 182 | |
| 183 | def GetRemote(self, name): |
| 184 | """Get the remote.$name.* configuration values as an object. |
| 185 | """ |
| 186 | try: |
| 187 | r = self._remotes[name] |
| 188 | except KeyError: |
| 189 | r = Remote(self, name) |
| 190 | self._remotes[r.name] = r |
| 191 | return r |
| 192 | |
| 193 | def GetBranch(self, name): |
| 194 | """Get the branch.$name.* configuration values as an object. |
| 195 | """ |
| 196 | try: |
| 197 | b = self._branches[name] |
| 198 | except KeyError: |
| 199 | b = Branch(self, name) |
| 200 | self._branches[b.name] = b |
| 201 | return b |
| 202 | |
Shawn O. Pearce | 366ad21 | 2009-05-19 12:47:37 -0700 | [diff] [blame] | 203 | def GetSubSections(self, section): |
| 204 | """List all subsection names matching $section.*.* |
| 205 | """ |
| 206 | return self._sections.get(section, set()) |
| 207 | |
Shawn O. Pearce | accc56d | 2009-04-18 14:45:51 -0700 | [diff] [blame] | 208 | def HasSection(self, section, subsection = ''): |
| 209 | """Does at least one key in section.subsection exist? |
| 210 | """ |
| 211 | try: |
| 212 | return subsection in self._sections[section] |
| 213 | except KeyError: |
| 214 | return False |
| 215 | |
Shawn O. Pearce | 13111b4 | 2011-09-19 11:00:31 -0700 | [diff] [blame] | 216 | def UrlInsteadOf(self, url): |
| 217 | """Resolve any url.*.insteadof references. |
| 218 | """ |
| 219 | for new_url in self.GetSubSections('url'): |
| 220 | old_url = self.GetString('url.%s.insteadof' % new_url) |
| 221 | if old_url is not None and url.startswith(old_url): |
| 222 | return new_url + url[len(old_url):] |
| 223 | return url |
| 224 | |
Shawn O. Pearce | accc56d | 2009-04-18 14:45:51 -0700 | [diff] [blame] | 225 | @property |
| 226 | def _sections(self): |
| 227 | d = self._section_dict |
| 228 | if d is None: |
| 229 | d = {} |
| 230 | for name in self._cache.keys(): |
| 231 | p = name.split('.') |
| 232 | if 2 == len(p): |
| 233 | section = p[0] |
| 234 | subsect = '' |
| 235 | else: |
| 236 | section = p[0] |
| 237 | subsect = '.'.join(p[1:-1]) |
| 238 | if section not in d: |
| 239 | d[section] = set() |
| 240 | d[section].add(subsect) |
| 241 | self._section_dict = d |
| 242 | return d |
| 243 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 244 | @property |
| 245 | def _cache(self): |
| 246 | if self._cache_dict is None: |
| 247 | self._cache_dict = self._Read() |
| 248 | return self._cache_dict |
| 249 | |
| 250 | def _Read(self): |
Shawn O. Pearce | c12c360 | 2009-04-17 21:03:32 -0700 | [diff] [blame] | 251 | d = self._ReadPickle() |
| 252 | if d is None: |
| 253 | d = self._ReadGit() |
| 254 | self._SavePickle(d) |
| 255 | return d |
| 256 | |
| 257 | def _ReadPickle(self): |
| 258 | try: |
| 259 | if os.path.getmtime(self._pickle) \ |
| 260 | <= os.path.getmtime(self.file): |
| 261 | os.remove(self._pickle) |
| 262 | return None |
| 263 | except OSError: |
| 264 | return None |
| 265 | try: |
Shawn O. Pearce | ad3193a | 2009-04-18 09:54:51 -0700 | [diff] [blame] | 266 | Trace(': unpickle %s', self.file) |
Shawn O. Pearce | 76ca9f8 | 2009-04-18 14:48:03 -0700 | [diff] [blame] | 267 | fd = open(self._pickle, 'rb') |
| 268 | try: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 269 | return pickle.load(fd) |
Shawn O. Pearce | 76ca9f8 | 2009-04-18 14:48:03 -0700 | [diff] [blame] | 270 | finally: |
| 271 | fd.close() |
Shawn O. Pearce | 2a3a81b | 2009-06-12 09:10:07 -0700 | [diff] [blame] | 272 | except EOFError: |
| 273 | os.remove(self._pickle) |
| 274 | return None |
Shawn O. Pearce | c12c360 | 2009-04-17 21:03:32 -0700 | [diff] [blame] | 275 | except IOError: |
| 276 | os.remove(self._pickle) |
| 277 | return None |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 278 | except pickle.PickleError: |
Shawn O. Pearce | c12c360 | 2009-04-17 21:03:32 -0700 | [diff] [blame] | 279 | os.remove(self._pickle) |
| 280 | return None |
| 281 | |
| 282 | def _SavePickle(self, cache): |
| 283 | try: |
Shawn O. Pearce | 76ca9f8 | 2009-04-18 14:48:03 -0700 | [diff] [blame] | 284 | fd = open(self._pickle, 'wb') |
| 285 | try: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 286 | pickle.dump(cache, fd, pickle.HIGHEST_PROTOCOL) |
Shawn O. Pearce | 76ca9f8 | 2009-04-18 14:48:03 -0700 | [diff] [blame] | 287 | finally: |
| 288 | fd.close() |
Shawn O. Pearce | c12c360 | 2009-04-17 21:03:32 -0700 | [diff] [blame] | 289 | except IOError: |
Ulrik Sjölin | 99482ae | 2010-10-29 08:23:30 -0700 | [diff] [blame] | 290 | if os.path.exists(self._pickle): |
| 291 | os.remove(self._pickle) |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 292 | except pickle.PickleError: |
Ulrik Sjölin | 99482ae | 2010-10-29 08:23:30 -0700 | [diff] [blame] | 293 | if os.path.exists(self._pickle): |
| 294 | os.remove(self._pickle) |
Shawn O. Pearce | c12c360 | 2009-04-17 21:03:32 -0700 | [diff] [blame] | 295 | |
| 296 | def _ReadGit(self): |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 297 | """ |
| 298 | Read configuration data from git. |
| 299 | |
| 300 | This internal method populates the GitConfig cache. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 301 | |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 302 | """ |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 303 | c = {} |
Shawn O. Pearce | c24c720 | 2009-07-02 16:12:57 -0700 | [diff] [blame] | 304 | d = self._do('--null', '--list') |
| 305 | if d is None: |
| 306 | return c |
David Pursehouse | 1d947b3 | 2012-10-25 12:23:11 +0900 | [diff] [blame] | 307 | for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401 |
| 308 | # Backslash is not anomalous |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 309 | if '\n' in line: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 310 | key, val = line.split('\n', 1) |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 311 | else: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 312 | key = line |
| 313 | val = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 314 | |
| 315 | if key in c: |
| 316 | c[key].append(val) |
| 317 | else: |
| 318 | c[key] = [val] |
| 319 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 320 | return c |
| 321 | |
| 322 | def _do(self, *args): |
| 323 | command = ['config', '--file', self.file] |
| 324 | command.extend(args) |
| 325 | |
| 326 | p = GitCommand(None, |
| 327 | command, |
| 328 | capture_stdout = True, |
| 329 | capture_stderr = True) |
| 330 | if p.Wait() == 0: |
| 331 | return p.stdout |
| 332 | else: |
| 333 | GitError('git config %s: %s' % (str(args), p.stderr)) |
| 334 | |
| 335 | |
| 336 | class RefSpec(object): |
| 337 | """A Git refspec line, split into its components: |
| 338 | |
| 339 | forced: True if the line starts with '+' |
| 340 | src: Left side of the line |
| 341 | dst: Right side of the line |
| 342 | """ |
| 343 | |
| 344 | @classmethod |
| 345 | def FromString(cls, rs): |
| 346 | lhs, rhs = rs.split(':', 2) |
| 347 | if lhs.startswith('+'): |
| 348 | lhs = lhs[1:] |
| 349 | forced = True |
| 350 | else: |
| 351 | forced = False |
| 352 | return cls(forced, lhs, rhs) |
| 353 | |
| 354 | def __init__(self, forced, lhs, rhs): |
| 355 | self.forced = forced |
| 356 | self.src = lhs |
| 357 | self.dst = rhs |
| 358 | |
| 359 | def SourceMatches(self, rev): |
| 360 | if self.src: |
| 361 | if rev == self.src: |
| 362 | return True |
| 363 | if self.src.endswith('/*') and rev.startswith(self.src[:-1]): |
| 364 | return True |
| 365 | return False |
| 366 | |
| 367 | def DestMatches(self, ref): |
| 368 | if self.dst: |
| 369 | if ref == self.dst: |
| 370 | return True |
| 371 | if self.dst.endswith('/*') and ref.startswith(self.dst[:-1]): |
| 372 | return True |
| 373 | return False |
| 374 | |
| 375 | def MapSource(self, rev): |
| 376 | if self.src.endswith('/*'): |
| 377 | return self.dst[:-1] + rev[len(self.src) - 1:] |
| 378 | return self.dst |
| 379 | |
| 380 | def __str__(self): |
| 381 | s = '' |
| 382 | if self.forced: |
| 383 | s += '+' |
| 384 | if self.src: |
| 385 | s += self.src |
| 386 | if self.dst: |
| 387 | s += ':' |
| 388 | s += self.dst |
| 389 | return s |
| 390 | |
| 391 | |
Doug Anderson | 06d029c | 2010-10-27 17:06:01 -0700 | [diff] [blame] | 392 | _master_processes = [] |
| 393 | _master_keys = set() |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 394 | _ssh_master = True |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 395 | _master_keys_lock = None |
| 396 | |
| 397 | def init_ssh(): |
| 398 | """Should be called once at the start of repo to init ssh master handling. |
| 399 | |
| 400 | At the moment, all we do is to create our lock. |
| 401 | """ |
| 402 | global _master_keys_lock |
| 403 | assert _master_keys_lock is None, "Should only call init_ssh once" |
| 404 | _master_keys_lock = _threading.Lock() |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 405 | |
Josh Guilfoyle | 7198572 | 2009-08-16 09:44:40 -0700 | [diff] [blame] | 406 | def _open_ssh(host, port=None): |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 407 | global _ssh_master |
| 408 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 409 | # Acquire the lock. This is needed to prevent opening multiple masters for |
| 410 | # the same host when we're running "repo sync -jN" (for N > 1) _and_ the |
| 411 | # manifest <remote fetch="ssh://xyz"> specifies a different host from the |
| 412 | # one that was passed to repo init. |
| 413 | _master_keys_lock.acquire() |
| 414 | try: |
Josh Guilfoyle | 7198572 | 2009-08-16 09:44:40 -0700 | [diff] [blame] | 415 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 416 | # Check to see whether we already think that the master is running; if we |
| 417 | # think it's already running, return right away. |
| 418 | if port is not None: |
| 419 | key = '%s:%s' % (host, port) |
| 420 | else: |
| 421 | key = host |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 422 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 423 | if key in _master_keys: |
| 424 | return True |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 425 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 426 | if not _ssh_master \ |
| 427 | or 'GIT_SSH' in os.environ \ |
| 428 | or sys.platform in ('win32', 'cygwin'): |
| 429 | # failed earlier, or cygwin ssh can't do this |
| 430 | # |
| 431 | return False |
Doug Anderson | 06d029c | 2010-10-27 17:06:01 -0700 | [diff] [blame] | 432 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 433 | # We will make two calls to ssh; this is the common part of both calls. |
| 434 | command_base = ['ssh', |
| 435 | '-o','ControlPath %s' % ssh_sock(), |
| 436 | host] |
| 437 | if port is not None: |
David Pursehouse | 8f62fb7 | 2012-11-14 12:09:38 +0900 | [diff] [blame] | 438 | command_base[1:1] = ['-p', str(port)] |
Doug Anderson | 06d029c | 2010-10-27 17:06:01 -0700 | [diff] [blame] | 439 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 440 | # Since the key wasn't in _master_keys, we think that master isn't running. |
| 441 | # ...but before actually starting a master, we'll double-check. This can |
| 442 | # be important because we can't tell that that 'git@myhost.com' is the same |
| 443 | # as 'myhost.com' where "User git" is setup in the user's ~/.ssh/config file. |
| 444 | check_command = command_base + ['-O','check'] |
| 445 | try: |
| 446 | Trace(': %s', ' '.join(check_command)) |
| 447 | check_process = subprocess.Popen(check_command, |
| 448 | stdout=subprocess.PIPE, |
| 449 | stderr=subprocess.PIPE) |
| 450 | check_process.communicate() # read output, but ignore it... |
| 451 | isnt_running = check_process.wait() |
Josh Guilfoyle | 7198572 | 2009-08-16 09:44:40 -0700 | [diff] [blame] | 452 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 453 | if not isnt_running: |
| 454 | # Our double-check found that the master _was_ infact running. Add to |
| 455 | # the list of keys. |
| 456 | _master_keys.add(key) |
| 457 | return True |
| 458 | except Exception: |
| 459 | # Ignore excpetions. We we will fall back to the normal command and print |
| 460 | # to the log there. |
| 461 | pass |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 462 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 463 | command = command_base[:1] + \ |
| 464 | ['-M', '-N'] + \ |
| 465 | command_base[1:] |
| 466 | try: |
| 467 | Trace(': %s', ' '.join(command)) |
| 468 | p = subprocess.Popen(command) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 469 | except Exception as e: |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 470 | _ssh_master = False |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 471 | print('\nwarn: cannot enable ssh control master for %s:%s\n%s' |
| 472 | % (host,port, str(e)), file=sys.stderr) |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 473 | return False |
| 474 | |
| 475 | _master_processes.append(p) |
| 476 | _master_keys.add(key) |
| 477 | time.sleep(1) |
| 478 | return True |
| 479 | finally: |
| 480 | _master_keys_lock.release() |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 481 | |
| 482 | def close_ssh(): |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 483 | global _master_keys_lock |
| 484 | |
Shawn O. Pearce | ca8c32c | 2010-05-11 18:21:33 -0700 | [diff] [blame] | 485 | terminate_ssh_clients() |
| 486 | |
Doug Anderson | 06d029c | 2010-10-27 17:06:01 -0700 | [diff] [blame] | 487 | for p in _master_processes: |
Shawn O. Pearce | 26120ca | 2009-06-16 11:49:10 -0700 | [diff] [blame] | 488 | try: |
| 489 | os.kill(p.pid, SIGTERM) |
| 490 | p.wait() |
Shawn O. Pearce | fb5c8fd | 2009-06-16 14:57:46 -0700 | [diff] [blame] | 491 | except OSError: |
Shawn O. Pearce | 26120ca | 2009-06-16 11:49:10 -0700 | [diff] [blame] | 492 | pass |
Doug Anderson | 06d029c | 2010-10-27 17:06:01 -0700 | [diff] [blame] | 493 | del _master_processes[:] |
| 494 | _master_keys.clear() |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 495 | |
Nico Sallembien | 1c85f4e | 2010-04-27 14:35:27 -0700 | [diff] [blame] | 496 | d = ssh_sock(create=False) |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 497 | if d: |
| 498 | try: |
| 499 | os.rmdir(os.path.dirname(d)) |
| 500 | except OSError: |
| 501 | pass |
| 502 | |
Doug Anderson | 0048b69 | 2010-12-21 13:39:23 -0800 | [diff] [blame] | 503 | # We're done with the lock, so we can delete it. |
| 504 | _master_keys_lock = None |
| 505 | |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 506 | URI_SCP = re.compile(r'^([^@:]*@?[^:/]{1,}):') |
Shawn O. Pearce | 898e12a | 2012-03-14 15:22:28 -0700 | [diff] [blame] | 507 | URI_ALL = re.compile(r'^([a-z][a-z+-]*)://([^@/]*@?[^/]*)/') |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 508 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 509 | def GetSchemeFromUrl(url): |
| 510 | m = URI_ALL.match(url) |
| 511 | if m: |
| 512 | return m.group(1) |
| 513 | return None |
| 514 | |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 515 | def _preconnect(url): |
| 516 | m = URI_ALL.match(url) |
| 517 | if m: |
| 518 | scheme = m.group(1) |
| 519 | host = m.group(2) |
| 520 | if ':' in host: |
| 521 | host, port = host.split(':') |
Shawn O. Pearce | 896d5df | 2009-04-21 14:51:04 -0700 | [diff] [blame] | 522 | else: |
Josh Guilfoyle | 7198572 | 2009-08-16 09:44:40 -0700 | [diff] [blame] | 523 | port = None |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 524 | if scheme in ('ssh', 'git+ssh', 'ssh+git'): |
| 525 | return _open_ssh(host, port) |
| 526 | return False |
| 527 | |
| 528 | m = URI_SCP.match(url) |
| 529 | if m: |
| 530 | host = m.group(1) |
Josh Guilfoyle | 7198572 | 2009-08-16 09:44:40 -0700 | [diff] [blame] | 531 | return _open_ssh(host) |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 532 | |
Shawn O. Pearce | 7b4f435 | 2009-06-12 09:06:35 -0700 | [diff] [blame] | 533 | return False |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 534 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 535 | class Remote(object): |
| 536 | """Configuration options related to a remote. |
| 537 | """ |
| 538 | def __init__(self, config, name): |
| 539 | self._config = config |
| 540 | self.name = name |
| 541 | self.url = self._Get('url') |
| 542 | self.review = self._Get('review') |
Shawn O. Pearce | 339ba9f | 2008-11-06 09:52:51 -0800 | [diff] [blame] | 543 | self.projectname = self._Get('projectname') |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 544 | self.fetch = list(map(RefSpec.FromString, |
| 545 | self._Get('fetch', all_keys=True))) |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 546 | self._review_url = None |
Shawn O. Pearce | b54a392 | 2009-01-05 16:18:58 -0800 | [diff] [blame] | 547 | |
Ulrik Sjolin | b6ea3bf | 2010-01-03 18:20:17 +0100 | [diff] [blame] | 548 | def _InsteadOf(self): |
| 549 | globCfg = GitConfig.ForUser() |
| 550 | urlList = globCfg.GetSubSections('url') |
| 551 | longest = "" |
| 552 | longestUrl = "" |
| 553 | |
| 554 | for url in urlList: |
| 555 | key = "url." + url + ".insteadOf" |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 556 | insteadOfList = globCfg.GetString(key, all_keys=True) |
Ulrik Sjolin | b6ea3bf | 2010-01-03 18:20:17 +0100 | [diff] [blame] | 557 | |
| 558 | for insteadOf in insteadOfList: |
| 559 | if self.url.startswith(insteadOf) \ |
| 560 | and len(insteadOf) > len(longest): |
| 561 | longest = insteadOf |
| 562 | longestUrl = url |
| 563 | |
| 564 | if len(longest) == 0: |
| 565 | return self.url |
| 566 | |
| 567 | return self.url.replace(longest, longestUrl, 1) |
| 568 | |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 569 | def PreConnectFetch(self): |
Ulrik Sjolin | b6ea3bf | 2010-01-03 18:20:17 +0100 | [diff] [blame] | 570 | connectionUrl = self._InsteadOf() |
| 571 | return _preconnect(connectionUrl) |
Shawn O. Pearce | fb23161 | 2009-04-10 18:53:46 -0700 | [diff] [blame] | 572 | |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 573 | def ReviewUrl(self, userEmail): |
| 574 | if self._review_url is None: |
Shawn O. Pearce | b54a392 | 2009-01-05 16:18:58 -0800 | [diff] [blame] | 575 | if self.review is None: |
| 576 | return None |
| 577 | |
| 578 | u = self.review |
| 579 | if not u.startswith('http:') and not u.startswith('https:'): |
| 580 | u = 'http://%s' % u |
Shawn O. Pearce | 13cc384 | 2009-03-25 13:54:54 -0700 | [diff] [blame] | 581 | if u.endswith('/Gerrit'): |
| 582 | u = u[:len(u) - len('/Gerrit')] |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 583 | if u.endswith('/ssh_info'): |
| 584 | u = u[:len(u) - len('/ssh_info')] |
| 585 | if not u.endswith('/'): |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 586 | u += '/' |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 587 | http_url = u |
Shawn O. Pearce | b54a392 | 2009-01-05 16:18:58 -0800 | [diff] [blame] | 588 | |
Shawn O. Pearce | 146fe90 | 2009-03-25 14:06:43 -0700 | [diff] [blame] | 589 | if u in REVIEW_CACHE: |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 590 | self._review_url = REVIEW_CACHE[u] |
Shawn O. Pearce | 1a68dc5 | 2011-10-11 14:12:46 -0700 | [diff] [blame] | 591 | elif 'REPO_HOST_PORT_INFO' in os.environ: |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 592 | host, port = os.environ['REPO_HOST_PORT_INFO'].split() |
| 593 | self._review_url = self._SshReviewUrl(userEmail, host, port) |
| 594 | REVIEW_CACHE[u] = self._review_url |
Shawn O. Pearce | 146fe90 | 2009-03-25 14:06:43 -0700 | [diff] [blame] | 595 | else: |
| 596 | try: |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 597 | info_url = u + 'ssh_info' |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 598 | info = urllib.request.urlopen(info_url).read() |
Shawn O. Pearce | 146fe90 | 2009-03-25 14:06:43 -0700 | [diff] [blame] | 599 | if '<' in info: |
| 600 | # Assume the server gave us some sort of HTML |
| 601 | # response back, like maybe a login page. |
| 602 | # |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 603 | raise UploadError('%s: Cannot parse response' % info_url) |
Shawn O. Pearce | b54a392 | 2009-01-05 16:18:58 -0800 | [diff] [blame] | 604 | |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 605 | if info == 'NOT_AVAILABLE': |
| 606 | # Assume HTTP if SSH is not enabled. |
| 607 | self._review_url = http_url + 'p/' |
Shawn O. Pearce | 146fe90 | 2009-03-25 14:06:43 -0700 | [diff] [blame] | 608 | else: |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 609 | host, port = info.split() |
| 610 | self._review_url = self._SshReviewUrl(userEmail, host, port) |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 611 | except urllib.error.HTTPError as e: |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 612 | raise UploadError('%s: %s' % (self.review, str(e))) |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 613 | except urllib.error.URLError as e: |
Shawn O. Pearce | bf1fbb2 | 2011-10-11 09:31:58 -0700 | [diff] [blame] | 614 | raise UploadError('%s: %s' % (self.review, str(e))) |
David Pursehouse | ecf8f2b | 2013-05-24 12:12:23 +0900 | [diff] [blame^] | 615 | except HTTPException as e: |
| 616 | raise UploadError('%s: %s' % (self.review, e.__class__.__name__)) |
Shawn O. Pearce | b54a392 | 2009-01-05 16:18:58 -0800 | [diff] [blame] | 617 | |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 618 | REVIEW_CACHE[u] = self._review_url |
| 619 | return self._review_url + self.projectname |
Shawn O. Pearce | b54a392 | 2009-01-05 16:18:58 -0800 | [diff] [blame] | 620 | |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 621 | def _SshReviewUrl(self, userEmail, host, port): |
Shawn O. Pearce | 3575b8f | 2010-07-15 17:00:14 -0700 | [diff] [blame] | 622 | username = self._config.GetString('review.%s.username' % self.review) |
| 623 | if username is None: |
Shawn O. Pearce | c957142 | 2012-01-11 14:58:54 -0800 | [diff] [blame] | 624 | username = userEmail.split('@')[0] |
| 625 | return 'ssh://%s@%s:%s/' % (username, host, port) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 626 | |
| 627 | def ToLocal(self, rev): |
| 628 | """Convert a remote revision string to something we have locally. |
| 629 | """ |
| 630 | if IsId(rev): |
| 631 | return rev |
| 632 | if rev.startswith(R_TAGS): |
| 633 | return rev |
| 634 | |
| 635 | if not rev.startswith('refs/'): |
| 636 | rev = R_HEADS + rev |
| 637 | |
| 638 | for spec in self.fetch: |
| 639 | if spec.SourceMatches(rev): |
| 640 | return spec.MapSource(rev) |
| 641 | raise GitError('remote %s does not have %s' % (self.name, rev)) |
| 642 | |
| 643 | def WritesTo(self, ref): |
| 644 | """True if the remote stores to the tracking ref. |
| 645 | """ |
| 646 | for spec in self.fetch: |
| 647 | if spec.DestMatches(ref): |
| 648 | return True |
| 649 | return False |
| 650 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 651 | def ResetFetch(self, mirror=False): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 652 | """Set the fetch refspec to its default value. |
| 653 | """ |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 654 | if mirror: |
| 655 | dst = 'refs/heads/*' |
| 656 | else: |
| 657 | dst = 'refs/remotes/%s/*' % self.name |
| 658 | self.fetch = [RefSpec(True, 'refs/heads/*', dst)] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 659 | |
| 660 | def Save(self): |
| 661 | """Save this remote to the configuration. |
| 662 | """ |
| 663 | self._Set('url', self.url) |
| 664 | self._Set('review', self.review) |
Shawn O. Pearce | 339ba9f | 2008-11-06 09:52:51 -0800 | [diff] [blame] | 665 | self._Set('projectname', self.projectname) |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 666 | self._Set('fetch', list(map(str, self.fetch))) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 667 | |
| 668 | def _Set(self, key, value): |
| 669 | key = 'remote.%s.%s' % (self.name, key) |
| 670 | return self._config.SetString(key, value) |
| 671 | |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 672 | def _Get(self, key, all_keys=False): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 673 | key = 'remote.%s.%s' % (self.name, key) |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 674 | return self._config.GetString(key, all_keys = all_keys) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 675 | |
| 676 | |
| 677 | class Branch(object): |
| 678 | """Configuration options related to a single branch. |
| 679 | """ |
| 680 | def __init__(self, config, name): |
| 681 | self._config = config |
| 682 | self.name = name |
| 683 | self.merge = self._Get('merge') |
| 684 | |
| 685 | r = self._Get('remote') |
| 686 | if r: |
| 687 | self.remote = self._config.GetRemote(r) |
| 688 | else: |
| 689 | self.remote = None |
| 690 | |
| 691 | @property |
| 692 | def LocalMerge(self): |
| 693 | """Convert the merge spec to a local name. |
| 694 | """ |
| 695 | if self.remote and self.merge: |
| 696 | return self.remote.ToLocal(self.merge) |
| 697 | return None |
| 698 | |
| 699 | def Save(self): |
| 700 | """Save this branch back into the configuration. |
| 701 | """ |
Shawn O. Pearce | accc56d | 2009-04-18 14:45:51 -0700 | [diff] [blame] | 702 | if self._config.HasSection('branch', self.name): |
| 703 | if self.remote: |
| 704 | self._Set('remote', self.remote.name) |
| 705 | else: |
| 706 | self._Set('remote', None) |
| 707 | self._Set('merge', self.merge) |
| 708 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 709 | else: |
Shawn O. Pearce | accc56d | 2009-04-18 14:45:51 -0700 | [diff] [blame] | 710 | fd = open(self._config.file, 'ab') |
| 711 | try: |
| 712 | fd.write('[branch "%s"]\n' % self.name) |
| 713 | if self.remote: |
| 714 | fd.write('\tremote = %s\n' % self.remote.name) |
| 715 | if self.merge: |
| 716 | fd.write('\tmerge = %s\n' % self.merge) |
| 717 | finally: |
| 718 | fd.close() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 719 | |
| 720 | def _Set(self, key, value): |
| 721 | key = 'branch.%s.%s' % (self.name, key) |
| 722 | return self._config.SetString(key, value) |
| 723 | |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 724 | def _Get(self, key, all_keys=False): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 725 | key = 'branch.%s.%s' % (self.name, key) |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 726 | return self._config.GetString(key, all_keys = all_keys) |