mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-28 20:17:26 +00:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
b54a392c9a | |||
21f7385400 | |||
24d8dfbc34 | |||
a6df7d284c | |||
67092448c2 | |||
e92ceebde0 |
@ -16,7 +16,8 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from error import GitError
|
from urllib2 import urlopen, HTTPError
|
||||||
|
from error import GitError, UploadError
|
||||||
from git_command import GitCommand
|
from git_command import GitCommand
|
||||||
|
|
||||||
R_HEADS = 'refs/heads/'
|
R_HEADS = 'refs/heads/'
|
||||||
@ -261,6 +262,45 @@ class Remote(object):
|
|||||||
self.projectname = self._Get('projectname')
|
self.projectname = self._Get('projectname')
|
||||||
self.fetch = map(lambda x: RefSpec.FromString(x),
|
self.fetch = map(lambda x: RefSpec.FromString(x),
|
||||||
self._Get('fetch', all=True))
|
self._Get('fetch', all=True))
|
||||||
|
self._review_protocol = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ReviewProtocol(self):
|
||||||
|
if self._review_protocol is None:
|
||||||
|
if self.review is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
u = self.review
|
||||||
|
if not u.startswith('http:') and not u.startswith('https:'):
|
||||||
|
u = 'http://%s' % u
|
||||||
|
if not u.endswith('/'):
|
||||||
|
u += '/'
|
||||||
|
u += 'ssh_info'
|
||||||
|
|
||||||
|
try:
|
||||||
|
info = urlopen(u).read()
|
||||||
|
if info == 'NOT_AVAILABLE':
|
||||||
|
raise UploadError('Upload over ssh unavailable')
|
||||||
|
|
||||||
|
self._review_protocol = 'ssh'
|
||||||
|
self._review_host = info.split(" ")[0]
|
||||||
|
self._review_port = info.split(" ")[1]
|
||||||
|
|
||||||
|
except HTTPError, e:
|
||||||
|
if e.code == 404:
|
||||||
|
self._review_protocol = 'http-post'
|
||||||
|
else:
|
||||||
|
raise UploadError('Cannot guess Gerrit version')
|
||||||
|
return self._review_protocol
|
||||||
|
|
||||||
|
def SshReviewUrl(self, userEmail):
|
||||||
|
if self.ReviewProtocol != 'ssh':
|
||||||
|
return None
|
||||||
|
return 'ssh://%s@%s:%s/%s' % (
|
||||||
|
userEmail.split("@")[0],
|
||||||
|
self._review_host,
|
||||||
|
self._review_port,
|
||||||
|
self.projectname)
|
||||||
|
|
||||||
def ToLocal(self, rev):
|
def ToLocal(self, rev):
|
||||||
"""Convert a remote revision string to something we have locally.
|
"""Convert a remote revision string to something we have locally.
|
||||||
|
75
project.py
75
project.py
@ -46,6 +46,8 @@ def _info(fmt, *args):
|
|||||||
def not_rev(r):
|
def not_rev(r):
|
||||||
return '^' + r
|
return '^' + r
|
||||||
|
|
||||||
|
def sq(r):
|
||||||
|
return "'" + r.replace("'", "'\''") + "'"
|
||||||
|
|
||||||
hook_list = None
|
hook_list = None
|
||||||
def repo_hooks():
|
def repo_hooks():
|
||||||
@ -475,33 +477,58 @@ class Project(object):
|
|||||||
if not dest_branch.startswith(R_HEADS):
|
if not dest_branch.startswith(R_HEADS):
|
||||||
dest_branch = R_HEADS + dest_branch
|
dest_branch = R_HEADS + dest_branch
|
||||||
|
|
||||||
base_list = []
|
|
||||||
for name, id in self._allrefs.iteritems():
|
|
||||||
if branch.remote.WritesTo(name):
|
|
||||||
base_list.append(not_rev(name))
|
|
||||||
if not base_list:
|
|
||||||
raise GitError('no base refs, cannot upload %s' % branch.name)
|
|
||||||
|
|
||||||
if not branch.remote.projectname:
|
if not branch.remote.projectname:
|
||||||
branch.remote.projectname = self.name
|
branch.remote.projectname = self.name
|
||||||
branch.remote.Save()
|
branch.remote.Save()
|
||||||
|
|
||||||
print >>sys.stderr, ''
|
if branch.remote.ReviewProtocol == 'http-post':
|
||||||
_info("Uploading %s to %s:", branch.name, self.name)
|
base_list = []
|
||||||
try:
|
for name, id in self._allrefs.iteritems():
|
||||||
UploadBundle(project = self,
|
if branch.remote.WritesTo(name):
|
||||||
server = branch.remote.review,
|
base_list.append(not_rev(name))
|
||||||
email = self.UserEmail,
|
if not base_list:
|
||||||
dest_project = branch.remote.projectname,
|
raise GitError('no base refs, cannot upload %s' % branch.name)
|
||||||
dest_branch = dest_branch,
|
|
||||||
src_branch = R_HEADS + branch.name,
|
print >>sys.stderr, ''
|
||||||
bases = base_list,
|
_info("Uploading %s to %s:", branch.name, self.name)
|
||||||
people = people,
|
try:
|
||||||
replace_changes = replace_changes)
|
UploadBundle(project = self,
|
||||||
except proto_client.ClientLoginError:
|
server = branch.remote.review,
|
||||||
raise UploadError('Login failure')
|
email = self.UserEmail,
|
||||||
except urllib2.HTTPError, e:
|
dest_project = branch.remote.projectname,
|
||||||
raise UploadError('HTTP error %d' % e.code)
|
dest_branch = dest_branch,
|
||||||
|
src_branch = R_HEADS + branch.name,
|
||||||
|
bases = base_list,
|
||||||
|
people = people,
|
||||||
|
replace_changes = replace_changes)
|
||||||
|
except proto_client.ClientLoginError:
|
||||||
|
raise UploadError('Login failure')
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
raise UploadError('HTTP error %d' % e.code)
|
||||||
|
|
||||||
|
elif branch.remote.ReviewProtocol == 'ssh':
|
||||||
|
if dest_branch.startswith(R_HEADS):
|
||||||
|
dest_branch = dest_branch[len(R_HEADS):]
|
||||||
|
|
||||||
|
rp = ['gerrit receive-pack']
|
||||||
|
for e in people[0]:
|
||||||
|
rp.append('--reviewer=%s' % sq(e))
|
||||||
|
for e in people[1]:
|
||||||
|
rp.append('--cc=%s' % sq(e))
|
||||||
|
|
||||||
|
cmd = ['push']
|
||||||
|
cmd.append('--receive-pack=%s' % " ".join(rp))
|
||||||
|
cmd.append(branch.remote.SshReviewUrl(self.UserEmail))
|
||||||
|
cmd.append('%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch))
|
||||||
|
if replace_changes:
|
||||||
|
for change_id,commit_id in replace_changes.iteritems():
|
||||||
|
cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id))
|
||||||
|
if GitCommand(self, cmd, bare = True).Wait() != 0:
|
||||||
|
raise UploadError('Upload failed')
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise UploadError('Unsupported protocol %s' \
|
||||||
|
% branch.remote.review)
|
||||||
|
|
||||||
msg = "posted to %s for %s" % (branch.remote.review, dest_branch)
|
msg = "posted to %s for %s" % (branch.remote.review, dest_branch)
|
||||||
self.bare_git.UpdateRef(R_PUB + branch.name,
|
self.bare_git.UpdateRef(R_PUB + branch.name,
|
||||||
@ -940,7 +967,7 @@ class Project(object):
|
|||||||
ref = R_M + self.manifest.branch
|
ref = R_M + self.manifest.branch
|
||||||
|
|
||||||
if IsId(self.revision):
|
if IsId(self.revision):
|
||||||
dst = self.revision + '^0',
|
dst = self.revision + '^0'
|
||||||
self.bare_git.UpdateRef(ref, dst, message = msg, detach = True)
|
self.bare_git.UpdateRef(ref, dst, message = msg, detach = True)
|
||||||
else:
|
else:
|
||||||
remote = self.GetRemote(self.remote.name)
|
remote = self.GetRemote(self.remote.name)
|
||||||
|
4
repo
4
repo
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## repo default configuration
|
## repo default configuration
|
||||||
##
|
##
|
||||||
REPO_URL='git://android.kernel.org/tools/repo.git'
|
REPO_URL='git://android.git.kernel.org/tools/repo.git'
|
||||||
REPO_REV='stable'
|
REPO_REV='stable'
|
||||||
|
|
||||||
# Copyright (C) 2008 Google Inc.
|
# Copyright (C) 2008 Google Inc.
|
||||||
@ -28,7 +28,7 @@ if __name__ == '__main__':
|
|||||||
del magic
|
del magic
|
||||||
|
|
||||||
# increment this whenever we make important changes to this script
|
# increment this whenever we make important changes to this script
|
||||||
VERSION = (1, 7)
|
VERSION = (1, 8)
|
||||||
|
|
||||||
# increment this if the MAINTAINER_KEYS block is modified
|
# increment this if the MAINTAINER_KEYS block is modified
|
||||||
KEYRING_VERSION = (1,0)
|
KEYRING_VERSION = (1,0)
|
||||||
|
@ -55,6 +55,12 @@ If the --reviewers or --cc options are passed, those emails are
|
|||||||
added to the respective list of users, and emails are sent to any
|
added to the respective list of users, and emails are sent to any
|
||||||
new users. Users passed to --reviewers must be already registered
|
new users. Users passed to --reviewers must be already registered
|
||||||
with the code review system, or the upload will fail.
|
with the code review system, or the upload will fail.
|
||||||
|
|
||||||
|
If the --replace option is passed the user can designate which
|
||||||
|
existing change(s) in Gerrit match up to the commits in the branch
|
||||||
|
being uploaded. For each matched pair of change,commit the commit
|
||||||
|
will be added as a new patch set, completely replacing the set of
|
||||||
|
files and description associated with the change in Gerrit.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _Options(self, p):
|
def _Options(self, p):
|
||||||
@ -151,7 +157,7 @@ with the code review system, or the upload will fail.
|
|||||||
_die("nothing uncommented for upload")
|
_die("nothing uncommented for upload")
|
||||||
self._UploadAndReport(todo, people)
|
self._UploadAndReport(todo, people)
|
||||||
|
|
||||||
def _ReplaceBranch(self, project):
|
def _ReplaceBranch(self, project, people):
|
||||||
branch = project.CurrentBranch
|
branch = project.CurrentBranch
|
||||||
if not branch:
|
if not branch:
|
||||||
print >>sys.stdout, "no branches ready for upload"
|
print >>sys.stdout, "no branches ready for upload"
|
||||||
@ -178,6 +184,7 @@ with the code review system, or the upload will fail.
|
|||||||
for line in script:
|
for line in script:
|
||||||
m = change_re.match(line)
|
m = change_re.match(line)
|
||||||
if m:
|
if m:
|
||||||
|
c = m.group(1)
|
||||||
f = m.group(2)
|
f = m.group(2)
|
||||||
try:
|
try:
|
||||||
f = full_hashes[f]
|
f = full_hashes[f]
|
||||||
@ -185,7 +192,11 @@ with the code review system, or the upload will fail.
|
|||||||
print 'fh = %s' % full_hashes
|
print 'fh = %s' % full_hashes
|
||||||
print >>sys.stderr, "error: commit %s not found" % f
|
print >>sys.stderr, "error: commit %s not found" % f
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
to_replace[m.group(1)] = f
|
if c in to_replace:
|
||||||
|
print >>sys.stderr,\
|
||||||
|
"error: change %s cannot accept multiple commits" % c
|
||||||
|
sys.exit(1)
|
||||||
|
to_replace[c] = f
|
||||||
|
|
||||||
if not to_replace:
|
if not to_replace:
|
||||||
print >>sys.stderr, "error: no replacements specified"
|
print >>sys.stderr, "error: no replacements specified"
|
||||||
@ -247,7 +258,7 @@ with the code review system, or the upload will fail.
|
|||||||
print >>sys.stderr, \
|
print >>sys.stderr, \
|
||||||
'error: --replace requires exactly one project'
|
'error: --replace requires exactly one project'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
self._ReplaceBranch(project_list[0])
|
self._ReplaceBranch(project_list[0], people)
|
||||||
return
|
return
|
||||||
|
|
||||||
for project in project_list:
|
for project in project_list:
|
||||||
|
Reference in New Issue
Block a user