mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-26 20:17:52 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
632768bc65 | |||
0758d2f1d6 | |||
bb0ee80571 | |||
02dbb6d120 |
@ -1 +1 @@
|
||||
__version__ = 'v1.0'
|
||||
__version__ = 'v1.0-14-gc4f226bc'
|
||||
|
@ -167,6 +167,10 @@ class HttpRpc(RpcChannel):
|
||||
Returns:
|
||||
The authentication token returned by ClientLogin.
|
||||
"""
|
||||
account_type = 'GOOGLE'
|
||||
if self.host.endswith('.google.com'):
|
||||
account_type = 'HOSTED'
|
||||
|
||||
req = self._CreateRequest(
|
||||
url="https://www.google.com/accounts/ClientLogin",
|
||||
data=urllib.urlencode({
|
||||
@ -174,7 +178,7 @@ class HttpRpc(RpcChannel):
|
||||
"Passwd": password,
|
||||
"service": "ah",
|
||||
"source": "gerrit-codereview-client",
|
||||
"accountType": "HOSTED_OR_GOOGLE",
|
||||
"accountType": account_type,
|
||||
})
|
||||
)
|
||||
try:
|
||||
@ -214,7 +218,6 @@ class HttpRpc(RpcChannel):
|
||||
response.info()["location"] != continue_location):
|
||||
raise urllib2.HTTPError(req.get_full_url(), response.code, response.msg,
|
||||
response.headers, response.fp)
|
||||
self.authenticated = True
|
||||
|
||||
def _GetXsrfToken(self):
|
||||
"""Fetches /proto/_token for use in X-XSRF-Token HTTP header.
|
||||
@ -253,10 +256,18 @@ class HttpRpc(RpcChannel):
|
||||
authentication cookie, it returns a 401 response and directs us to
|
||||
authenticate ourselves with ClientLogin.
|
||||
"""
|
||||
for i in range(3):
|
||||
credentials = self.auth_function()
|
||||
auth_token = self._GetAuthToken(credentials[0], credentials[1])
|
||||
attempts = 0
|
||||
while True:
|
||||
attempts += 1
|
||||
try:
|
||||
cred = self.auth_function()
|
||||
auth_token = self._GetAuthToken(cred[0], cred[1])
|
||||
except ClientLoginError:
|
||||
if attempts < 3:
|
||||
continue
|
||||
raise
|
||||
self._GetAuthCookie(auth_token)
|
||||
self.authenticated = True
|
||||
if self.cookie_file is not None:
|
||||
self.cookie_jar.save()
|
||||
return
|
||||
|
53
project.py
53
project.py
@ -45,6 +45,31 @@ def _info(fmt, *args):
|
||||
def not_rev(r):
|
||||
return '^' + r
|
||||
|
||||
class DownloadedChange(object):
|
||||
_commit_cache = None
|
||||
|
||||
def __init__(self, project, base, change_id, ps_id, commit):
|
||||
self.project = project
|
||||
self.base = base
|
||||
self.change_id = change_id
|
||||
self.ps_id = ps_id
|
||||
self.commit = commit
|
||||
|
||||
@property
|
||||
def commits(self):
|
||||
if self._commit_cache is None:
|
||||
self._commit_cache = self.project.bare_git.rev_list(
|
||||
'--abbrev=8',
|
||||
'--abbrev-commit',
|
||||
'--pretty=oneline',
|
||||
'--reverse',
|
||||
'--date-order',
|
||||
not_rev(self.base),
|
||||
self.commit,
|
||||
'--')
|
||||
return self._commit_cache
|
||||
|
||||
|
||||
class ReviewableBranch(object):
|
||||
_commit_cache = None
|
||||
|
||||
@ -88,6 +113,10 @@ class ReviewableBranch(object):
|
||||
commit = self.project.bare_git.rev_parse(R_HEADS + self.name)
|
||||
return 'http://%s/r/%s' % (me.remote.review, commit[0:12])
|
||||
|
||||
@property
|
||||
def owner_email(self):
|
||||
return self.project.UserEmail
|
||||
|
||||
|
||||
class StatusColoring(Coloring):
|
||||
def __init__(self, config):
|
||||
@ -608,6 +637,23 @@ class Project(object):
|
||||
src = os.path.join(self.worktree, src)
|
||||
self.copyfiles.append(_CopyFile(src, dest))
|
||||
|
||||
def DownloadPatchSet(self, change_id, patch_id):
|
||||
"""Download a single patch set of a single change to FETCH_HEAD.
|
||||
"""
|
||||
remote = self.GetRemote(self.remote.name)
|
||||
|
||||
cmd = ['fetch', remote.name]
|
||||
cmd.append('refs/changes/%2.2d/%d/%d' \
|
||||
% (change_id % 100, change_id, patch_id))
|
||||
cmd.extend(map(lambda x: str(x), remote.fetch))
|
||||
if GitCommand(self, cmd, bare=True).Wait() != 0:
|
||||
return None
|
||||
return DownloadedChange(self,
|
||||
remote.ToLocal(self.revision),
|
||||
change_id,
|
||||
patch_id,
|
||||
self.bare_git.rev_parse('FETCH_HEAD'))
|
||||
|
||||
|
||||
## Branch Management ##
|
||||
|
||||
@ -920,8 +966,11 @@ class Project(object):
|
||||
if out:
|
||||
out = iter(out[:-1].split('\0'))
|
||||
while out:
|
||||
info = out.next()
|
||||
path = out.next()
|
||||
try:
|
||||
info = out.next()
|
||||
path = out.next()
|
||||
except StopIteration:
|
||||
break
|
||||
|
||||
class _Info(object):
|
||||
def __init__(self, path, omode, nmode, oid, nid, state):
|
||||
|
78
subcmds/download.py
Normal file
78
subcmds/download.py
Normal file
@ -0,0 +1,78 @@
|
||||
#
|
||||
# Copyright (C) 2008 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from command import Command
|
||||
|
||||
CHANGE_RE = re.compile(r'^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$')
|
||||
|
||||
class Download(Command):
|
||||
common = True
|
||||
helpSummary = "Download and checkout a change"
|
||||
helpUsage = """
|
||||
%prog {project change[/patchset]}...
|
||||
"""
|
||||
helpDescription = """
|
||||
The '%prog' command downloads a change from the review system and
|
||||
makes it available in your project's local working directory.
|
||||
"""
|
||||
|
||||
def _Options(self, p):
|
||||
pass
|
||||
|
||||
def _ParseChangeIds(self, args):
|
||||
to_get = []
|
||||
project = None
|
||||
|
||||
for a in args:
|
||||
m = CHANGE_RE.match(a)
|
||||
if m:
|
||||
if not project:
|
||||
self.Usage()
|
||||
chg_id = int(m.group(1))
|
||||
if m.group(2):
|
||||
ps_id = int(m.group(2))
|
||||
else:
|
||||
ps_id = 1
|
||||
to_get.append((project, chg_id, ps_id))
|
||||
else:
|
||||
project = self.GetProjects([a])[0]
|
||||
return to_get
|
||||
|
||||
def Execute(self, opt, args):
|
||||
for project, change_id, ps_id in self._ParseChangeIds(args):
|
||||
dl = project.DownloadPatchSet(change_id, ps_id)
|
||||
if not dl:
|
||||
print >>sys.stderr, \
|
||||
'[%s] change %d/%d not found' \
|
||||
% (project.name, change_id, ps_id)
|
||||
sys.exit(1)
|
||||
|
||||
if not dl.commits:
|
||||
print >>sys.stderr, \
|
||||
'[%s] change %d/%d has already been merged' \
|
||||
% (project.name, change_id, ps_id)
|
||||
continue
|
||||
|
||||
if len(dl.commits) > 1:
|
||||
print >>sys.stderr, \
|
||||
'[%s] %d/%d depends on %d unmerged changes:' \
|
||||
% (project.name, change_id, ps_id, len(dl.commits))
|
||||
for c in dl.commits:
|
||||
print >>sys.stderr, ' %s' % (c)
|
||||
project._Checkout(dl.commit)
|
@ -158,6 +158,7 @@ changes in all projects listed in the manifest.
|
||||
branch.project.relpath + '/',
|
||||
branch.name)
|
||||
print >>sys.stderr, '%s' % branch.tip_url
|
||||
print >>sys.stderr, '(as %s)' % branch.owner_email
|
||||
print >>sys.stderr, ''
|
||||
|
||||
if have_errors:
|
||||
|
Reference in New Issue
Block a user