Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Side by Side Diff: git_cl.py

Issue 9385010: git_cl: drop migration code (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 import logging 10 import logging
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 class Settings(object): 139 class Settings(object):
140 def __init__(self): 140 def __init__(self):
141 self.default_server = None 141 self.default_server = None
142 self.cc = None 142 self.cc = None
143 self.root = None 143 self.root = None
144 self.is_git_svn = None 144 self.is_git_svn = None
145 self.svn_branch = None 145 self.svn_branch = None
146 self.tree_status_url = None 146 self.tree_status_url = None
147 self.viewvc_url = None 147 self.viewvc_url = None
148 self.updated = False 148 self.updated = False
149 self.did_migrate_check = False
150 self.is_gerrit = None 149 self.is_gerrit = None
151 150
152 def LazyUpdateIfNeeded(self): 151 def LazyUpdateIfNeeded(self):
153 """Updates the settings from a codereview.settings file, if available.""" 152 """Updates the settings from a codereview.settings file, if available."""
154 if not self.updated: 153 if not self.updated:
155 cr_settings_file = FindCodereviewSettingsFile() 154 cr_settings_file = FindCodereviewSettingsFile()
156 if cr_settings_file: 155 if cr_settings_file:
157 LoadCodereviewSettingsFromFile(cr_settings_file) 156 LoadCodereviewSettingsFromFile(cr_settings_file)
158 self.updated = True 157 self.updated = True
159 158
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 """Return true if this repo is assosiated with gerrit code review system.""" 268 """Return true if this repo is assosiated with gerrit code review system."""
270 if self.is_gerrit is None: 269 if self.is_gerrit is None:
271 self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True) 270 self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True)
272 return self.is_gerrit 271 return self.is_gerrit
273 272
274 def _GetConfig(self, param, **kwargs): 273 def _GetConfig(self, param, **kwargs):
275 self.LazyUpdateIfNeeded() 274 self.LazyUpdateIfNeeded()
276 return RunGit(['config', param], **kwargs).strip() 275 return RunGit(['config', param], **kwargs).strip()
277 276
278 277
279 def CheckForMigration():
280 """Migrate from the old issue format, if found.
281
282 We used to store the branch<->issue mapping in a file in .git, but it's
283 better to store it in the .git/config, since deleting a branch deletes that
284 branch's entry there.
285 """
286
287 # Don't run more than once.
288 if settings.did_migrate_check:
289 return
290
291 gitdir = RunGit(['rev-parse', '--git-dir']).strip()
292 storepath = os.path.join(gitdir, 'cl-mapping')
293 if os.path.exists(storepath):
294 print "old-style git-cl mapping file (%s) found; migrating." % storepath
295 store = open(storepath, 'r')
296 for line in store:
297 branch, issue = line.strip().split()
298 RunGit(['config', 'branch.%s.rietveldissue' % ShortBranchName(branch),
299 issue])
300 store.close()
301 os.remove(storepath)
302 settings.did_migrate_check = True
303
304
305 def ShortBranchName(branch): 278 def ShortBranchName(branch):
306 """Convert a name like 'refs/heads/foo' to just 'foo'.""" 279 """Convert a name like 'refs/heads/foo' to just 'foo'."""
307 return branch.replace('refs/heads/', '') 280 return branch.replace('refs/heads/', '')
308 281
309 282
310 class Changelist(object): 283 class Changelist(object):
311 def __init__(self, branchref=None): 284 def __init__(self, branchref=None):
312 # Poke settings so we get the "configure your server" message if necessary. 285 # Poke settings so we get the "configure your server" message if necessary.
313 global settings 286 global settings
314 if not settings: 287 if not settings:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 387
415 Returns None if there is no remote. 388 Returns None if there is no remote.
416 """ 389 """
417 remote = self.FetchUpstreamTuple()[0] 390 remote = self.FetchUpstreamTuple()[0]
418 if remote == '.': 391 if remote == '.':
419 return None 392 return None
420 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() 393 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip()
421 394
422 def GetIssue(self): 395 def GetIssue(self):
423 if not self.has_issue: 396 if not self.has_issue:
424 CheckForMigration()
425 issue = RunGit(['config', self._IssueSetting()], error_ok=True).strip() 397 issue = RunGit(['config', self._IssueSetting()], error_ok=True).strip()
426 if issue: 398 if issue:
427 self.issue = issue 399 self.issue = issue
428 self.rietveld_server = gclient_utils.UpgradeToHttps(RunGit( 400 self.rietveld_server = gclient_utils.UpgradeToHttps(RunGit(
429 ['config', self._RietveldServer()], error_ok=True).strip()) 401 ['config', self._RietveldServer()], error_ok=True).strip())
430 else: 402 else:
431 self.issue = None 403 self.issue = None
432 if not self.rietveld_server: 404 if not self.rietveld_server:
433 self.rietveld_server = settings.GetDefaultServerUrl() 405 self.rietveld_server = settings.GetDefaultServerUrl()
434 self.has_issue = True 406 self.has_issue = True
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1470 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1499 1471
1500 # Not a known command. Default to help. 1472 # Not a known command. Default to help.
1501 GenUsage(parser, 'help') 1473 GenUsage(parser, 'help')
1502 return CMDhelp(parser, argv) 1474 return CMDhelp(parser, argv)
1503 1475
1504 1476
1505 if __name__ == '__main__': 1477 if __name__ == '__main__':
1506 fix_encoding.fix_encoding() 1478 fix_encoding.fix_encoding()
1507 sys.exit(main(sys.argv[1:])) 1479 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698