mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-26 20:17:52 +00:00
Compare commits
39 Commits
Author | SHA1 | Date | |
---|---|---|---|
a22f99ae41 | |||
3575b8f8bd | |||
a5ece0e050 | |||
cc50bac8c7 | |||
0cb1b3f687 | |||
9e426aa432 | |||
08a3f68d38 | |||
feb39d61ef | |||
7198572dd7 | |||
2daf66740b | |||
f4f04d9fa8 | |||
18afd7f679 | |||
6623b21e10 | |||
ca8c32cd7a | |||
f0a9a1a30e | |||
879a9a5cf0 | |||
ff6929dde8 | |||
1c85f4e43b | |||
719965af35 | |||
5732e47ebb | |||
f3fdf823cf | |||
a1bfd2cd72 | |||
6d7508b3d5 | |||
9452e4ec09 | |||
4c50deea28 | |||
d63060fc95 | |||
b6ea3bfcc3 | |||
aa4982e4c9 | |||
9bb1816bdc | |||
c24c720b61 | |||
2d1a396897 | |||
1dcb58a7d0 | |||
37dbf2bf0f | |||
438c54713a | |||
e020ebee4e | |||
21c5c34ee2 | |||
54fccd71fb | |||
fb5c8fd948 | |||
26120ca18d |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
|
.repopickle_*
|
||||||
|
80
SUBMITTING_PATCHES
Normal file
80
SUBMITTING_PATCHES
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
Short Version:
|
||||||
|
|
||||||
|
- Make small logical changes.
|
||||||
|
- Provide a meaningful commit message.
|
||||||
|
- Make sure all code is under the Apache License, 2.0.
|
||||||
|
- Publish your changes for review:
|
||||||
|
|
||||||
|
git push ssh://review.source.android.com:29418/tools/repo.git HEAD:refs/for/master
|
||||||
|
|
||||||
|
|
||||||
|
Long Version:
|
||||||
|
|
||||||
|
I wanted a file describing how to submit patches for repo,
|
||||||
|
so I started with the one found in the core Git distribution
|
||||||
|
(Documentation/SubmittingPatches), which itself was based on the
|
||||||
|
patch submission guidelines for the Linux kernel.
|
||||||
|
|
||||||
|
However there are some differences, so please review and familiarize
|
||||||
|
yourself with the following relevant bits:
|
||||||
|
|
||||||
|
|
||||||
|
(1) Make separate commits for logically separate changes.
|
||||||
|
|
||||||
|
Unless your patch is really trivial, you should not be sending
|
||||||
|
out a patch that was generated between your working tree and your
|
||||||
|
commit head. Instead, always make a commit with complete commit
|
||||||
|
message and generate a series of patches from your repository.
|
||||||
|
It is a good discipline.
|
||||||
|
|
||||||
|
Describe the technical detail of the change(s).
|
||||||
|
|
||||||
|
If your description starts to get too long, that's a sign that you
|
||||||
|
probably need to split up your commit to finer grained pieces.
|
||||||
|
|
||||||
|
|
||||||
|
(2) Check the license
|
||||||
|
|
||||||
|
repo is licensed under the Apache License, 2.0.
|
||||||
|
|
||||||
|
Because of this licensing model *every* file within the project
|
||||||
|
*must* list the license that covers it in the header of the file.
|
||||||
|
Any new contributions to an existing file *must* be submitted under
|
||||||
|
the current license of that file. Any new files *must* clearly
|
||||||
|
indicate which license they are provided under in the file header.
|
||||||
|
|
||||||
|
Please verify that you are legally allowed and willing to submit your
|
||||||
|
changes under the license covering each file *prior* to submitting
|
||||||
|
your patch. It is virtually impossible to remove a patch once it
|
||||||
|
has been applied and pushed out.
|
||||||
|
|
||||||
|
|
||||||
|
(3) Sending your patches.
|
||||||
|
|
||||||
|
Do not email your patches to anyone.
|
||||||
|
|
||||||
|
Instead, login to the Gerrit Code Review tool at:
|
||||||
|
|
||||||
|
https://review.source.android.com/
|
||||||
|
|
||||||
|
Ensure you have completed one of the necessary contributor
|
||||||
|
agreements, providing documentation to the project maintainers that
|
||||||
|
they have right to redistribute your work under the Apache License:
|
||||||
|
|
||||||
|
https://review.source.android.com/#settings,agreements
|
||||||
|
|
||||||
|
Ensure you have registered one or more SSH public keys, so you can
|
||||||
|
push your commits directly over SSH:
|
||||||
|
|
||||||
|
https://review.source.android.com/#settings,ssh-keys
|
||||||
|
|
||||||
|
Push your patches over SSH to the review server, possibly through
|
||||||
|
a remembered remote to make this easier in the future:
|
||||||
|
|
||||||
|
git config remote.review.url ssh://review.source.android.com:29418/tools/repo.git
|
||||||
|
git config remote.review.push HEAD:refs/for/master
|
||||||
|
|
||||||
|
git push review
|
||||||
|
|
||||||
|
You will be automatically emailed a copy of your commits, and any
|
||||||
|
comments made by the project maintainers.
|
@ -22,6 +22,7 @@ following DTD:
|
|||||||
<!DOCTYPE manifest [
|
<!DOCTYPE manifest [
|
||||||
<!ELEMENT manifest (remote*,
|
<!ELEMENT manifest (remote*,
|
||||||
default?,
|
default?,
|
||||||
|
manifest-server?,
|
||||||
remove-project*,
|
remove-project*,
|
||||||
project*)>
|
project*)>
|
||||||
|
|
||||||
@ -33,6 +34,9 @@ following DTD:
|
|||||||
<!ELEMENT default (EMPTY)>
|
<!ELEMENT default (EMPTY)>
|
||||||
<!ATTLIST default remote IDREF #IMPLIED>
|
<!ATTLIST default remote IDREF #IMPLIED>
|
||||||
<!ATTLIST default revision CDATA #IMPLIED>
|
<!ATTLIST default revision CDATA #IMPLIED>
|
||||||
|
|
||||||
|
<!ELEMENT manifest-server (EMPTY)>
|
||||||
|
<!ATTLIST url CDATA #REQUIRED>
|
||||||
|
|
||||||
<!ELEMENT project (EMPTY)>
|
<!ELEMENT project (EMPTY)>
|
||||||
<!ATTLIST project name CDATA #REQUIRED>
|
<!ATTLIST project name CDATA #REQUIRED>
|
||||||
@ -89,6 +93,27 @@ Attribute `revision`: Name of a Git branch (e.g. `master` or
|
|||||||
revision attribute will use this revision.
|
revision attribute will use this revision.
|
||||||
|
|
||||||
|
|
||||||
|
Element manifest-server
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
At most one manifest-server may be specified. The url attribute
|
||||||
|
is used to specify the URL of a manifest server, which is an
|
||||||
|
XML RPC service that will return a manifest in which each project
|
||||||
|
is pegged to a known good revision for the current branch and
|
||||||
|
target.
|
||||||
|
|
||||||
|
The manifest server should implement:
|
||||||
|
|
||||||
|
GetApprovedManifest(branch, target)
|
||||||
|
|
||||||
|
The target to use is defined by environment variables TARGET_PRODUCT
|
||||||
|
and TARGET_BUILD_VARIANT. These variables are used to create a string
|
||||||
|
of the form $TARGET_PRODUCT-$TARGET_BUILD_VARIANT, e.g. passion-userdebug.
|
||||||
|
If one of those variables or both are not present, the program will call
|
||||||
|
GetApprovedManifest without the target paramater and the manifest server
|
||||||
|
should choose a reasonable default target.
|
||||||
|
|
||||||
|
|
||||||
Element project
|
Element project
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
32
editor.py
32
editor.py
@ -14,6 +14,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -38,9 +39,10 @@ class Editor(object):
|
|||||||
if e:
|
if e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
e = cls.globalConfig.GetString('core.editor')
|
if cls.globalConfig:
|
||||||
if e:
|
e = cls.globalConfig.GetString('core.editor')
|
||||||
return e
|
if e:
|
||||||
|
return e
|
||||||
|
|
||||||
e = os.getenv('VISUAL')
|
e = os.getenv('VISUAL')
|
||||||
if e:
|
if e:
|
||||||
@ -69,15 +71,33 @@ least one of these before using this command."""
|
|||||||
Returns:
|
Returns:
|
||||||
new value of edited text; None if editing did not succeed
|
new value of edited text; None if editing did not succeed
|
||||||
"""
|
"""
|
||||||
editor = cls._GetEditor().split()
|
editor = cls._GetEditor()
|
||||||
|
if editor == ':':
|
||||||
|
return data
|
||||||
|
|
||||||
fd, path = tempfile.mkstemp()
|
fd, path = tempfile.mkstemp()
|
||||||
try:
|
try:
|
||||||
os.write(fd, data)
|
os.write(fd, data)
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
fd = None
|
fd = None
|
||||||
|
|
||||||
if subprocess.Popen(editor + [path]).wait() != 0:
|
if re.compile("^.*[$ \t'].*$").match(editor):
|
||||||
raise EditorError()
|
args = [editor + ' "$@"']
|
||||||
|
shell = True
|
||||||
|
else:
|
||||||
|
args = [editor]
|
||||||
|
shell = False
|
||||||
|
args.append(path)
|
||||||
|
|
||||||
|
try:
|
||||||
|
rc = subprocess.Popen(args, shell=shell).wait()
|
||||||
|
except OSError, e:
|
||||||
|
raise EditorError('editor failed, %s: %s %s'
|
||||||
|
% (str(e), editor, path))
|
||||||
|
if rc != 0:
|
||||||
|
raise EditorError('editor failed with exit status %d: %s %s'
|
||||||
|
% (rc, editor, path))
|
||||||
|
|
||||||
fd2 = open(path)
|
fd2 = open(path)
|
||||||
try:
|
try:
|
||||||
return fd2.read()
|
return fd2.read()
|
||||||
|
5
error.py
5
error.py
@ -24,6 +24,11 @@ class ManifestInvalidRevisionError(Exception):
|
|||||||
class EditorError(Exception):
|
class EditorError(Exception):
|
||||||
"""Unspecified error from the user's text editor.
|
"""Unspecified error from the user's text editor.
|
||||||
"""
|
"""
|
||||||
|
def __init__(self, reason):
|
||||||
|
self.reason = reason
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.reason
|
||||||
|
|
||||||
class GitError(Exception):
|
class GitError(Exception):
|
||||||
"""Unspecified internal error from git.
|
"""Unspecified internal error from git.
|
||||||
|
@ -17,6 +17,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from signal import SIGTERM
|
||||||
from error import GitError
|
from error import GitError
|
||||||
from trace import REPO_TRACE, IsTrace, Trace
|
from trace import REPO_TRACE, IsTrace, Trace
|
||||||
|
|
||||||
@ -29,8 +30,9 @@ LAST_CWD = None
|
|||||||
|
|
||||||
_ssh_proxy_path = None
|
_ssh_proxy_path = None
|
||||||
_ssh_sock_path = None
|
_ssh_sock_path = None
|
||||||
|
_ssh_clients = []
|
||||||
|
|
||||||
def _ssh_sock(create=True):
|
def ssh_sock(create=True):
|
||||||
global _ssh_sock_path
|
global _ssh_sock_path
|
||||||
if _ssh_sock_path is None:
|
if _ssh_sock_path is None:
|
||||||
if not create:
|
if not create:
|
||||||
@ -51,6 +53,24 @@ def _ssh_proxy():
|
|||||||
'git_ssh')
|
'git_ssh')
|
||||||
return _ssh_proxy_path
|
return _ssh_proxy_path
|
||||||
|
|
||||||
|
def _add_ssh_client(p):
|
||||||
|
_ssh_clients.append(p)
|
||||||
|
|
||||||
|
def _remove_ssh_client(p):
|
||||||
|
try:
|
||||||
|
_ssh_clients.remove(p)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def terminate_ssh_clients():
|
||||||
|
global _ssh_clients
|
||||||
|
for p in _ssh_clients:
|
||||||
|
try:
|
||||||
|
os.kill(p.pid, SIGTERM)
|
||||||
|
p.wait()
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
_ssh_clients = []
|
||||||
|
|
||||||
class _GitCall(object):
|
class _GitCall(object):
|
||||||
def version(self):
|
def version(self):
|
||||||
@ -119,7 +139,7 @@ class GitCommand(object):
|
|||||||
if disable_editor:
|
if disable_editor:
|
||||||
env['GIT_EDITOR'] = ':'
|
env['GIT_EDITOR'] = ':'
|
||||||
if ssh_proxy:
|
if ssh_proxy:
|
||||||
env['REPO_SSH_SOCK'] = _ssh_sock()
|
env['REPO_SSH_SOCK'] = ssh_sock()
|
||||||
env['GIT_SSH'] = _ssh_proxy()
|
env['GIT_SSH'] = _ssh_proxy()
|
||||||
|
|
||||||
if project:
|
if project:
|
||||||
@ -188,6 +208,9 @@ class GitCommand(object):
|
|||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise GitError('%s: %s' % (command[1], e))
|
raise GitError('%s: %s' % (command[1], e))
|
||||||
|
|
||||||
|
if ssh_proxy:
|
||||||
|
_add_ssh_client(p)
|
||||||
|
|
||||||
self.process = p
|
self.process = p
|
||||||
self.stdin = p.stdin
|
self.stdin = p.stdin
|
||||||
|
|
||||||
@ -210,4 +233,8 @@ class GitCommand(object):
|
|||||||
else:
|
else:
|
||||||
p.stderr = None
|
p.stderr = None
|
||||||
|
|
||||||
return self.process.wait()
|
try:
|
||||||
|
rc = p.wait()
|
||||||
|
finally:
|
||||||
|
_remove_ssh_client(p)
|
||||||
|
return rc
|
||||||
|
@ -23,7 +23,10 @@ from signal import SIGTERM
|
|||||||
from urllib2 import urlopen, HTTPError
|
from urllib2 import urlopen, HTTPError
|
||||||
from error import GitError, UploadError
|
from error import GitError, UploadError
|
||||||
from trace import Trace
|
from trace import Trace
|
||||||
from git_command import GitCommand, _ssh_sock
|
|
||||||
|
from git_command import GitCommand
|
||||||
|
from git_command import ssh_sock
|
||||||
|
from git_command import terminate_ssh_clients
|
||||||
|
|
||||||
R_HEADS = 'refs/heads/'
|
R_HEADS = 'refs/heads/'
|
||||||
R_TAGS = 'refs/tags/'
|
R_TAGS = 'refs/tags/'
|
||||||
@ -259,21 +262,28 @@ class GitConfig(object):
|
|||||||
os.remove(self._pickle)
|
os.remove(self._pickle)
|
||||||
|
|
||||||
def _ReadGit(self):
|
def _ReadGit(self):
|
||||||
d = self._do('--null', '--list')
|
"""
|
||||||
c = {}
|
Read configuration data from git.
|
||||||
while d:
|
|
||||||
lf = d.index('\n')
|
|
||||||
nul = d.index('\0', lf + 1)
|
|
||||||
|
|
||||||
key = _key(d[0:lf])
|
This internal method populates the GitConfig cache.
|
||||||
val = d[lf + 1:nul]
|
|
||||||
|
"""
|
||||||
|
c = {}
|
||||||
|
d = self._do('--null', '--list')
|
||||||
|
if d is None:
|
||||||
|
return c
|
||||||
|
for line in d.rstrip('\0').split('\0'):
|
||||||
|
if '\n' in line:
|
||||||
|
key, val = line.split('\n', 1)
|
||||||
|
else:
|
||||||
|
key = line
|
||||||
|
val = None
|
||||||
|
|
||||||
if key in c:
|
if key in c:
|
||||||
c[key].append(val)
|
c[key].append(val)
|
||||||
else:
|
else:
|
||||||
c[key] = [val]
|
c[key] = [val]
|
||||||
|
|
||||||
d = d[nul + 1:]
|
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def _do(self, *args):
|
def _do(self, *args):
|
||||||
@ -349,10 +359,14 @@ class RefSpec(object):
|
|||||||
_ssh_cache = {}
|
_ssh_cache = {}
|
||||||
_ssh_master = True
|
_ssh_master = True
|
||||||
|
|
||||||
def _open_ssh(host, port):
|
def _open_ssh(host, port=None):
|
||||||
global _ssh_master
|
global _ssh_master
|
||||||
|
|
||||||
key = '%s:%s' % (host, port)
|
if port is not None:
|
||||||
|
key = '%s:%s' % (host, port)
|
||||||
|
else:
|
||||||
|
key = host
|
||||||
|
|
||||||
if key in _ssh_cache:
|
if key in _ssh_cache:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -364,11 +378,14 @@ def _open_ssh(host, port):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
command = ['ssh',
|
command = ['ssh',
|
||||||
'-o','ControlPath %s' % _ssh_sock(),
|
'-o','ControlPath %s' % ssh_sock(),
|
||||||
'-p',str(port),
|
|
||||||
'-M',
|
'-M',
|
||||||
'-N',
|
'-N',
|
||||||
host]
|
host]
|
||||||
|
|
||||||
|
if port is not None:
|
||||||
|
command[3:3] = ['-p',str(port)]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Trace(': %s', ' '.join(command))
|
Trace(': %s', ' '.join(command))
|
||||||
p = subprocess.Popen(command)
|
p = subprocess.Popen(command)
|
||||||
@ -384,12 +401,17 @@ def _open_ssh(host, port):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def close_ssh():
|
def close_ssh():
|
||||||
|
terminate_ssh_clients()
|
||||||
|
|
||||||
for key,p in _ssh_cache.iteritems():
|
for key,p in _ssh_cache.iteritems():
|
||||||
os.kill(p.pid, SIGTERM)
|
try:
|
||||||
p.wait()
|
os.kill(p.pid, SIGTERM)
|
||||||
|
p.wait()
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
_ssh_cache.clear()
|
_ssh_cache.clear()
|
||||||
|
|
||||||
d = _ssh_sock(create=False)
|
d = ssh_sock(create=False)
|
||||||
if d:
|
if d:
|
||||||
try:
|
try:
|
||||||
os.rmdir(os.path.dirname(d))
|
os.rmdir(os.path.dirname(d))
|
||||||
@ -407,7 +429,7 @@ def _preconnect(url):
|
|||||||
if ':' in host:
|
if ':' in host:
|
||||||
host, port = host.split(':')
|
host, port = host.split(':')
|
||||||
else:
|
else:
|
||||||
port = 22
|
port = None
|
||||||
if scheme in ('ssh', 'git+ssh', 'ssh+git'):
|
if scheme in ('ssh', 'git+ssh', 'ssh+git'):
|
||||||
return _open_ssh(host, port)
|
return _open_ssh(host, port)
|
||||||
return False
|
return False
|
||||||
@ -415,7 +437,7 @@ def _preconnect(url):
|
|||||||
m = URI_SCP.match(url)
|
m = URI_SCP.match(url)
|
||||||
if m:
|
if m:
|
||||||
host = m.group(1)
|
host = m.group(1)
|
||||||
return _open_ssh(host, 22)
|
return _open_ssh(host)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -432,8 +454,30 @@ class Remote(object):
|
|||||||
self._Get('fetch', all=True))
|
self._Get('fetch', all=True))
|
||||||
self._review_protocol = None
|
self._review_protocol = None
|
||||||
|
|
||||||
|
def _InsteadOf(self):
|
||||||
|
globCfg = GitConfig.ForUser()
|
||||||
|
urlList = globCfg.GetSubSections('url')
|
||||||
|
longest = ""
|
||||||
|
longestUrl = ""
|
||||||
|
|
||||||
|
for url in urlList:
|
||||||
|
key = "url." + url + ".insteadOf"
|
||||||
|
insteadOfList = globCfg.GetString(key, all=True)
|
||||||
|
|
||||||
|
for insteadOf in insteadOfList:
|
||||||
|
if self.url.startswith(insteadOf) \
|
||||||
|
and len(insteadOf) > len(longest):
|
||||||
|
longest = insteadOf
|
||||||
|
longestUrl = url
|
||||||
|
|
||||||
|
if len(longest) == 0:
|
||||||
|
return self.url
|
||||||
|
|
||||||
|
return self.url.replace(longest, longestUrl, 1)
|
||||||
|
|
||||||
def PreConnectFetch(self):
|
def PreConnectFetch(self):
|
||||||
return _preconnect(self.url)
|
connectionUrl = self._InsteadOf()
|
||||||
|
return _preconnect(connectionUrl)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ReviewProtocol(self):
|
def ReviewProtocol(self):
|
||||||
@ -487,8 +531,11 @@ class Remote(object):
|
|||||||
def SshReviewUrl(self, userEmail):
|
def SshReviewUrl(self, userEmail):
|
||||||
if self.ReviewProtocol != 'ssh':
|
if self.ReviewProtocol != 'ssh':
|
||||||
return None
|
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' % (
|
return 'ssh://%s@%s:%s/%s' % (
|
||||||
userEmail.split("@")[0],
|
username,
|
||||||
self._review_host,
|
self._review_host,
|
||||||
self._review_port,
|
self._review_port,
|
||||||
self.projectname)
|
self.projectname)
|
||||||
|
101
hooks/commit-msg
Executable file
101
hooks/commit-msg
Executable file
@ -0,0 +1,101 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# From Gerrit Code Review 2.1.2-rc2-33-g7e30c72
|
||||||
|
#
|
||||||
|
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
|
||||||
|
#
|
||||||
|
# Copyright (C) 2009 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
CHANGE_ID_AFTER="Bug|Issue"
|
||||||
|
MSG="$1"
|
||||||
|
|
||||||
|
# Check for, and add if missing, a unique Change-Id
|
||||||
|
#
|
||||||
|
add_ChangeId() {
|
||||||
|
clean_message=$(sed -e '
|
||||||
|
/^diff --git a\/.*/{
|
||||||
|
s///
|
||||||
|
q
|
||||||
|
}
|
||||||
|
/^Signed-off-by:/d
|
||||||
|
/^#/d
|
||||||
|
' "$MSG" | git stripspace)
|
||||||
|
if test -z "$clean_message"
|
||||||
|
then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -i '^Change-Id:' "$MSG" >/dev/null
|
||||||
|
then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
id=$(_gen_ChangeId)
|
||||||
|
perl -e '
|
||||||
|
$MSG = shift;
|
||||||
|
$id = shift;
|
||||||
|
$CHANGE_ID_AFTER = shift;
|
||||||
|
|
||||||
|
undef $/;
|
||||||
|
open(I, $MSG); $_ = <I>; close I;
|
||||||
|
s|^diff --git a/.*||ms;
|
||||||
|
s|^#.*$||mg;
|
||||||
|
exit unless $_;
|
||||||
|
|
||||||
|
@message = split /\n/;
|
||||||
|
$haveFooter = 0;
|
||||||
|
$startFooter = @message;
|
||||||
|
for($line = @message - 1; $line >= 0; $line--) {
|
||||||
|
$_ = $message[$line];
|
||||||
|
|
||||||
|
($haveFooter++, next) if /^[a-zA-Z0-9-]+:/;
|
||||||
|
next if /^[ []/;
|
||||||
|
$startFooter = $line if ($haveFooter && /^\r?$/);
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
|
@footer = @message[$startFooter+1..@message];
|
||||||
|
@message = @message[0..$startFooter];
|
||||||
|
push(@footer, "") unless @footer;
|
||||||
|
|
||||||
|
for ($line = 0; $line < @footer; $line++) {
|
||||||
|
$_ = $footer[$line];
|
||||||
|
next if /^($CHANGE_ID_AFTER):/i;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
splice(@footer, $line, 0, "Change-Id: I$id");
|
||||||
|
|
||||||
|
$_ = join("\n", @message, @footer);
|
||||||
|
open(O, ">$MSG"); print O; close O;
|
||||||
|
' "$MSG" "$id" "$CHANGE_ID_AFTER"
|
||||||
|
}
|
||||||
|
_gen_ChangeIdInput() {
|
||||||
|
echo "tree $(git write-tree)"
|
||||||
|
if parent=$(git rev-parse HEAD^0 2>/dev/null)
|
||||||
|
then
|
||||||
|
echo "parent $parent"
|
||||||
|
fi
|
||||||
|
echo "author $(git var GIT_AUTHOR_IDENT)"
|
||||||
|
echo "committer $(git var GIT_COMMITTER_IDENT)"
|
||||||
|
echo
|
||||||
|
printf '%s' "$clean_message"
|
||||||
|
}
|
||||||
|
_gen_ChangeId() {
|
||||||
|
_gen_ChangeIdInput |
|
||||||
|
git hash-object -t commit --stdin
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
add_ChangeId
|
@ -65,8 +65,8 @@ class XmlManifest(object):
|
|||||||
|
|
||||||
self._Unload()
|
self._Unload()
|
||||||
|
|
||||||
def Link(self, name):
|
def Override(self, name):
|
||||||
"""Update the repo metadata to use a different manifest.
|
"""Use a different manifest, just for the current instantiation.
|
||||||
"""
|
"""
|
||||||
path = os.path.join(self.manifestProject.worktree, name)
|
path = os.path.join(self.manifestProject.worktree, name)
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
@ -80,6 +80,11 @@ class XmlManifest(object):
|
|||||||
finally:
|
finally:
|
||||||
self.manifestFile = old
|
self.manifestFile = old
|
||||||
|
|
||||||
|
def Link(self, name):
|
||||||
|
"""Update the repo metadata to use a different manifest.
|
||||||
|
"""
|
||||||
|
self.Override(name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if os.path.exists(self.manifestFile):
|
if os.path.exists(self.manifestFile):
|
||||||
os.remove(self.manifestFile)
|
os.remove(self.manifestFile)
|
||||||
@ -123,6 +128,12 @@ class XmlManifest(object):
|
|||||||
root.appendChild(e)
|
root.appendChild(e)
|
||||||
root.appendChild(doc.createTextNode(''))
|
root.appendChild(doc.createTextNode(''))
|
||||||
|
|
||||||
|
if self._manifest_server:
|
||||||
|
e = doc.createElement('manifest-server')
|
||||||
|
e.setAttribute('url', self._manifest_server)
|
||||||
|
root.appendChild(e)
|
||||||
|
root.appendChild(doc.createTextNode(''))
|
||||||
|
|
||||||
sort_projects = list(self.projects.keys())
|
sort_projects = list(self.projects.keys())
|
||||||
sort_projects.sort()
|
sort_projects.sort()
|
||||||
|
|
||||||
@ -168,6 +179,11 @@ class XmlManifest(object):
|
|||||||
self._Load()
|
self._Load()
|
||||||
return self._default
|
return self._default
|
||||||
|
|
||||||
|
@property
|
||||||
|
def manifest_server(self):
|
||||||
|
self._Load()
|
||||||
|
return self._manifest_server
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def IsMirror(self):
|
def IsMirror(self):
|
||||||
return self.manifestProject.config.GetBoolean('repo.mirror')
|
return self.manifestProject.config.GetBoolean('repo.mirror')
|
||||||
@ -178,12 +194,13 @@ class XmlManifest(object):
|
|||||||
self._remotes = {}
|
self._remotes = {}
|
||||||
self._default = None
|
self._default = None
|
||||||
self.branch = None
|
self.branch = None
|
||||||
|
self._manifest_server = None
|
||||||
|
|
||||||
def _Load(self):
|
def _Load(self):
|
||||||
if not self._loaded:
|
if not self._loaded:
|
||||||
m = self.manifestProject
|
m = self.manifestProject
|
||||||
b = m.GetBranch(m.CurrentBranch).merge
|
b = m.GetBranch(m.CurrentBranch).merge
|
||||||
if b.startswith(R_HEADS):
|
if b is not None and b.startswith(R_HEADS):
|
||||||
b = b[len(R_HEADS):]
|
b = b[len(R_HEADS):]
|
||||||
self.branch = b
|
self.branch = b
|
||||||
|
|
||||||
@ -246,6 +263,15 @@ class XmlManifest(object):
|
|||||||
if self._default is None:
|
if self._default is None:
|
||||||
self._default = _Default()
|
self._default = _Default()
|
||||||
|
|
||||||
|
for node in config.childNodes:
|
||||||
|
if node.nodeName == 'manifest-server':
|
||||||
|
url = self._reqatt(node, 'url')
|
||||||
|
if self._manifest_server is not None:
|
||||||
|
raise ManifestParseError, \
|
||||||
|
'duplicate manifest-server in %s' % \
|
||||||
|
(self.manifestFile)
|
||||||
|
self._manifest_server = url
|
||||||
|
|
||||||
for node in config.childNodes:
|
for node in config.childNodes:
|
||||||
if node.nodeName == 'project':
|
if node.nodeName == 'project':
|
||||||
project = self._ParseProject(node)
|
project = self._ParseProject(node)
|
||||||
@ -315,7 +341,7 @@ class XmlManifest(object):
|
|||||||
def _ParseProject(self, node):
|
def _ParseProject(self, node):
|
||||||
"""
|
"""
|
||||||
reads a <project> element from the manifest file
|
reads a <project> element from the manifest file
|
||||||
"""
|
"""
|
||||||
name = self._reqatt(node, 'name')
|
name = self._reqatt(node, 'name')
|
||||||
|
|
||||||
remote = self._get_remote(node)
|
remote = self._get_remote(node)
|
||||||
|
@ -13,10 +13,13 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from time import time
|
from time import time
|
||||||
from trace import IsTrace
|
from trace import IsTrace
|
||||||
|
|
||||||
|
_NOT_TTY = not os.isatty(2)
|
||||||
|
|
||||||
class Progress(object):
|
class Progress(object):
|
||||||
def __init__(self, title, total=0):
|
def __init__(self, title, total=0):
|
||||||
self._title = title
|
self._title = title
|
||||||
@ -29,7 +32,7 @@ class Progress(object):
|
|||||||
def update(self, inc=1):
|
def update(self, inc=1):
|
||||||
self._done += inc
|
self._done += inc
|
||||||
|
|
||||||
if IsTrace():
|
if _NOT_TTY or IsTrace():
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self._show:
|
if not self._show:
|
||||||
@ -56,7 +59,7 @@ class Progress(object):
|
|||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
if IsTrace() or not self._show:
|
if _NOT_TTY or IsTrace() or not self._show:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._total <= 0:
|
if self._total <= 0:
|
||||||
|
99
project.py
99
project.py
@ -149,10 +149,11 @@ class ReviewableBranch(object):
|
|||||||
R_HEADS + self.name,
|
R_HEADS + self.name,
|
||||||
'--')
|
'--')
|
||||||
|
|
||||||
def UploadForReview(self, people):
|
def UploadForReview(self, people, auto_topic=False):
|
||||||
self.project.UploadForReview(self.name,
|
self.project.UploadForReview(self.name,
|
||||||
self.replace_changes,
|
self.replace_changes,
|
||||||
people)
|
people,
|
||||||
|
auto_topic=auto_topic)
|
||||||
|
|
||||||
def GetPublishedRefs(self):
|
def GetPublishedRefs(self):
|
||||||
refs = {}
|
refs = {}
|
||||||
@ -203,6 +204,10 @@ class _CopyFile:
|
|||||||
# remove existing file first, since it might be read-only
|
# remove existing file first, since it might be read-only
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
os.remove(dest)
|
os.remove(dest)
|
||||||
|
else:
|
||||||
|
dir = os.path.dirname(dest)
|
||||||
|
if not os.path.isdir(dir):
|
||||||
|
os.makedirs(dir)
|
||||||
shutil.copy(src, dest)
|
shutil.copy(src, dest)
|
||||||
# make the file read-only
|
# make the file read-only
|
||||||
mode = os.stat(dest)[stat.ST_MODE]
|
mode = os.stat(dest)[stat.ST_MODE]
|
||||||
@ -279,7 +284,7 @@ class Project(object):
|
|||||||
return os.path.exists(os.path.join(g, 'rebase-apply')) \
|
return os.path.exists(os.path.join(g, 'rebase-apply')) \
|
||||||
or os.path.exists(os.path.join(g, 'rebase-merge')) \
|
or os.path.exists(os.path.join(g, 'rebase-merge')) \
|
||||||
or os.path.exists(os.path.join(w, '.dotest'))
|
or os.path.exists(os.path.join(w, '.dotest'))
|
||||||
|
|
||||||
def IsDirty(self, consider_untracked=True):
|
def IsDirty(self, consider_untracked=True):
|
||||||
"""Is the working directory modified in some way?
|
"""Is the working directory modified in some way?
|
||||||
"""
|
"""
|
||||||
@ -364,6 +369,27 @@ class Project(object):
|
|||||||
|
|
||||||
## Status Display ##
|
## 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):
|
def PrintWorkTreeStatus(self):
|
||||||
"""Prints the status of the repository to stdout.
|
"""Prints the status of the repository to stdout.
|
||||||
"""
|
"""
|
||||||
@ -412,7 +438,7 @@ class Project(object):
|
|||||||
|
|
||||||
try: f = df[p]
|
try: f = df[p]
|
||||||
except KeyError: f = None
|
except KeyError: f = None
|
||||||
|
|
||||||
if i: i_status = i.status.upper()
|
if i: i_status = i.status.upper()
|
||||||
else: i_status = '-'
|
else: i_status = '-'
|
||||||
|
|
||||||
@ -530,7 +556,10 @@ class Project(object):
|
|||||||
return rb
|
return rb
|
||||||
return None
|
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.
|
"""Uploads the named branch for code review.
|
||||||
"""
|
"""
|
||||||
if branch is None:
|
if branch is None:
|
||||||
@ -562,10 +591,15 @@ class Project(object):
|
|||||||
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 = ['push']
|
||||||
cmd.append('--receive-pack=%s' % " ".join(rp))
|
cmd.append('--receive-pack=%s' % " ".join(rp))
|
||||||
cmd.append(branch.remote.SshReviewUrl(self.UserEmail))
|
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:
|
if replace_changes:
|
||||||
for change_id,commit_id in replace_changes.iteritems():
|
for change_id,commit_id in replace_changes.iteritems():
|
||||||
cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id))
|
cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id))
|
||||||
@ -597,6 +631,18 @@ class Project(object):
|
|||||||
if not self._RemoteFetch():
|
if not self._RemoteFetch():
|
||||||
return False
|
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:
|
if self.worktree:
|
||||||
self._InitMRef()
|
self._InitMRef()
|
||||||
else:
|
else:
|
||||||
@ -706,10 +752,9 @@ class Project(object):
|
|||||||
# commits are not yet merged upstream. We do not want
|
# commits are not yet merged upstream. We do not want
|
||||||
# to rewrite the published commits so we punt.
|
# to rewrite the published commits so we punt.
|
||||||
#
|
#
|
||||||
syncbuf.info(self,
|
syncbuf.fail(self,
|
||||||
"branch %s is published but is now %d commits behind",
|
"branch %s is published (but not merged) and is now %d commits behind"
|
||||||
branch.name,
|
% (branch.name, len(upstream_gain)))
|
||||||
len(upstream_gain))
|
|
||||||
return
|
return
|
||||||
elif pub == head:
|
elif pub == head:
|
||||||
# All published commits are merged, and thus we are a
|
# All published commits are merged, and thus we are a
|
||||||
@ -728,7 +773,7 @@ class Project(object):
|
|||||||
last_mine = None
|
last_mine = None
|
||||||
cnt_mine = 0
|
cnt_mine = 0
|
||||||
for commit in local_changes:
|
for commit in local_changes:
|
||||||
commit_id, committer_email = commit.split(' ', 2)
|
commit_id, committer_email = commit.split(' ', 1)
|
||||||
if committer_email == self.UserEmail:
|
if committer_email == self.UserEmail:
|
||||||
last_mine = commit_id
|
last_mine = commit_id
|
||||||
cnt_mine += 1
|
cnt_mine += 1
|
||||||
@ -979,7 +1024,7 @@ class Project(object):
|
|||||||
|
|
||||||
## Direct Git Commands ##
|
## Direct Git Commands ##
|
||||||
|
|
||||||
def _RemoteFetch(self, name=None):
|
def _RemoteFetch(self, name=None, tag=None):
|
||||||
if not name:
|
if not name:
|
||||||
name = self.remote.name
|
name = self.remote.name
|
||||||
|
|
||||||
@ -991,6 +1036,9 @@ class Project(object):
|
|||||||
if not self.worktree:
|
if not self.worktree:
|
||||||
cmd.append('--update-head-ok')
|
cmd.append('--update-head-ok')
|
||||||
cmd.append(name)
|
cmd.append(name)
|
||||||
|
if tag is not None:
|
||||||
|
cmd.append('tag')
|
||||||
|
cmd.append(tag)
|
||||||
return GitCommand(self,
|
return GitCommand(self,
|
||||||
cmd,
|
cmd,
|
||||||
bare = True,
|
bare = True,
|
||||||
@ -1056,13 +1104,27 @@ class Project(object):
|
|||||||
if not os.path.exists(hooks):
|
if not os.path.exists(hooks):
|
||||||
os.makedirs(hooks)
|
os.makedirs(hooks)
|
||||||
for stock_hook in repo_hooks():
|
for stock_hook in repo_hooks():
|
||||||
dst = os.path.join(hooks, os.path.basename(stock_hook))
|
name = os.path.basename(stock_hook)
|
||||||
|
|
||||||
|
if name in ('commit-msg') and not self.remote.review:
|
||||||
|
# Don't install a Gerrit Code Review hook if this
|
||||||
|
# project does not appear to use it for reviews.
|
||||||
|
#
|
||||||
|
continue
|
||||||
|
|
||||||
|
dst = os.path.join(hooks, name)
|
||||||
|
if os.path.islink(dst):
|
||||||
|
continue
|
||||||
|
if os.path.exists(dst):
|
||||||
|
if filecmp.cmp(stock_hook, dst, shallow=False):
|
||||||
|
os.remove(dst)
|
||||||
|
else:
|
||||||
|
_error("%s: Not replacing %s hook", self.relpath, name)
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
os.symlink(relpath(stock_hook, dst), dst)
|
os.symlink(relpath(stock_hook, dst), dst)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if e.errno == errno.EEXIST:
|
if e.errno == errno.EPERM:
|
||||||
pass
|
|
||||||
elif e.errno == errno.EPERM:
|
|
||||||
raise GitError('filesystem must support symlinks')
|
raise GitError('filesystem must support symlinks')
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
@ -1120,7 +1182,10 @@ class Project(object):
|
|||||||
try:
|
try:
|
||||||
src = os.path.join(self.gitdir, name)
|
src = os.path.join(self.gitdir, name)
|
||||||
dst = os.path.join(dotgit, name)
|
dst = os.path.join(dotgit, name)
|
||||||
os.symlink(relpath(src, dst), dst)
|
if os.path.islink(dst) or not os.path.exists(dst):
|
||||||
|
os.symlink(relpath(src, dst), dst)
|
||||||
|
else:
|
||||||
|
raise GitError('cannot overwrite a local work tree')
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if e.errno == errno.EPERM:
|
if e.errno == errno.EPERM:
|
||||||
raise GitError('filesystem must support symlinks')
|
raise GitError('filesystem must support symlinks')
|
||||||
|
@ -136,7 +136,7 @@ is shown, then the branch appears in all projects.
|
|||||||
hdr('%c%c %-*s' % (current, published, width, name))
|
hdr('%c%c %-*s' % (current, published, width, name))
|
||||||
out.write(' |')
|
out.write(' |')
|
||||||
|
|
||||||
if in_cnt < project_cnt and (in_cnt == 1):
|
if in_cnt < project_cnt:
|
||||||
fmt = out.write
|
fmt = out.write
|
||||||
paths = []
|
paths = []
|
||||||
if in_cnt < project_cnt - in_cnt:
|
if in_cnt < project_cnt - in_cnt:
|
||||||
@ -150,15 +150,17 @@ is shown, then the branch appears in all projects.
|
|||||||
for b in i.projects:
|
for b in i.projects:
|
||||||
have.add(b.project)
|
have.add(b.project)
|
||||||
for p in projects:
|
for p in projects:
|
||||||
paths.append(p.relpath)
|
if not p in have:
|
||||||
|
paths.append(p.relpath)
|
||||||
|
|
||||||
s = ' %s %s' % (type, ', '.join(paths))
|
s = ' %s %s' % (type, ', '.join(paths))
|
||||||
if width + 7 + len(s) < 80:
|
if width + 7 + len(s) < 80:
|
||||||
fmt(s)
|
fmt(s)
|
||||||
else:
|
else:
|
||||||
out.nl()
|
fmt(' %s:' % type)
|
||||||
fmt(' %s:' % type)
|
|
||||||
for p in paths:
|
for p in paths:
|
||||||
out.nl()
|
out.nl()
|
||||||
fmt(' %s' % p)
|
fmt(width*' ' + ' %s' % p)
|
||||||
|
else:
|
||||||
|
out.write(' in all projects')
|
||||||
out.nl()
|
out.nl()
|
||||||
|
@ -204,7 +204,7 @@ contain a line that matches both expressions:
|
|||||||
else:
|
else:
|
||||||
out.project('--- project %s ---' % project.relpath)
|
out.project('--- project %s ---' % project.relpath)
|
||||||
out.nl()
|
out.nl()
|
||||||
out.write(p.stderr)
|
out.write("%s", p.stderr)
|
||||||
out.nl()
|
out.nl()
|
||||||
continue
|
continue
|
||||||
have_match = True
|
have_match = True
|
||||||
@ -217,17 +217,17 @@ contain a line that matches both expressions:
|
|||||||
if have_rev and full_name:
|
if have_rev and full_name:
|
||||||
for line in r:
|
for line in r:
|
||||||
rev, line = line.split(':', 1)
|
rev, line = line.split(':', 1)
|
||||||
out.write(rev)
|
out.write("%s", rev)
|
||||||
out.write(':')
|
out.write(':')
|
||||||
out.project(project.relpath)
|
out.project(project.relpath)
|
||||||
out.write('/')
|
out.write('/')
|
||||||
out.write(line)
|
out.write("%s", line)
|
||||||
out.nl()
|
out.nl()
|
||||||
elif full_name:
|
elif full_name:
|
||||||
for line in r:
|
for line in r:
|
||||||
out.project(project.relpath)
|
out.project(project.relpath)
|
||||||
out.write('/')
|
out.write('/')
|
||||||
out.write(line)
|
out.write("%s", line)
|
||||||
out.nl()
|
out.nl()
|
||||||
else:
|
else:
|
||||||
for line in r:
|
for line in r:
|
||||||
|
@ -148,20 +148,34 @@ to update the working directory files.
|
|||||||
print >>sys.stderr, 'fatal: %s' % str(e)
|
print >>sys.stderr, 'fatal: %s' % str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def _PromptKey(self, prompt, key, value):
|
def _Prompt(self, prompt, value):
|
||||||
mp = self.manifest.manifestProject
|
mp = self.manifest.manifestProject
|
||||||
|
|
||||||
sys.stdout.write('%-10s [%s]: ' % (prompt, value))
|
sys.stdout.write('%-10s [%s]: ' % (prompt, value))
|
||||||
a = sys.stdin.readline().strip()
|
a = sys.stdin.readline().strip()
|
||||||
if a != '' and a != value:
|
if a == '':
|
||||||
mp.config.SetString(key, a)
|
return value
|
||||||
|
return a
|
||||||
|
|
||||||
def _ConfigureUser(self):
|
def _ConfigureUser(self):
|
||||||
mp = self.manifest.manifestProject
|
mp = self.manifest.manifestProject
|
||||||
|
|
||||||
print ''
|
while True:
|
||||||
self._PromptKey('Your Name', 'user.name', mp.UserName)
|
print ''
|
||||||
self._PromptKey('Your Email', 'user.email', mp.UserEmail)
|
name = self._Prompt('Your Name', mp.UserName)
|
||||||
|
email = self._Prompt('Your Email', mp.UserEmail)
|
||||||
|
|
||||||
|
print ''
|
||||||
|
print 'Your identity is: %s <%s>' % (name, email)
|
||||||
|
sys.stdout.write('is this correct [y/n]? ')
|
||||||
|
a = sys.stdin.readline().strip()
|
||||||
|
if a in ('yes', 'y', 't', 'true'):
|
||||||
|
break
|
||||||
|
|
||||||
|
if name != mp.UserName:
|
||||||
|
mp.config.SetString('user.name', name)
|
||||||
|
if email != mp.UserEmail:
|
||||||
|
mp.config.SetString('user.email', email)
|
||||||
|
|
||||||
def _HasColorSet(self, gc):
|
def _HasColorSet(self, gc):
|
||||||
for n in ['ui', 'diff', 'status']:
|
for n in ['ui', 'diff', 'status']:
|
||||||
|
107
subcmds/rebase.py
Normal file
107
subcmds/rebase.py
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#
|
||||||
|
# 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)")
|
||||||
|
|
||||||
|
p.add_option('-f', '--force-rebase',
|
||||||
|
dest='force_rebase', action='store_true',
|
||||||
|
help='Pass --force-rebase to git rebase')
|
||||||
|
p.add_option('--no-ff',
|
||||||
|
dest='no_ff', action='store_true',
|
||||||
|
help='Pass --no-ff to git rebase')
|
||||||
|
p.add_option('-q', '--quiet',
|
||||||
|
dest='quiet', action='store_true',
|
||||||
|
help='Pass --quiet to git rebase')
|
||||||
|
p.add_option('--autosquash',
|
||||||
|
dest='autosquash', action='store_true',
|
||||||
|
help='Pass --autosquash to git rebase')
|
||||||
|
p.add_option('--whitespace',
|
||||||
|
dest='whitespace', action='store', metavar='WS',
|
||||||
|
help='Pass --whitespace to git rebase')
|
||||||
|
|
||||||
|
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.relpath
|
||||||
|
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.relpath
|
||||||
|
return -1
|
||||||
|
# ignore branches without remotes
|
||||||
|
continue
|
||||||
|
|
||||||
|
args = ["rebase"]
|
||||||
|
|
||||||
|
if opt.whitespace:
|
||||||
|
args.append('--whitespace=%s' % opt.whitespace)
|
||||||
|
|
||||||
|
if opt.quiet:
|
||||||
|
args.append('--quiet')
|
||||||
|
|
||||||
|
if opt.force_rebase:
|
||||||
|
args.append('--force-rebase')
|
||||||
|
|
||||||
|
if opt.no_ff:
|
||||||
|
args.append('--no-ff')
|
||||||
|
|
||||||
|
if opt.autosquash:
|
||||||
|
args.append('--autosquash')
|
||||||
|
|
||||||
|
if opt.interactive:
|
||||||
|
args.append("-i")
|
||||||
|
|
||||||
|
args.append(upbranch.LocalMerge)
|
||||||
|
|
||||||
|
print >>sys.stderr, '# %s: rebasing %s -> %s' % \
|
||||||
|
(project.relpath, cb, upbranch.LocalMerge)
|
||||||
|
|
||||||
|
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)
|
181
subcmds/sync.py
181
subcmds/sync.py
@ -17,11 +17,19 @@ from optparse import SUPPRESS_HELP
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import xmlrpclib
|
||||||
|
|
||||||
|
try:
|
||||||
|
import threading as _threading
|
||||||
|
except ImportError:
|
||||||
|
import dummy_threading as _threading
|
||||||
|
|
||||||
from git_command import GIT
|
from git_command import GIT
|
||||||
|
from git_refs import R_HEADS
|
||||||
from project import HEAD
|
from project import HEAD
|
||||||
from project import Project
|
from project import Project
|
||||||
from project import RemoteSpec
|
from project import RemoteSpec
|
||||||
@ -32,6 +40,7 @@ from project import SyncBuffer
|
|||||||
from progress import Progress
|
from progress import Progress
|
||||||
|
|
||||||
class Sync(Command, MirrorSafeCommand):
|
class Sync(Command, MirrorSafeCommand):
|
||||||
|
jobs = 1
|
||||||
common = True
|
common = True
|
||||||
helpSummary = "Update working tree to the latest revision"
|
helpSummary = "Update working tree to the latest revision"
|
||||||
helpUsage = """
|
helpUsage = """
|
||||||
@ -57,6 +66,10 @@ back to the manifest revision. This option is especially helpful
|
|||||||
if the project is currently on a topic branch, but the manifest
|
if the project is currently on a topic branch, but the manifest
|
||||||
revision is temporarily needed.
|
revision is temporarily needed.
|
||||||
|
|
||||||
|
The -s/--smart-sync option can be used to sync to a known good
|
||||||
|
build as specified by the manifest-server element in the current
|
||||||
|
manifest.
|
||||||
|
|
||||||
SSH Connections
|
SSH Connections
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
@ -87,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',
|
p.add_option('-l','--local-only',
|
||||||
dest='local_only', action='store_true',
|
dest='local_only', action='store_true',
|
||||||
help="only update working tree, don't fetch")
|
help="only update working tree, don't fetch")
|
||||||
@ -97,6 +110,13 @@ later is required to fix a server side protocol bug.
|
|||||||
p.add_option('-d','--detach',
|
p.add_option('-d','--detach',
|
||||||
dest='detach_head', action='store_true',
|
dest='detach_head', action='store_true',
|
||||||
help='detach projects back to manifest revision')
|
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')
|
||||||
|
|
||||||
g = p.add_option_group('repo Version options')
|
g = p.add_option_group('repo Version options')
|
||||||
g.add_option('--no-repo-verify',
|
g.add_option('--no-repo-verify',
|
||||||
@ -106,17 +126,44 @@ later is required to fix a server side protocol bug.
|
|||||||
dest='repo_upgraded', action='store_true',
|
dest='repo_upgraded', action='store_true',
|
||||||
help=SUPPRESS_HELP)
|
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):
|
def _Fetch(self, projects):
|
||||||
fetched = set()
|
fetched = set()
|
||||||
pm = Progress('Fetching projects', len(projects))
|
pm = Progress('Fetching projects', len(projects))
|
||||||
for project in projects:
|
|
||||||
pm.update()
|
|
||||||
|
|
||||||
if project.Sync_NetworkHalf():
|
if self.jobs == 1:
|
||||||
fetched.add(project.gitdir)
|
for project in projects:
|
||||||
else:
|
pm.update()
|
||||||
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
if project.Sync_NetworkHalf():
|
||||||
sys.exit(1)
|
fetched.add(project.gitdir)
|
||||||
|
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()
|
pm.end()
|
||||||
return fetched
|
return fetched
|
||||||
|
|
||||||
@ -139,32 +186,36 @@ later is required to fix a server side protocol bug.
|
|||||||
if not path:
|
if not path:
|
||||||
continue
|
continue
|
||||||
if path not in new_project_paths:
|
if path not in new_project_paths:
|
||||||
project = Project(
|
"""If the path has already been deleted, we don't need to do it
|
||||||
manifest = self.manifest,
|
"""
|
||||||
name = path,
|
if os.path.exists(self.manifest.topdir + '/' + path):
|
||||||
remote = RemoteSpec('origin'),
|
project = Project(
|
||||||
gitdir = os.path.join(self.manifest.topdir,
|
manifest = self.manifest,
|
||||||
path, '.git'),
|
name = path,
|
||||||
worktree = os.path.join(self.manifest.topdir, path),
|
remote = RemoteSpec('origin'),
|
||||||
relpath = path,
|
gitdir = os.path.join(self.manifest.topdir,
|
||||||
revisionExpr = 'HEAD',
|
path, '.git'),
|
||||||
revisionId = None)
|
worktree = os.path.join(self.manifest.topdir, path),
|
||||||
if project.IsDirty():
|
relpath = path,
|
||||||
print >>sys.stderr, 'error: Cannot remove project "%s": \
|
revisionExpr = 'HEAD',
|
||||||
|
revisionId = None)
|
||||||
|
|
||||||
|
if project.IsDirty():
|
||||||
|
print >>sys.stderr, 'error: Cannot remove project "%s": \
|
||||||
uncommitted changes are present' % project.relpath
|
uncommitted changes are present' % project.relpath
|
||||||
print >>sys.stderr, ' commit changes, then run sync again'
|
print >>sys.stderr, ' commit changes, then run sync again'
|
||||||
return -1
|
return -1
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree
|
print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree
|
||||||
shutil.rmtree(project.worktree)
|
shutil.rmtree(project.worktree)
|
||||||
# Try deleting parent subdirs if they are empty
|
# Try deleting parent subdirs if they are empty
|
||||||
dir = os.path.dirname(project.worktree)
|
dir = os.path.dirname(project.worktree)
|
||||||
while dir != self.manifest.topdir:
|
while dir != self.manifest.topdir:
|
||||||
try:
|
try:
|
||||||
os.rmdir(dir)
|
os.rmdir(dir)
|
||||||
except OSError:
|
except OSError:
|
||||||
break
|
break
|
||||||
dir = os.path.dirname(dir)
|
dir = os.path.dirname(dir)
|
||||||
|
|
||||||
new_project_paths.sort()
|
new_project_paths.sort()
|
||||||
fd = open(file_path, 'w')
|
fd = open(file_path, 'w')
|
||||||
@ -176,6 +227,8 @@ uncommitted changes are present' % project.relpath
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def Execute(self, opt, args):
|
def Execute(self, opt, args):
|
||||||
|
if opt.jobs:
|
||||||
|
self.jobs = opt.jobs
|
||||||
if opt.network_only and opt.detach_head:
|
if opt.network_only and opt.detach_head:
|
||||||
print >>sys.stderr, 'error: cannot combine -n and -d'
|
print >>sys.stderr, 'error: cannot combine -n and -d'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -183,6 +236,51 @@ uncommitted changes are present' % project.relpath
|
|||||||
print >>sys.stderr, 'error: cannot combine -n and -l'
|
print >>sys.stderr, 'error: cannot combine -n and -l'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if opt.smart_sync:
|
||||||
|
if not self.manifest.manifest_server:
|
||||||
|
print >>sys.stderr, \
|
||||||
|
'error: cannot smart sync: no manifest server defined in manifest'
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
|
server = xmlrpclib.Server(self.manifest.manifest_server)
|
||||||
|
p = self.manifest.manifestProject
|
||||||
|
b = p.GetBranch(p.CurrentBranch)
|
||||||
|
branch = b.merge
|
||||||
|
if branch.startswith(R_HEADS):
|
||||||
|
branch = branch[len(R_HEADS):]
|
||||||
|
|
||||||
|
env = dict(os.environ)
|
||||||
|
if (env.has_key('TARGET_PRODUCT') and
|
||||||
|
env.has_key('TARGET_BUILD_VARIANT')):
|
||||||
|
target = '%s-%s' % (env['TARGET_PRODUCT'],
|
||||||
|
env['TARGET_BUILD_VARIANT'])
|
||||||
|
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
||||||
|
else:
|
||||||
|
[success, manifest_str] = server.GetApprovedManifest(branch)
|
||||||
|
|
||||||
|
if success:
|
||||||
|
manifest_name = "smart_sync_override.xml"
|
||||||
|
manifest_path = os.path.join(self.manifest.manifestProject.worktree,
|
||||||
|
manifest_name)
|
||||||
|
try:
|
||||||
|
f = open(manifest_path, 'w')
|
||||||
|
try:
|
||||||
|
f.write(manifest_str)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
except IOError:
|
||||||
|
print >>sys.stderr, 'error: cannot write manifest to %s' % \
|
||||||
|
manifest_path
|
||||||
|
sys.exit(1)
|
||||||
|
self.manifest.Override(manifest_name)
|
||||||
|
else:
|
||||||
|
print >>sys.stderr, 'error: %s' % manifest_str
|
||||||
|
sys.exit(1)
|
||||||
|
except socket.error:
|
||||||
|
print >>sys.stderr, 'error: cannot connect to manifest server %s' % (
|
||||||
|
self.manifest.manifest_server)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
rp = self.manifest.repoProject
|
rp = self.manifest.repoProject
|
||||||
rp.PreSync()
|
rp.PreSync()
|
||||||
|
|
||||||
@ -192,6 +290,15 @@ uncommitted changes are present' % project.relpath
|
|||||||
if opt.repo_upgraded:
|
if opt.repo_upgraded:
|
||||||
_PostRepoUpgrade(self.manifest)
|
_PostRepoUpgrade(self.manifest)
|
||||||
|
|
||||||
|
if not opt.local_only:
|
||||||
|
mp.Sync_NetworkHalf()
|
||||||
|
|
||||||
|
if mp.HasChanges:
|
||||||
|
syncbuf = SyncBuffer(mp.config)
|
||||||
|
mp.Sync_LocalHalf(syncbuf)
|
||||||
|
if not syncbuf.Finish():
|
||||||
|
sys.exit(1)
|
||||||
|
self.manifest._Unload()
|
||||||
all = self.GetProjects(args, missing_ok=True)
|
all = self.GetProjects(args, missing_ok=True)
|
||||||
|
|
||||||
if not opt.local_only:
|
if not opt.local_only:
|
||||||
@ -199,7 +306,6 @@ uncommitted changes are present' % project.relpath
|
|||||||
now = time.time()
|
now = time.time()
|
||||||
if (24 * 60 * 60) <= (now - rp.LastFetch):
|
if (24 * 60 * 60) <= (now - rp.LastFetch):
|
||||||
to_fetch.append(rp)
|
to_fetch.append(rp)
|
||||||
to_fetch.append(mp)
|
|
||||||
to_fetch.extend(all)
|
to_fetch.extend(all)
|
||||||
|
|
||||||
fetched = self._Fetch(to_fetch)
|
fetched = self._Fetch(to_fetch)
|
||||||
@ -208,12 +314,6 @@ uncommitted changes are present' % project.relpath
|
|||||||
# bail out now; the rest touches the working tree
|
# bail out now; the rest touches the working tree
|
||||||
return
|
return
|
||||||
|
|
||||||
if mp.HasChanges:
|
|
||||||
syncbuf = SyncBuffer(mp.config)
|
|
||||||
mp.Sync_LocalHalf(syncbuf)
|
|
||||||
if not syncbuf.Finish():
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
self.manifest._Unload()
|
self.manifest._Unload()
|
||||||
all = self.GetProjects(args, missing_ok=True)
|
all = self.GetProjects(args, missing_ok=True)
|
||||||
missing = []
|
missing = []
|
||||||
@ -241,7 +341,6 @@ uncommitted changes are present' % project.relpath
|
|||||||
if not syncbuf.Finish():
|
if not syncbuf.Finish():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def _PostRepoUpgrade(manifest):
|
def _PostRepoUpgrade(manifest):
|
||||||
for project in manifest.projects.values():
|
for project in manifest.projects.values():
|
||||||
if project.Exists:
|
if project.Exists:
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import copy
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -20,6 +21,17 @@ from command import InteractiveCommand
|
|||||||
from editor import Editor
|
from editor import Editor
|
||||||
from error import UploadError
|
from error import UploadError
|
||||||
|
|
||||||
|
UNUSUAL_COMMIT_THRESHOLD = 5
|
||||||
|
|
||||||
|
def _ConfirmManyUploads(multiple_branches=False):
|
||||||
|
if multiple_branches:
|
||||||
|
print "ATTENTION: One or more branches has an unusually high number of commits."
|
||||||
|
else:
|
||||||
|
print "ATTENTION: You are uploading an unusually high number of commits."
|
||||||
|
print "YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across branches?)"
|
||||||
|
answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip()
|
||||||
|
return answer == "yes"
|
||||||
|
|
||||||
def _die(fmt, *args):
|
def _die(fmt, *args):
|
||||||
msg = fmt % args
|
msg = fmt % args
|
||||||
print >>sys.stderr, 'error: %s' % msg
|
print >>sys.stderr, 'error: %s' % msg
|
||||||
@ -72,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
|
and will not prompt you further. If it is set to "false" then repo
|
||||||
will assume you always answer "n", and will abort.
|
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,
|
The URL must match the review URL listed in the manifest XML file,
|
||||||
or in the .git/config within the project. For example:
|
or in the .git/config within the project. For example:
|
||||||
|
|
||||||
@ -81,6 +106,7 @@ or in the .git/config within the project. For example:
|
|||||||
|
|
||||||
[review "http://review.example.com/"]
|
[review "http://review.example.com/"]
|
||||||
autoupload = true
|
autoupload = true
|
||||||
|
autocopy = johndoe@company.com,my-team-alias@company.com
|
||||||
|
|
||||||
References
|
References
|
||||||
----------
|
----------
|
||||||
@ -90,6 +116,9 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def _Options(self, p):
|
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',
|
p.add_option('--replace',
|
||||||
dest='replace', action='store_true',
|
dest='replace', action='store_true',
|
||||||
help='Upload replacement patchesets from this branch')
|
help='Upload replacement patchesets from this branch')
|
||||||
@ -100,7 +129,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
type='string', action='append', dest='cc',
|
type='string', action='append', dest='cc',
|
||||||
help='Also send email to these email addresses.')
|
help='Also send email to these email addresses.')
|
||||||
|
|
||||||
def _SingleBranch(self, branch, people):
|
def _SingleBranch(self, opt, branch, people):
|
||||||
project = branch.project
|
project = branch.project
|
||||||
name = branch.name
|
name = branch.name
|
||||||
remote = project.GetBranch(name).remote
|
remote = project.GetBranch(name).remote
|
||||||
@ -129,11 +158,15 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
answer = answer in ('y', 'Y', 'yes', '1', 'true', 't')
|
answer = answer in ('y', 'Y', 'yes', '1', 'true', 't')
|
||||||
|
|
||||||
if answer:
|
if answer:
|
||||||
self._UploadAndReport([branch], people)
|
if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
|
||||||
|
answer = _ConfirmManyUploads()
|
||||||
|
|
||||||
|
if answer:
|
||||||
|
self._UploadAndReport(opt, [branch], people)
|
||||||
else:
|
else:
|
||||||
_die("upload aborted by user")
|
_die("upload aborted by user")
|
||||||
|
|
||||||
def _MultipleBranches(self, pending, people):
|
def _MultipleBranches(self, opt, pending, people):
|
||||||
projects = {}
|
projects = {}
|
||||||
branches = {}
|
branches = {}
|
||||||
|
|
||||||
@ -192,7 +225,30 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
todo.append(branch)
|
todo.append(branch)
|
||||||
if not todo:
|
if not todo:
|
||||||
_die("nothing uncommented for upload")
|
_die("nothing uncommented for upload")
|
||||||
self._UploadAndReport(todo, people)
|
|
||||||
|
many_commits = False
|
||||||
|
for branch in todo:
|
||||||
|
if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
|
||||||
|
many_commits = True
|
||||||
|
break
|
||||||
|
if many_commits:
|
||||||
|
if not _ConfirmManyUploads(multiple_branches=True):
|
||||||
|
_die("upload aborted by user")
|
||||||
|
|
||||||
|
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):
|
def _FindGerritChange(self, branch):
|
||||||
last_pub = branch.project.WasPublished(branch.name)
|
last_pub = branch.project.WasPublished(branch.name)
|
||||||
@ -258,14 +314,36 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
print >>sys.stderr, " use 'repo upload' without --replace"
|
print >>sys.stderr, " use 'repo upload' without --replace"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
branch.replace_changes = to_replace
|
if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
|
||||||
self._UploadAndReport([branch], people)
|
if not _ConfirmManyUploads(multiple_branches=True):
|
||||||
|
_die("upload aborted by user")
|
||||||
|
|
||||||
def _UploadAndReport(self, todo, people):
|
branch.replace_changes = to_replace
|
||||||
|
self._UploadAndReport(opt, [branch], people)
|
||||||
|
|
||||||
|
def _UploadAndReport(self, opt, todo, original_people):
|
||||||
have_errors = False
|
have_errors = False
|
||||||
for branch in todo:
|
for branch in todo:
|
||||||
try:
|
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
|
branch.uploaded = True
|
||||||
except UploadError, e:
|
except UploadError, e:
|
||||||
branch.error = e
|
branch.error = e
|
||||||
@ -321,6 +399,6 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
if not pending:
|
if not pending:
|
||||||
print >>sys.stdout, "no branches ready for upload"
|
print >>sys.stdout, "no branches ready for upload"
|
||||||
elif len(pending) == 1 and len(pending[0][1]) == 1:
|
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:
|
else:
|
||||||
self._MultipleBranches(pending, people)
|
self._MultipleBranches(opt, pending, people)
|
||||||
|
3
tests/fixtures/test.gitconfig
vendored
Normal file
3
tests/fixtures/test.gitconfig
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[section]
|
||||||
|
empty
|
||||||
|
nonempty = true
|
52
tests/test_git_config.py
Normal file
52
tests/test_git_config.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import git_config
|
||||||
|
|
||||||
|
def fixture(*paths):
|
||||||
|
"""Return a path relative to test/fixtures.
|
||||||
|
"""
|
||||||
|
return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
|
||||||
|
|
||||||
|
class GitConfigUnitTest(unittest.TestCase):
|
||||||
|
"""Tests the GitConfig class.
|
||||||
|
"""
|
||||||
|
def setUp(self):
|
||||||
|
"""Create a GitConfig object using the test.gitconfig fixture.
|
||||||
|
"""
|
||||||
|
config_fixture = fixture('test.gitconfig')
|
||||||
|
self.config = git_config.GitConfig(config_fixture)
|
||||||
|
|
||||||
|
def test_GetString_with_empty_config_values(self):
|
||||||
|
"""
|
||||||
|
Test config entries with no value.
|
||||||
|
|
||||||
|
[section]
|
||||||
|
empty
|
||||||
|
|
||||||
|
"""
|
||||||
|
val = self.config.GetString('section.empty')
|
||||||
|
self.assertEqual(val, None)
|
||||||
|
|
||||||
|
def test_GetString_with_true_value(self):
|
||||||
|
"""
|
||||||
|
Test config entries with a string value.
|
||||||
|
|
||||||
|
[section]
|
||||||
|
nonempty = true
|
||||||
|
|
||||||
|
"""
|
||||||
|
val = self.config.GetString('section.nonempty')
|
||||||
|
self.assertEqual(val, 'true')
|
||||||
|
|
||||||
|
def test_GetString_from_missing_file(self):
|
||||||
|
"""
|
||||||
|
Test missing config file
|
||||||
|
"""
|
||||||
|
config_fixture = fixture('not.present.gitconfig')
|
||||||
|
config = git_config.GitConfig(config_fixture)
|
||||||
|
val = config.GetString('empty')
|
||||||
|
self.assertEqual(val, None)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user