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

Unified Diff: git_cl.py

Issue 9264065: Add minimal Gerrit support to 'git cl config' and 'git cl upload' (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
===================================================================
--- git_cl.py (revision 120036)
+++ git_cl.py (working copy)
@@ -147,6 +147,7 @@
self.viewvc_url = None
self.updated = False
self.did_migrate_check = False
+ self.is_gerrit = None
def LazyUpdateIfNeeded(self):
"""Updates the settings from a codereview.settings file, if available."""
@@ -264,6 +265,12 @@
def GetDefaultCCList(self):
return self._GetConfig('rietveld.cc', error_ok=True)
+ def GetIsGerrit(self):
+ """Return true if this repo is assosiated with gerrit code review system."""
+ if self.is_gerrit is None:
+ self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True)
+ return self.is_gerrit
+
def _GetConfig(self, param, **kwargs):
self.LazyUpdateIfNeeded()
return RunGit(['config', param], **kwargs).strip()
@@ -604,6 +611,7 @@
def GetCodereviewSettingsInteractively():
"""Prompt the user for settings."""
+ # TODO(ukai): ask code review system is rietveld or gerrit?
server = settings.GetDefaultServerUrl(error_ok=True)
prompt = 'Rietveld server (host[:port])'
prompt += ' [%s]' % (server or DEFAULT_SERVER)
@@ -723,6 +731,15 @@
SetProperty('tree-status-url', 'STATUS', unset_error_ok=True)
SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True)
+ if 'GERRIT_HOST' in keyvals and 'GERRIT_PORT' in keyvals:
+ RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']])
+ RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']])
+ # Install the standard commit-msg hook.
+ RunCommand(['scp', '-p', '-P', keyvals['GERRIT_PORT'],
+ '%s:hooks/commit-msg' % keyvals['GERRIT_HOST'],
+ os.path.join(settings.GetRoot(),
+ '.git', 'hooks', 'commit-msg')])
+
if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals:
#should be of the form
#PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof
@@ -863,6 +880,44 @@
return 0
+def GerritUpload(options, args, cl):
+ """upload the current branch to gerrit."""
+ # We assume the remote called "origin" is the one we want.
+ # It is probably not worthwhile to support different workflows.
M-A Ruel 2012/02/01 15:50:35 What about CL pipelining? Why not just get the bra
ukai 2012/02/02 04:21:59 I'm new to gerrit and don't know how to do it yet.
+ remote = 'origin'
+ branch = 'master'
+ if args:
+ branch = args[0]
+
+ description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b',
+ '%s...' % (branch)]).strip()
+
+ receive_options = []
+ cc = []
+ if options.cc:
+ cc = options.cc.split(',')
+ cc = filter(None, (cl.GetCCList(), cc))
+ if cc:
+ receive_options += ['--cc=' + email for email in cc]
+ # Retrieves all reviewer lines
+ reviewer_regexp = re.compile(r'^\s*(TBR|R)=(.+)$', re.MULTILINE)
M-A Ruel 2012/02/01 15:50:35 Why can't you reuse the parsing code? It'd be nice
ukai 2012/02/02 04:21:59 Done.
+ reviewers = filter(None, ','.join(
+ i.group(2).strip()
+ for i in reviewer_regexp.finditer(description)).split(','))
+ if options.reviewers:
+ reviewers += filter(None, options.reviewers.split(','))
+ if reviewers:
+ receive_options += ['--reviewer=' + email for email in reviewers]
+
+ git_command = ['push']
+ if receive_options:
+ git_command.append('--receive-pack=git receive-pack ' +
+ ' '.join(receive_options))
+ git_command += [remote, 'HEAD:refs/for/' + branch]
+ RunGit(git_command)
+ return 0
+
+
@usage('[args to "git diff"]')
def CMDupload(parser, args):
"""upload the current changelist to codereview"""
@@ -896,11 +951,15 @@
cl = Changelist()
if args:
+ # TODO(ukai): is it ok for gerrit case?
base_branch = args[0]
else:
# Default to diffing against the "upstream" branch.
base_branch = cl.GetUpstreamBranch()
- args = [base_branch + "..."]
+ if settings.GetIsGerrit():
+ args = ['master']
M-A Ruel 2012/02/01 15:50:35 Why?
ukai 2012/02/02 04:21:59 I initially thought args[0] to be used for target
+ else:
+ args = [base_branch + "..."]
if not options.bypass_hooks:
hook_results = cl.RunHook(committing=False, upstream_branch=base_branch,
@@ -921,6 +980,11 @@
subprocess2.call(
['git', 'diff', '--no-ext-diff', '--stat', '-M'] + args, env=env)
+ if settings.GetIsGerrit():
+ GerritUpload(options, args, cl)
+ # TODO(ukai): parse Change-Id: and set issue number?
+ return 0
+
upload_args = ['--assume_yes'] # Don't ask about untracked files.
M-A Ruel 2012/02/01 15:50:35 I'd rather move the rest into RietveldUpload to ma
ukai 2012/02/02 04:21:59 Done.
upload_args.extend(['--server', cl.GetRietveldServer()])
if options.emulate_svn_auto_props:
@@ -1229,6 +1293,7 @@
issue_arg = args[0]
# TODO(maruel): Use apply_issue.py
+ # TODO(ukai): use gerrit-cherry-pick for gerrit repository?
if re.match(r'\d+', issue_arg):
# Input is an issue id. Figure out the URL.
« 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