mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-26 20:17:52 +00:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
3575b8f8bd | |||
a5ece0e050 | |||
cc50bac8c7 | |||
0cb1b3f687 | |||
9e426aa432 | |||
08a3f68d38 | |||
feb39d61ef | |||
7198572dd7 | |||
2daf66740b | |||
f4f04d9fa8 | |||
18afd7f679 | |||
6623b21e10 |
@ -359,10 +359,14 @@ class RefSpec(object):
|
||||
_ssh_cache = {}
|
||||
_ssh_master = True
|
||||
|
||||
def _open_ssh(host, port):
|
||||
def _open_ssh(host, port=None):
|
||||
global _ssh_master
|
||||
|
||||
if port is not None:
|
||||
key = '%s:%s' % (host, port)
|
||||
else:
|
||||
key = host
|
||||
|
||||
if key in _ssh_cache:
|
||||
return True
|
||||
|
||||
@ -375,10 +379,13 @@ def _open_ssh(host, port):
|
||||
|
||||
command = ['ssh',
|
||||
'-o','ControlPath %s' % ssh_sock(),
|
||||
'-p',str(port),
|
||||
'-M',
|
||||
'-N',
|
||||
host]
|
||||
|
||||
if port is not None:
|
||||
command[3:3] = ['-p',str(port)]
|
||||
|
||||
try:
|
||||
Trace(': %s', ' '.join(command))
|
||||
p = subprocess.Popen(command)
|
||||
@ -422,7 +429,7 @@ def _preconnect(url):
|
||||
if ':' in host:
|
||||
host, port = host.split(':')
|
||||
else:
|
||||
port = 22
|
||||
port = None
|
||||
if scheme in ('ssh', 'git+ssh', 'ssh+git'):
|
||||
return _open_ssh(host, port)
|
||||
return False
|
||||
@ -430,7 +437,7 @@ def _preconnect(url):
|
||||
m = URI_SCP.match(url)
|
||||
if m:
|
||||
host = m.group(1)
|
||||
return _open_ssh(host, 22)
|
||||
return _open_ssh(host)
|
||||
|
||||
return False
|
||||
|
||||
@ -524,8 +531,11 @@ class Remote(object):
|
||||
def SshReviewUrl(self, userEmail):
|
||||
if self.ReviewProtocol != 'ssh':
|
||||
return None
|
||||
username = self._config.GetString('review.%s.username' % self.review)
|
||||
if username is None:
|
||||
username = userEmail.split("@")[0]
|
||||
return 'ssh://%s@%s:%s/%s' % (
|
||||
userEmail.split("@")[0],
|
||||
username,
|
||||
self._review_host,
|
||||
self._review_port,
|
||||
self.projectname)
|
||||
|
@ -13,10 +13,13 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import sys
|
||||
from time import time
|
||||
from trace import IsTrace
|
||||
|
||||
_NOT_TTY = not os.isatty(2)
|
||||
|
||||
class Progress(object):
|
||||
def __init__(self, title, total=0):
|
||||
self._title = title
|
||||
@ -29,7 +32,7 @@ class Progress(object):
|
||||
def update(self, inc=1):
|
||||
self._done += inc
|
||||
|
||||
if IsTrace():
|
||||
if _NOT_TTY or IsTrace():
|
||||
return
|
||||
|
||||
if not self._show:
|
||||
@ -56,7 +59,7 @@ class Progress(object):
|
||||
sys.stderr.flush()
|
||||
|
||||
def end(self):
|
||||
if IsTrace() or not self._show:
|
||||
if _NOT_TTY or IsTrace() or not self._show:
|
||||
return
|
||||
|
||||
if self._total <= 0:
|
||||
|
59
project.py
59
project.py
@ -149,10 +149,11 @@ class ReviewableBranch(object):
|
||||
R_HEADS + self.name,
|
||||
'--')
|
||||
|
||||
def UploadForReview(self, people):
|
||||
def UploadForReview(self, people, auto_topic=False):
|
||||
self.project.UploadForReview(self.name,
|
||||
self.replace_changes,
|
||||
people)
|
||||
people,
|
||||
auto_topic=auto_topic)
|
||||
|
||||
def GetPublishedRefs(self):
|
||||
refs = {}
|
||||
@ -203,6 +204,10 @@ class _CopyFile:
|
||||
# remove existing file first, since it might be read-only
|
||||
if os.path.exists(dest):
|
||||
os.remove(dest)
|
||||
else:
|
||||
dir = os.path.dirname(dest)
|
||||
if not os.path.isdir(dir):
|
||||
os.makedirs(dir)
|
||||
shutil.copy(src, dest)
|
||||
# make the file read-only
|
||||
mode = os.stat(dest)[stat.ST_MODE]
|
||||
@ -364,6 +369,27 @@ class Project(object):
|
||||
|
||||
## Status Display ##
|
||||
|
||||
def HasChanges(self):
|
||||
"""Returns true if there are uncommitted changes.
|
||||
"""
|
||||
self.work_git.update_index('-q',
|
||||
'--unmerged',
|
||||
'--ignore-missing',
|
||||
'--refresh')
|
||||
if self.IsRebaseInProgress():
|
||||
return True
|
||||
|
||||
if self.work_git.DiffZ('diff-index', '--cached', HEAD):
|
||||
return True
|
||||
|
||||
if self.work_git.DiffZ('diff-files'):
|
||||
return True
|
||||
|
||||
if self.work_git.LsOthers():
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def PrintWorkTreeStatus(self):
|
||||
"""Prints the status of the repository to stdout.
|
||||
"""
|
||||
@ -530,7 +556,10 @@ class Project(object):
|
||||
return rb
|
||||
return None
|
||||
|
||||
def UploadForReview(self, branch=None, replace_changes=None, people=([],[])):
|
||||
def UploadForReview(self, branch=None,
|
||||
replace_changes=None,
|
||||
people=([],[]),
|
||||
auto_topic=False):
|
||||
"""Uploads the named branch for code review.
|
||||
"""
|
||||
if branch is None:
|
||||
@ -562,10 +591,15 @@ class Project(object):
|
||||
for e in people[1]:
|
||||
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(branch.remote.SshReviewUrl(self.UserEmail))
|
||||
cmd.append('%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch))
|
||||
cmd.append(ref_spec)
|
||||
|
||||
if replace_changes:
|
||||
for change_id,commit_id in replace_changes.iteritems():
|
||||
cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id))
|
||||
@ -597,6 +631,18 @@ class Project(object):
|
||||
if not self._RemoteFetch():
|
||||
return False
|
||||
|
||||
#Check that the requested ref was found after fetch
|
||||
#
|
||||
try:
|
||||
self.GetRevisionId()
|
||||
except ManifestInvalidRevisionError:
|
||||
# if the ref is a tag. We can try fetching
|
||||
# the tag manually as a last resort
|
||||
#
|
||||
rev = self.revisionExpr
|
||||
if rev.startswith(R_TAGS):
|
||||
self._RemoteFetch(None, rev[len(R_TAGS):])
|
||||
|
||||
if self.worktree:
|
||||
self._InitMRef()
|
||||
else:
|
||||
@ -978,7 +1024,7 @@ class Project(object):
|
||||
|
||||
## Direct Git Commands ##
|
||||
|
||||
def _RemoteFetch(self, name=None):
|
||||
def _RemoteFetch(self, name=None, tag=None):
|
||||
if not name:
|
||||
name = self.remote.name
|
||||
|
||||
@ -990,6 +1036,9 @@ class Project(object):
|
||||
if not self.worktree:
|
||||
cmd.append('--update-head-ok')
|
||||
cmd.append(name)
|
||||
if tag is not None:
|
||||
cmd.append('tag')
|
||||
cmd.append(tag)
|
||||
return GitCommand(self,
|
||||
cmd,
|
||||
bare = True,
|
||||
|
@ -204,7 +204,7 @@ contain a line that matches both expressions:
|
||||
else:
|
||||
out.project('--- project %s ---' % project.relpath)
|
||||
out.nl()
|
||||
out.write(p.stderr)
|
||||
out.write("%s", p.stderr)
|
||||
out.nl()
|
||||
continue
|
||||
have_match = True
|
||||
@ -217,17 +217,17 @@ contain a line that matches both expressions:
|
||||
if have_rev and full_name:
|
||||
for line in r:
|
||||
rev, line = line.split(':', 1)
|
||||
out.write(rev)
|
||||
out.write("%s", rev)
|
||||
out.write(':')
|
||||
out.project(project.relpath)
|
||||
out.write('/')
|
||||
out.write(line)
|
||||
out.write("%s", line)
|
||||
out.nl()
|
||||
elif full_name:
|
||||
for line in r:
|
||||
out.project(project.relpath)
|
||||
out.write('/')
|
||||
out.write(line)
|
||||
out.write("%s", line)
|
||||
out.nl()
|
||||
else:
|
||||
for line in r:
|
||||
|
75
subcmds/rebase.py
Normal file
75
subcmds/rebase.py
Normal file
@ -0,0 +1,75 @@
|
||||
#
|
||||
# Copyright (C) 2010 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 sys
|
||||
|
||||
from command import Command
|
||||
from git_command import GitCommand
|
||||
from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
|
||||
from error import GitError
|
||||
|
||||
class Rebase(Command):
|
||||
common = True
|
||||
helpSummary = "Rebase local branches on upstream branch"
|
||||
helpUsage = """
|
||||
%prog {[<project>...] | -i <project>...}
|
||||
"""
|
||||
helpDescription = """
|
||||
'%prog' uses git rebase to move local changes in the current topic branch to
|
||||
the HEAD of the upstream history, useful when you have made commits in a topic
|
||||
branch but need to incorporate new upstream changes "underneath" them.
|
||||
"""
|
||||
|
||||
def _Options(self, p):
|
||||
p.add_option('-i', '--interactive',
|
||||
dest="interactive", action="store_true",
|
||||
help="interactive rebase (single project only)")
|
||||
|
||||
def Execute(self, opt, args):
|
||||
all = self.GetProjects(args)
|
||||
one_project = len(all) == 1
|
||||
|
||||
if opt.interactive and not one_project:
|
||||
print >>sys.stderr, 'error: interactive rebase not supported with multiple projects'
|
||||
return -1
|
||||
|
||||
for project in all:
|
||||
cb = project.CurrentBranch
|
||||
if not cb:
|
||||
if one_project:
|
||||
print >>sys.stderr, "error: project %s has a detatched HEAD" % project.name
|
||||
return -1
|
||||
# ignore branches with detatched HEADs
|
||||
continue
|
||||
|
||||
upbranch = project.GetBranch(cb)
|
||||
if not upbranch.LocalMerge:
|
||||
if one_project:
|
||||
print >>sys.stderr, "error: project %s does not track any remote branches" % project.name
|
||||
return -1
|
||||
# ignore branches without remotes
|
||||
continue
|
||||
|
||||
upstream = project.GetRevisionId()
|
||||
|
||||
args = ["rebase"]
|
||||
if opt.interactive:
|
||||
args.append("-i")
|
||||
args.append(upstream)
|
||||
|
||||
print '# project %s: rebasing branch %s -> %s (%s)' % (
|
||||
project.relpath, cb, upbranch.LocalMerge, upstream[0:7])
|
||||
if GitCommand(project, args).Wait() != 0:
|
||||
return -1
|
33
subcmds/smartsync.py
Normal file
33
subcmds/smartsync.py
Normal file
@ -0,0 +1,33 @@
|
||||
#
|
||||
# Copyright (C) 2010 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.
|
||||
|
||||
from sync import Sync
|
||||
|
||||
class Smartsync(Sync):
|
||||
common = True
|
||||
helpSummary = "Update working tree to the latest known good revision"
|
||||
helpUsage = """
|
||||
%prog [<project>...]
|
||||
"""
|
||||
helpDescription = """
|
||||
The '%prog' command is a shortcut for sync -s.
|
||||
"""
|
||||
|
||||
def _Options(self, p):
|
||||
Sync._Options(self, p, show_smart=False)
|
||||
|
||||
def Execute(self, opt, args):
|
||||
opt.smart_sync = True
|
||||
Sync.Execute(self, opt, args)
|
@ -23,6 +23,11 @@ import sys
|
||||
import time
|
||||
import xmlrpclib
|
||||
|
||||
try:
|
||||
import threading as _threading
|
||||
except ImportError:
|
||||
import dummy_threading as _threading
|
||||
|
||||
from git_command import GIT
|
||||
from git_refs import R_HEADS
|
||||
from project import HEAD
|
||||
@ -35,6 +40,7 @@ from project import SyncBuffer
|
||||
from progress import Progress
|
||||
|
||||
class Sync(Command, MirrorSafeCommand):
|
||||
jobs = 1
|
||||
common = True
|
||||
helpSummary = "Update working tree to the latest revision"
|
||||
helpUsage = """
|
||||
@ -94,7 +100,7 @@ later is required to fix a server side protocol bug.
|
||||
|
||||
"""
|
||||
|
||||
def _Options(self, p):
|
||||
def _Options(self, p, show_smart=True):
|
||||
p.add_option('-l','--local-only',
|
||||
dest='local_only', action='store_true',
|
||||
help="only update working tree, don't fetch")
|
||||
@ -104,6 +110,10 @@ later is required to fix a server side protocol bug.
|
||||
p.add_option('-d','--detach',
|
||||
dest='detach_head', action='store_true',
|
||||
help='detach projects back to manifest revision')
|
||||
p.add_option('-j','--jobs',
|
||||
dest='jobs', action='store', type='int',
|
||||
help="number of projects to fetch simultaneously")
|
||||
if show_smart:
|
||||
p.add_option('-s', '--smart-sync',
|
||||
dest='smart_sync', action='store_true',
|
||||
help='smart sync using manifest from a known good build')
|
||||
@ -116,9 +126,23 @@ later is required to fix a server side protocol bug.
|
||||
dest='repo_upgraded', action='store_true',
|
||||
help=SUPPRESS_HELP)
|
||||
|
||||
def _FetchHelper(self, project, lock, fetched, pm, sem):
|
||||
if not project.Sync_NetworkHalf():
|
||||
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
||||
sem.release()
|
||||
sys.exit(1)
|
||||
|
||||
lock.acquire()
|
||||
fetched.add(project.gitdir)
|
||||
pm.update()
|
||||
lock.release()
|
||||
sem.release()
|
||||
|
||||
def _Fetch(self, projects):
|
||||
fetched = set()
|
||||
pm = Progress('Fetching projects', len(projects))
|
||||
|
||||
if self.jobs == 1:
|
||||
for project in projects:
|
||||
pm.update()
|
||||
if project.Sync_NetworkHalf():
|
||||
@ -126,6 +150,20 @@ later is required to fix a server side protocol bug.
|
||||
else:
|
||||
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
||||
sys.exit(1)
|
||||
else:
|
||||
threads = set()
|
||||
lock = _threading.Lock()
|
||||
sem = _threading.Semaphore(self.jobs)
|
||||
for project in projects:
|
||||
sem.acquire()
|
||||
t = _threading.Thread(target = self._FetchHelper,
|
||||
args = (project, lock, fetched, pm, sem))
|
||||
threads.add(t)
|
||||
t.start()
|
||||
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
pm.end()
|
||||
return fetched
|
||||
|
||||
@ -189,6 +227,8 @@ uncommitted changes are present' % project.relpath
|
||||
return 0
|
||||
|
||||
def Execute(self, opt, args):
|
||||
if opt.jobs:
|
||||
self.jobs = opt.jobs
|
||||
if opt.network_only and opt.detach_head:
|
||||
print >>sys.stderr, 'error: cannot combine -n and -d'
|
||||
sys.exit(1)
|
||||
|
@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import copy
|
||||
import re
|
||||
import sys
|
||||
|
||||
@ -83,6 +84,19 @@ to "true" then repo will assume you always answer "y" at the prompt,
|
||||
and will not prompt you further. If it is set to "false" then repo
|
||||
will assume you always answer "n", and will abort.
|
||||
|
||||
review.URL.autocopy:
|
||||
|
||||
To automatically copy a user or mailing list to all uploaded reviews,
|
||||
you can set a per-project or global Git option to do so. Specifically,
|
||||
review.URL.autocopy can be set to a comma separated list of reviewers
|
||||
who you always want copied on all uploads with a non-empty --re
|
||||
argument.
|
||||
|
||||
review.URL.username:
|
||||
|
||||
Override the username used to connect to Gerrit Code Review.
|
||||
By default the local part of the email address is used.
|
||||
|
||||
The URL must match the review URL listed in the manifest XML file,
|
||||
or in the .git/config within the project. For example:
|
||||
|
||||
@ -92,6 +106,7 @@ or in the .git/config within the project. For example:
|
||||
|
||||
[review "http://review.example.com/"]
|
||||
autoupload = true
|
||||
autocopy = johndoe@company.com,my-team-alias@company.com
|
||||
|
||||
References
|
||||
----------
|
||||
@ -101,6 +116,9 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
||||
"""
|
||||
|
||||
def _Options(self, p):
|
||||
p.add_option('-t',
|
||||
dest='auto_topic', action='store_true',
|
||||
help='Send local branch name to Gerrit Code Review')
|
||||
p.add_option('--replace',
|
||||
dest='replace', action='store_true',
|
||||
help='Upload replacement patchesets from this branch')
|
||||
@ -111,7 +129,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
||||
type='string', action='append', dest='cc',
|
||||
help='Also send email to these email addresses.')
|
||||
|
||||
def _SingleBranch(self, branch, people):
|
||||
def _SingleBranch(self, opt, branch, people):
|
||||
project = branch.project
|
||||
name = branch.name
|
||||
remote = project.GetBranch(name).remote
|
||||
@ -144,11 +162,11 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
||||
answer = _ConfirmManyUploads()
|
||||
|
||||
if answer:
|
||||
self._UploadAndReport([branch], people)
|
||||
self._UploadAndReport(opt, [branch], people)
|
||||
else:
|
||||
_die("upload aborted by user")
|
||||
|
||||
def _MultipleBranches(self, pending, people):
|
||||
def _MultipleBranches(self, opt, pending, people):
|
||||
projects = {}
|
||||
branches = {}
|
||||
|
||||
@ -217,7 +235,20 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
||||
if not _ConfirmManyUploads(multiple_branches=True):
|
||||
_die("upload aborted by user")
|
||||
|
||||
self._UploadAndReport(todo, people)
|
||||
self._UploadAndReport(opt, todo, people)
|
||||
|
||||
def _AppendAutoCcList(self, branch, people):
|
||||
"""
|
||||
Appends the list of users in the CC list in the git project's config if a
|
||||
non-empty reviewer list was found.
|
||||
"""
|
||||
|
||||
name = branch.name
|
||||
project = branch.project
|
||||
key = 'review.%s.autocopy' % project.GetBranch(name).remote.review
|
||||
raw_list = project.config.GetString(key)
|
||||
if not raw_list is None and len(people[0]) > 0:
|
||||
people[1].extend([entry.strip() for entry in raw_list.split(',')])
|
||||
|
||||
def _FindGerritChange(self, branch):
|
||||
last_pub = branch.project.WasPublished(branch.name)
|
||||
@ -288,13 +319,31 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
||||
_die("upload aborted by user")
|
||||
|
||||
branch.replace_changes = to_replace
|
||||
self._UploadAndReport([branch], people)
|
||||
self._UploadAndReport(opt, [branch], people)
|
||||
|
||||
def _UploadAndReport(self, todo, people):
|
||||
def _UploadAndReport(self, opt, todo, original_people):
|
||||
have_errors = False
|
||||
for branch in todo:
|
||||
try:
|
||||
branch.UploadForReview(people)
|
||||
people = copy.deepcopy(original_people)
|
||||
self._AppendAutoCcList(branch, people)
|
||||
|
||||
# Check if there are local changes that may have been forgotten
|
||||
if branch.project.HasChanges():
|
||||
key = 'review.%s.autoupload' % branch.project.remote.review
|
||||
answer = branch.project.config.GetBoolean(key)
|
||||
|
||||
# if they want to auto upload, let's not ask because it could be automated
|
||||
if answer is None:
|
||||
sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/n) ')
|
||||
a = sys.stdin.readline().strip().lower()
|
||||
if a not in ('y', 'yes', 't', 'true', 'on'):
|
||||
print >>sys.stderr, "skipping upload"
|
||||
branch.uploaded = False
|
||||
branch.error = 'User aborted'
|
||||
continue
|
||||
|
||||
branch.UploadForReview(people, auto_topic=opt.auto_topic)
|
||||
branch.uploaded = True
|
||||
except UploadError, e:
|
||||
branch.error = e
|
||||
@ -350,6 +399,6 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
||||
if not pending:
|
||||
print >>sys.stdout, "no branches ready for upload"
|
||||
elif len(pending) == 1 and len(pending[0][1]) == 1:
|
||||
self._SingleBranch(pending[0][1][0], people)
|
||||
self._SingleBranch(opt, pending[0][1][0], people)
|
||||
else:
|
||||
self._MultipleBranches(pending, people)
|
||||
self._MultipleBranches(opt, pending, people)
|
||||
|
Reference in New Issue
Block a user