Compare commits

...

3 Commits

Author SHA1 Message Date
c9571423f8 upload: Support uploading to Gerrit over https://
If SSH is not available, Gerrit returns NOT_AVAILABLE to the /ssh_info
query made by repo upload. In this case fallback to the /p/$PROJECT URL
that Gerrit also exports and use that for uploads.

Change-Id: I1e3e39ab709ecc0a692614a41a42446426f39c08
2012-01-11 16:18:40 -08:00
34fb20f67c Revert "Default repo manifest settings in git config"
This reverts commit ee1c2f5717.

This breaks a lot of buildbot systems. Rolling it back for now
until we can understand what the breakage was and how to fix it.
2011-11-30 13:41:02 -08:00
ecff4f17b0 Describe the repo launch version in repo version
repo version v1.7.8
         (from https://android.googlesource.com/tools/repo.git)
  repo launcher version 1.14
         (from /home/sop/bin/repo)
  git version 1.7.8.rc2.256.gcc761
  Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
  [GCC 4.4.3]

Change-Id: Ifcbe5b0e226a1a6ca85455eb62e4da5e9a0f0ca0
2011-11-29 15:02:15 -08:00
7 changed files with 60 additions and 107 deletions

View File

@ -527,7 +527,7 @@ 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 self._review_url = None
def _InsteadOf(self): def _InsteadOf(self):
globCfg = GitConfig.ForUser() globCfg = GitConfig.ForUser()
@ -554,9 +554,8 @@ class Remote(object):
connectionUrl = self._InsteadOf() connectionUrl = self._InsteadOf()
return _preconnect(connectionUrl) return _preconnect(connectionUrl)
@property def ReviewUrl(self, userEmail):
def ReviewProtocol(self): if self._review_url is None:
if self._review_protocol is None:
if self.review is None: if self.review is None:
return None return None
@ -565,67 +564,47 @@ class Remote(object):
u = 'http://%s' % u u = 'http://%s' % u
if u.endswith('/Gerrit'): if u.endswith('/Gerrit'):
u = u[:len(u) - len('/Gerrit')] u = u[:len(u) - len('/Gerrit')]
if not u.endswith('/ssh_info'): if u.endswith('/ssh_info'):
if not u.endswith('/'): u = u[:len(u) - len('/ssh_info')]
u += '/' if not u.endswith('/'):
u += 'ssh_info' u += '/'
http_url = u
if u in REVIEW_CACHE: if u in REVIEW_CACHE:
info = REVIEW_CACHE[u] self._review_url = REVIEW_CACHE[u]
self._review_protocol = info[0]
self._review_host = info[1]
self._review_port = info[2]
elif 'REPO_HOST_PORT_INFO' in os.environ: elif 'REPO_HOST_PORT_INFO' in os.environ:
info = os.environ['REPO_HOST_PORT_INFO'] host, port = os.environ['REPO_HOST_PORT_INFO'].split()
self._review_protocol = 'ssh' self._review_url = self._SshReviewUrl(userEmail, host, port)
self._review_host = info.split(" ")[0] REVIEW_CACHE[u] = self._review_url
self._review_port = info.split(" ")[1]
REVIEW_CACHE[u] = (
self._review_protocol,
self._review_host,
self._review_port)
else: else:
try: try:
info = urllib2.urlopen(u).read() info_url = u + 'ssh_info'
if info == 'NOT_AVAILABLE': info = urllib2.urlopen(info_url).read()
raise UploadError('%s: SSH disabled' % self.review)
if '<' in info: if '<' in info:
# Assume the server gave us some sort of HTML # Assume the server gave us some sort of HTML
# response back, like maybe a login page. # response back, like maybe a login page.
# #
raise UploadError('%s: Cannot parse response' % u) raise UploadError('%s: Cannot parse response' % info_url)
self._review_protocol = 'ssh' if info == 'NOT_AVAILABLE':
self._review_host = info.split(" ")[0] # Assume HTTP if SSH is not enabled.
self._review_port = info.split(" ")[1] self._review_url = http_url + 'p/'
except urllib2.HTTPError, e:
if e.code == 404:
self._review_protocol = 'http-post'
self._review_host = None
self._review_port = None
else: else:
raise UploadError('Upload over SSH unavailable') host, port = info.split()
self._review_url = self._SshReviewUrl(userEmail, host, port)
except urllib2.HTTPError, e:
raise UploadError('%s: %s' % (self.review, str(e)))
except urllib2.URLError, e: except urllib2.URLError, e:
raise UploadError('%s: %s' % (self.review, str(e))) raise UploadError('%s: %s' % (self.review, str(e)))
REVIEW_CACHE[u] = ( REVIEW_CACHE[u] = self._review_url
self._review_protocol, return self._review_url + self.projectname
self._review_host,
self._review_port)
return self._review_protocol
def SshReviewUrl(self, userEmail): def _SshReviewUrl(self, userEmail, host, port):
if self.ReviewProtocol != 'ssh':
return None
username = self._config.GetString('review.%s.username' % self.review) username = self._config.GetString('review.%s.username' % self.review)
if username is None: if username is None:
username = userEmail.split("@")[0] username = userEmail.split('@')[0]
return 'ssh://%s@%s:%s/%s' % ( return 'ssh://%s@%s:%s/' % (username, host, port)
username,
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.

View File

@ -36,6 +36,7 @@ from git_config import init_ssh, close_ssh
from command import InteractiveCommand from command import InteractiveCommand
from command import MirrorSafeCommand from command import MirrorSafeCommand
from command import PagedCommand from command import PagedCommand
from subcmds.version import Version
from editor import Editor from editor import Editor
from error import DownloadError from error import DownloadError
from error import ManifestInvalidRevisionError from error import ManifestInvalidRevisionError
@ -334,6 +335,9 @@ def _Main(argv):
_CheckWrapperVersion(opt.wrapper_version, opt.wrapper_path) _CheckWrapperVersion(opt.wrapper_version, opt.wrapper_path)
_CheckRepoDir(opt.repodir) _CheckRepoDir(opt.repodir)
Version.wrapper_version = opt.wrapper_version
Version.wrapper_path = opt.wrapper_path
repo = _Repo(opt.repodir) repo = _Repo(opt.repodir)
try: try:
try: try:

View File

@ -228,11 +228,7 @@ class XmlManifest(object):
@property @property
def manifest_server(self): def manifest_server(self):
self._Load() self._Load()
return self._manifest_server
if self._manifest_server:
return self._manifest_server
return self.manifestProject.config.GetString('repo.manifest-server')
@property @property
def IsMirror(self): def IsMirror(self):

View File

@ -866,31 +866,30 @@ class Project(object):
branch.remote.projectname = self.name branch.remote.projectname = self.name
branch.remote.Save() branch.remote.Save()
if branch.remote.ReviewProtocol == 'ssh': url = branch.remote.ReviewUrl(self.UserEmail)
if dest_branch.startswith(R_HEADS): if url is None:
dest_branch = dest_branch[len(R_HEADS):] raise UploadError('review not configured')
cmd = ['push']
if url.startswith('ssh://'):
rp = ['gerrit receive-pack'] rp = ['gerrit receive-pack']
for e in people[0]: for e in people[0]:
rp.append('--reviewer=%s' % sq(e)) rp.append('--reviewer=%s' % sq(e))
for e in people[1]: for e in people[1]:
rp.append('--cc=%s' % sq(e)) rp.append('--cc=%s' % sq(e))
ref_spec = '%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch)
if auto_topic:
ref_spec = ref_spec + '/' + branch.name
cmd = ['push']
cmd.append('--receive-pack=%s' % " ".join(rp)) cmd.append('--receive-pack=%s' % " ".join(rp))
cmd.append(branch.remote.SshReviewUrl(self.UserEmail))
cmd.append(ref_spec)
if GitCommand(self, cmd, bare = True).Wait() != 0: cmd.append(url)
raise UploadError('Upload failed')
else: if dest_branch.startswith(R_HEADS):
raise UploadError('Unsupported protocol %s' \ dest_branch = dest_branch[len(R_HEADS):]
% branch.remote.review) ref_spec = '%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch)
if auto_topic:
ref_spec = ref_spec + '/' + branch.name
cmd.append(ref_spec)
if GitCommand(self, cmd, bare = True).Wait() != 0:
raise UploadError('Upload failed')
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,

4
repo
View File

@ -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, 14) VERSION = (1, 13)
# 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)
@ -154,7 +154,7 @@ def _Init(args):
"""Installs repo by cloning it over the network. """Installs repo by cloning it over the network.
""" """
opt, args = init_optparse.parse_args(args) opt, args = init_optparse.parse_args(args)
if args: if args or not opt.manifest_url:
init_optparse.print_usage() init_optparse.print_usage()
sys.exit(1) sys.exit(1)

View File

@ -23,7 +23,6 @@ from error import ManifestParseError
from project import SyncBuffer from project import SyncBuffer
from git_config import GitConfig from git_config import GitConfig
from git_command import git_require, MIN_GIT_VERSION from git_command import git_require, MIN_GIT_VERSION
from git_config import GitConfig
class Init(InteractiveCommand, MirrorSafeCommand): class Init(InteractiveCommand, MirrorSafeCommand):
common = True common = True
@ -37,20 +36,6 @@ The latest repo source code and manifest collection is downloaded
from the server and is installed in the .repo/ directory in the from the server and is installed in the .repo/ directory in the
current working directory. current working directory.
The optional -u argument can be used to specify a URL to the
manifest project. It is also possible to have a git configuration
section as below to use 'identifier' as argument to -u:
[repo-manifest "identifier"]
url = ...
server = ...
reference = ...
Only the url is required - the others are optional.
If no -u argument is specified, the 'repo-manifest' section named
'default' will be used if present.
The optional -b argument can be used to select the manifest branch The optional -b argument can be used to select the manifest branch
to checkout and use. If no branch is specified, master is assumed. to checkout and use. If no branch is specified, master is assumed.
@ -84,7 +69,7 @@ to update the working directory files.
# Manifest # Manifest
g = p.add_option_group('Manifest options') g = p.add_option_group('Manifest options')
g.add_option('-u', '--manifest-url', g.add_option('-u', '--manifest-url',
dest='manifest_url', default='default', dest='manifest_url',
help='manifest repository location', metavar='URL') help='manifest repository location', metavar='URL')
g.add_option('-b', '--manifest-branch', g.add_option('-b', '--manifest-branch',
dest='manifest_branch', dest='manifest_branch',
@ -123,25 +108,10 @@ to update the working directory files.
def _SyncManifest(self, opt): def _SyncManifest(self, opt):
m = self.manifest.manifestProject m = self.manifest.manifestProject
is_new = not m.Exists is_new = not m.Exists
manifest_server = None
# The manifest url may point out a manifest section in the config
key = 'repo-manifest.%s.' % opt.manifest_url
if GitConfig.ForUser().GetString(key + 'url'):
opt.manifest_url = GitConfig.ForUser().GetString(key + 'url')
# Also copy other options to the manifest config if not specified already.
if not opt.reference:
opt.reference = GitConfig.ForUser().GetString(key + 'reference')
manifest_server = GitConfig.ForUser().GetString(key + 'server')
if is_new: if is_new:
if not opt.manifest_url or opt.manifest_url == 'default': if not opt.manifest_url:
print >>sys.stderr, """\ print >>sys.stderr, 'fatal: manifest url (-u) is required.'
fatal: missing manifest url (-u) and no default found.
tip: The global git configuration key 'repo-manifest.default.url' can
be used to specify a default url."""
sys.exit(1) sys.exit(1)
if not opt.quiet: if not opt.quiet:
@ -165,9 +135,6 @@ fatal: missing manifest url (-u) and no default found.
r.ResetFetch() r.ResetFetch()
r.Save() r.Save()
if manifest_server:
m.config.SetString('repo.manifest-server', manifest_server)
if opt.reference: if opt.reference:
m.config.SetString('repo.reference', opt.reference) m.config.SetString('repo.reference', opt.reference)

View File

@ -19,6 +19,9 @@ from git_command import git
from project import HEAD from project import HEAD
class Version(Command, MirrorSafeCommand): class Version(Command, MirrorSafeCommand):
wrapper_version = None
wrapper_path = None
common = False common = False
helpSummary = "Display the version of repo" helpSummary = "Display the version of repo"
helpUsage = """ helpUsage = """
@ -31,5 +34,10 @@ class Version(Command, MirrorSafeCommand):
print 'repo version %s' % rp.work_git.describe(HEAD) print 'repo version %s' % rp.work_git.describe(HEAD)
print ' (from %s)' % rem.url print ' (from %s)' % rem.url
if Version.wrapper_path is not None:
print 'repo launcher version %s' % Version.wrapper_version
print ' (from %s)' % Version.wrapper_path
print git.version().strip() print git.version().strip()
print 'Python %s' % sys.version print 'Python %s' % sys.version