mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-07-09 08:29:02 +00:00
Compare commits
63 Commits
Author | SHA1 | Date | |
---|---|---|---|
9371979628 | |||
2086004261 | |||
2338788050 | |||
0402cd882a | |||
936183a492 | |||
85e8267031 | |||
e30f46b957 | |||
e4978cfbe3 | |||
126e298214 | |||
38e4387f8e | |||
24245e0094 | |||
db6f1b0884 | |||
f2fad61bde | |||
ee69084421 | |||
d37d43f036 | |||
7bdac71087 | |||
f97e8383a3 | |||
3000cdad22 | |||
b9d9efd394 | |||
497bde4de5 | |||
4abf8e6ef8 | |||
137d0131bf | |||
42e679b9f6 | |||
902665bce6 | |||
c8d882ae2a | |||
3eb87cec5c | |||
5fb8ed217c | |||
7e12e0a2fa | |||
7893b85509 | |||
b4e50e67e8 | |||
0936aeab2c | |||
14e134da02 | |||
04e52d6166 | |||
909d58b2e2 | |||
5cf16607d3 | |||
c190b98ed5 | |||
4863307299 | |||
f75870beac | |||
bf0b0cbc2f | |||
3a10968a70 | |||
c46de6932a | |||
303a82f33a | |||
7a91d51dcf | |||
a8d539189e | |||
588142dfcb | |||
a6d258b84d | |||
a769498568 | |||
884a387eca | |||
80b87fe6c1 | |||
e9f75b1782 | |||
a35e402161 | |||
dd7aea6c11 | |||
5196805fa2 | |||
85b24acd6a | |||
36ea2fb6ee | |||
2cd1f0452e | |||
65e3a78a9e | |||
d792f7928d | |||
6efdde9f6e | |||
7446c5954a | |||
d58bfe5a58 | |||
70f6890352 | |||
4e4d40f7c0 |
27
color.py
27
color.py
@ -83,15 +83,38 @@ def _Color(fg = None, bg = None, attr = None):
|
||||
return code
|
||||
|
||||
|
||||
DEFAULT = None
|
||||
|
||||
def SetDefaultColoring(state):
|
||||
"""Set coloring behavior to |state|.
|
||||
|
||||
This is useful for overriding config options via the command line.
|
||||
"""
|
||||
if state is None:
|
||||
# Leave it alone -- return quick!
|
||||
return
|
||||
|
||||
global DEFAULT
|
||||
state = state.lower()
|
||||
if state in ('auto',):
|
||||
DEFAULT = state
|
||||
elif state in ('always', 'yes', 'true', True):
|
||||
DEFAULT = 'always'
|
||||
elif state in ('never', 'no', 'false', False):
|
||||
DEFAULT = 'never'
|
||||
|
||||
|
||||
class Coloring(object):
|
||||
def __init__(self, config, section_type):
|
||||
self._section = 'color.%s' % section_type
|
||||
self._config = config
|
||||
self._out = sys.stdout
|
||||
|
||||
on = self._config.GetString(self._section)
|
||||
on = DEFAULT
|
||||
if on is None:
|
||||
on = self._config.GetString('color.ui')
|
||||
on = self._config.GetString(self._section)
|
||||
if on is None:
|
||||
on = self._config.GetString('color.ui')
|
||||
|
||||
if on == 'auto':
|
||||
if pager.active or os.isatty(1):
|
||||
|
@ -26,6 +26,7 @@ following DTD:
|
||||
manifest-server?,
|
||||
remove-project*,
|
||||
project*,
|
||||
extend-project*,
|
||||
repo-hooks?)>
|
||||
|
||||
<!ELEMENT notice (#PCDATA)>
|
||||
@ -35,6 +36,7 @@ following DTD:
|
||||
<!ATTLIST remote alias CDATA #IMPLIED>
|
||||
<!ATTLIST remote fetch CDATA #REQUIRED>
|
||||
<!ATTLIST remote review CDATA #IMPLIED>
|
||||
<!ATTLIST remote revision CDATA #IMPLIED>
|
||||
|
||||
<!ELEMENT default (EMPTY)>
|
||||
<!ATTLIST default remote IDREF #IMPLIED>
|
||||
@ -66,6 +68,11 @@ following DTD:
|
||||
<!ATTLIST annotation value CDATA #REQUIRED>
|
||||
<!ATTLIST annotation keep CDATA "true">
|
||||
|
||||
<!ELEMENT extend-project>
|
||||
<!ATTLIST extend-project name CDATA #REQUIRED>
|
||||
<!ATTLIST extend-project path CDATA #IMPLIED>
|
||||
<!ATTLIST extend-project groups CDATA #IMPLIED>
|
||||
|
||||
<!ELEMENT remove-project (EMPTY)>
|
||||
<!ATTLIST remove-project name CDATA #REQUIRED>
|
||||
|
||||
@ -112,6 +119,10 @@ Attribute `review`: Hostname of the Gerrit server where reviews
|
||||
are uploaded to by `repo upload`. This attribute is optional;
|
||||
if not specified then `repo upload` will not function.
|
||||
|
||||
Attribute `revision`: Name of a Git branch (e.g. `master` or
|
||||
`refs/heads/master`). Remotes with their own revision will override
|
||||
the default revision.
|
||||
|
||||
Element default
|
||||
---------------
|
||||
|
||||
@ -132,14 +143,14 @@ Project elements not setting their own `dest-branch` will inherit
|
||||
this value. If this value is not set, projects will use `revision`
|
||||
by default instead.
|
||||
|
||||
Attribute `sync_j`: Number of parallel jobs to use when synching.
|
||||
Attribute `sync-j`: Number of parallel jobs to use when synching.
|
||||
|
||||
Attribute `sync_c`: Set to true to only sync the given Git
|
||||
Attribute `sync-c`: Set to true to only sync the given Git
|
||||
branch (specified in the `revision` attribute) rather than the
|
||||
whole ref space. Project elements lacking a sync_c element of
|
||||
whole ref space. Project elements lacking a sync-c element of
|
||||
their own will use this value.
|
||||
|
||||
Attribute `sync_s`: Set to true to also sync sub-projects.
|
||||
Attribute `sync-s`: Set to true to also sync sub-projects.
|
||||
|
||||
|
||||
Element manifest-server
|
||||
@ -208,7 +219,8 @@ to track for this project. Names can be relative to refs/heads
|
||||
(e.g. just "master") or absolute (e.g. "refs/heads/master").
|
||||
Tags and/or explicit SHA-1s should work in theory, but have not
|
||||
been extensively tested. If not supplied the revision given by
|
||||
the default element is used.
|
||||
the remote element is used if applicable, else the default
|
||||
element is used.
|
||||
|
||||
Attribute `dest-branch`: Name of a Git branch (e.g. `master`).
|
||||
When using `repo upload`, changes will be submitted for code
|
||||
@ -226,13 +238,13 @@ group "notdefault", it will not be automatically downloaded by repo.
|
||||
If the project has a parent element, the `name` and `path` here
|
||||
are the prefixed ones.
|
||||
|
||||
Attribute `sync_c`: Set to true to only sync the given Git
|
||||
Attribute `sync-c`: Set to true to only sync the given Git
|
||||
branch (specified in the `revision` attribute) rather than the
|
||||
whole ref space.
|
||||
|
||||
Attribute `sync_s`: Set to true to also sync sub-projects.
|
||||
Attribute `sync-s`: Set to true to also sync sub-projects.
|
||||
|
||||
Attribute `upstream`: Name of the Git branch in which a sha1
|
||||
Attribute `upstream`: Name of the Git ref in which a sha1
|
||||
can be found. Used when syncing a revision locked manifest in
|
||||
-c mode to avoid having to sync the entire ref space.
|
||||
|
||||
@ -246,6 +258,22 @@ rather than the `name` attribute. This attribute only applies to the
|
||||
local mirrors syncing, it will be ignored when syncing the projects in a
|
||||
client working directory.
|
||||
|
||||
Element extend-project
|
||||
----------------------
|
||||
|
||||
Modify the attributes of the named project.
|
||||
|
||||
This element is mostly useful in a local manifest file, to modify the
|
||||
attributes of an existing project without completely replacing the
|
||||
existing project definition. This makes the local manifest more robust
|
||||
against changes to the original manifest.
|
||||
|
||||
Attribute `path`: If specified, limit the change to projects checked out
|
||||
at the specified path, rather than all projects with the given name.
|
||||
|
||||
Attribute `groups`: List of additional groups to which this project
|
||||
belongs. Same syntax as the corresponding element of `project`.
|
||||
|
||||
Element annotation
|
||||
------------------
|
||||
|
||||
|
@ -80,13 +80,13 @@ class _GitCall(object):
|
||||
def version(self):
|
||||
p = GitCommand(None, ['--version'], capture_stdout=True)
|
||||
if p.Wait() == 0:
|
||||
return p.stdout
|
||||
return p.stdout.decode('utf-8')
|
||||
return None
|
||||
|
||||
def version_tuple(self):
|
||||
global _git_version
|
||||
if _git_version is None:
|
||||
ver_str = git.version().decode('utf-8')
|
||||
ver_str = git.version()
|
||||
_git_version = Wrapper().ParseGitVersion(ver_str)
|
||||
if _git_version is None:
|
||||
print('fatal: "%s" unsupported' % ver_str, file=sys.stderr)
|
||||
|
@ -15,8 +15,8 @@
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import json
|
||||
import os
|
||||
import pickle
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
@ -80,7 +80,7 @@ class GitConfig(object):
|
||||
return cls(configfile = os.path.join(gitdir, 'config'),
|
||||
defaults = defaults)
|
||||
|
||||
def __init__(self, configfile, defaults=None, pickleFile=None):
|
||||
def __init__(self, configfile, defaults=None, jsonFile=None):
|
||||
self.file = configfile
|
||||
self.defaults = defaults
|
||||
self._cache_dict = None
|
||||
@ -88,12 +88,11 @@ class GitConfig(object):
|
||||
self._remotes = {}
|
||||
self._branches = {}
|
||||
|
||||
if pickleFile is None:
|
||||
self._pickle = os.path.join(
|
||||
self._json = jsonFile
|
||||
if self._json is None:
|
||||
self._json = os.path.join(
|
||||
os.path.dirname(self.file),
|
||||
'.repopickle_' + os.path.basename(self.file))
|
||||
else:
|
||||
self._pickle = pickleFile
|
||||
'.repo_' + os.path.basename(self.file) + '.json')
|
||||
|
||||
def Has(self, name, include_defaults = True):
|
||||
"""Return true if this configuration file has the key.
|
||||
@ -217,9 +216,9 @@ class GitConfig(object):
|
||||
"""Resolve any url.*.insteadof references.
|
||||
"""
|
||||
for new_url in self.GetSubSections('url'):
|
||||
old_url = self.GetString('url.%s.insteadof' % new_url)
|
||||
if old_url is not None and url.startswith(old_url):
|
||||
return new_url + url[len(old_url):]
|
||||
for old_url in self.GetString('url.%s.insteadof' % new_url, True):
|
||||
if old_url is not None and url.startswith(old_url):
|
||||
return new_url + url[len(old_url):]
|
||||
return url
|
||||
|
||||
@property
|
||||
@ -248,50 +247,41 @@ class GitConfig(object):
|
||||
return self._cache_dict
|
||||
|
||||
def _Read(self):
|
||||
d = self._ReadPickle()
|
||||
d = self._ReadJson()
|
||||
if d is None:
|
||||
d = self._ReadGit()
|
||||
self._SavePickle(d)
|
||||
self._SaveJson(d)
|
||||
return d
|
||||
|
||||
def _ReadPickle(self):
|
||||
def _ReadJson(self):
|
||||
try:
|
||||
if os.path.getmtime(self._pickle) \
|
||||
if os.path.getmtime(self._json) \
|
||||
<= os.path.getmtime(self.file):
|
||||
os.remove(self._pickle)
|
||||
os.remove(self._json)
|
||||
return None
|
||||
except OSError:
|
||||
return None
|
||||
try:
|
||||
Trace(': unpickle %s', self.file)
|
||||
fd = open(self._pickle, 'rb')
|
||||
Trace(': parsing %s', self.file)
|
||||
fd = open(self._json)
|
||||
try:
|
||||
return pickle.load(fd)
|
||||
return json.load(fd)
|
||||
finally:
|
||||
fd.close()
|
||||
except EOFError:
|
||||
os.remove(self._pickle)
|
||||
return None
|
||||
except IOError:
|
||||
os.remove(self._pickle)
|
||||
return None
|
||||
except pickle.PickleError:
|
||||
os.remove(self._pickle)
|
||||
except (IOError, ValueError):
|
||||
os.remove(self._json)
|
||||
return None
|
||||
|
||||
def _SavePickle(self, cache):
|
||||
def _SaveJson(self, cache):
|
||||
try:
|
||||
fd = open(self._pickle, 'wb')
|
||||
fd = open(self._json, 'w')
|
||||
try:
|
||||
pickle.dump(cache, fd, pickle.HIGHEST_PROTOCOL)
|
||||
json.dump(cache, fd, indent=2)
|
||||
finally:
|
||||
fd.close()
|
||||
except IOError:
|
||||
if os.path.exists(self._pickle):
|
||||
os.remove(self._pickle)
|
||||
except pickle.PickleError:
|
||||
if os.path.exists(self._pickle):
|
||||
os.remove(self._pickle)
|
||||
except (IOError, TypeError):
|
||||
if os.path.exists(self.json):
|
||||
os.remove(self._json)
|
||||
|
||||
def _ReadGit(self):
|
||||
"""
|
||||
@ -576,6 +566,8 @@ class Remote(object):
|
||||
return None
|
||||
|
||||
u = self.review
|
||||
if u.startswith('persistent-'):
|
||||
u = u[len('persistent-'):]
|
||||
if u.split(':')[0] not in ('http', 'https', 'sso'):
|
||||
u = 'http://%s' % u
|
||||
if u.endswith('/Gerrit'):
|
||||
@ -627,9 +619,7 @@ class Remote(object):
|
||||
def ToLocal(self, rev):
|
||||
"""Convert a remote revision string to something we have locally.
|
||||
"""
|
||||
if IsId(rev):
|
||||
return rev
|
||||
if rev.startswith(R_TAGS):
|
||||
if self.name == '.' or IsId(rev):
|
||||
return rev
|
||||
|
||||
if not rev.startswith('refs/'):
|
||||
@ -638,6 +628,10 @@ class Remote(object):
|
||||
for spec in self.fetch:
|
||||
if spec.SourceMatches(rev):
|
||||
return spec.MapSource(rev)
|
||||
|
||||
if not rev.startswith(R_HEADS):
|
||||
return rev
|
||||
|
||||
raise GitError('remote %s does not have %s' % (self.name, rev))
|
||||
|
||||
def WritesTo(self, ref):
|
||||
@ -707,7 +701,7 @@ class Branch(object):
|
||||
self._Set('merge', self.merge)
|
||||
|
||||
else:
|
||||
fd = open(self._config.file, 'ab')
|
||||
fd = open(self._config.file, 'a')
|
||||
try:
|
||||
fd.write('[branch "%s"]\n' % self.name)
|
||||
if self.remote:
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/bin/sh
|
||||
# From Gerrit Code Review 2.6
|
||||
#
|
||||
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
|
||||
#
|
||||
@ -27,7 +26,7 @@ MSG="$1"
|
||||
#
|
||||
add_ChangeId() {
|
||||
clean_message=`sed -e '
|
||||
/^diff --git a\/.*/{
|
||||
/^diff --git .*/{
|
||||
s///
|
||||
q
|
||||
}
|
||||
@ -39,6 +38,11 @@ add_ChangeId() {
|
||||
return
|
||||
fi
|
||||
|
||||
if test "false" = "`git config --bool --get gerrit.createChangeId`"
|
||||
then
|
||||
return
|
||||
fi
|
||||
|
||||
# Does Change-Id: already exist? if so, exit (no change).
|
||||
if grep -i '^Change-Id:' "$MSG" >/dev/null
|
||||
then
|
||||
@ -77,7 +81,7 @@ add_ChangeId() {
|
||||
# Skip the line starting with the diff command and everything after it,
|
||||
# up to the end of the file, assuming it is only patch data.
|
||||
# If more than one line before the diff was empty, strip all but one.
|
||||
/^diff --git a/ {
|
||||
/^diff --git / {
|
||||
blankLines = 0
|
||||
while (getline) { }
|
||||
next
|
||||
|
6
main.py
6
main.py
@ -36,6 +36,7 @@ try:
|
||||
except ImportError:
|
||||
kerberos = None
|
||||
|
||||
from color import SetDefaultColoring
|
||||
from trace import SetTrace
|
||||
from git_command import git, GitCommand
|
||||
from git_config import init_ssh, close_ssh
|
||||
@ -69,6 +70,9 @@ global_options.add_option('-p', '--paginate',
|
||||
global_options.add_option('--no-pager',
|
||||
dest='no_pager', action='store_true',
|
||||
help='disable the pager')
|
||||
global_options.add_option('--color',
|
||||
choices=('auto', 'always', 'never'), default=None,
|
||||
help='control color usage: auto, always, never')
|
||||
global_options.add_option('--trace',
|
||||
dest='trace', action='store_true',
|
||||
help='trace git command execution')
|
||||
@ -113,6 +117,8 @@ class _Repo(object):
|
||||
print('fatal: invalid usage of --version', file=sys.stderr)
|
||||
return 1
|
||||
|
||||
SetDefaultColoring(gopts.color)
|
||||
|
||||
try:
|
||||
cmd = self.commands[name]
|
||||
except KeyError:
|
||||
|
@ -63,12 +63,14 @@ class _XmlRemote(object):
|
||||
alias=None,
|
||||
fetch=None,
|
||||
manifestUrl=None,
|
||||
review=None):
|
||||
review=None,
|
||||
revision=None):
|
||||
self.name = name
|
||||
self.fetchUrl = fetch
|
||||
self.manifestUrl = manifestUrl
|
||||
self.remoteAlias = alias
|
||||
self.reviewUrl = review
|
||||
self.revision = revision
|
||||
self.resolvedFetchUrl = self._resolveFetchUrl()
|
||||
|
||||
def __eq__(self, other):
|
||||
@ -84,16 +86,20 @@ class _XmlRemote(object):
|
||||
# about here are:
|
||||
# * no scheme in the base url, like <hostname:port>
|
||||
# * persistent-https://
|
||||
# * rpc://
|
||||
# We handle this by replacing these with obscure protocols
|
||||
# and then replacing them with the original when we are done.
|
||||
# gopher -> <none>
|
||||
# wais -> persistent-https
|
||||
# nntp -> rpc
|
||||
if manifestUrl.find(':') != manifestUrl.find('/') - 1:
|
||||
manifestUrl = 'gopher://' + manifestUrl
|
||||
manifestUrl = re.sub(r'^persistent-https://', 'wais://', manifestUrl)
|
||||
manifestUrl = re.sub(r'^rpc://', 'nntp://', manifestUrl)
|
||||
url = urllib.parse.urljoin(manifestUrl, url)
|
||||
url = re.sub(r'^gopher://', '', url)
|
||||
url = re.sub(r'^wais://', 'persistent-https://', url)
|
||||
url = re.sub(r'^nntp://', 'rpc://', url)
|
||||
return url
|
||||
|
||||
def ToRemoteSpec(self, projectName):
|
||||
@ -159,6 +165,11 @@ class XmlManifest(object):
|
||||
e.setAttribute('alias', r.remoteAlias)
|
||||
if r.reviewUrl is not None:
|
||||
e.setAttribute('review', r.reviewUrl)
|
||||
if r.revision is not None:
|
||||
e.setAttribute('revision', r.revision)
|
||||
|
||||
def _ParseGroups(self, groups):
|
||||
return [x for x in re.split(r'[,\s]+', groups) if x]
|
||||
|
||||
def Save(self, fd, peg_rev=False, peg_rev_upstream=True):
|
||||
"""Write the current manifest out to the given file descriptor.
|
||||
@ -167,7 +178,7 @@ class XmlManifest(object):
|
||||
|
||||
groups = mp.config.GetString('manifest.groups')
|
||||
if groups:
|
||||
groups = [x for x in re.split(r'[,\s]+', groups) if x]
|
||||
groups = self._ParseGroups(groups)
|
||||
|
||||
doc = xml.dom.minidom.Document()
|
||||
root = doc.createElement('manifest')
|
||||
@ -240,7 +251,8 @@ class XmlManifest(object):
|
||||
if d.remote:
|
||||
remoteName = d.remote.remoteAlias or d.remote.name
|
||||
if not d.remote or p.remote.name != remoteName:
|
||||
e.setAttribute('remote', p.remote.name)
|
||||
remoteName = p.remote.name
|
||||
e.setAttribute('remote', remoteName)
|
||||
if peg_rev:
|
||||
if self.IsMirror:
|
||||
value = p.bare_git.rev_parse(p.revisionExpr + '^0')
|
||||
@ -252,8 +264,12 @@ class XmlManifest(object):
|
||||
# isn't our value, and the if the default doesn't already have that
|
||||
# covered.
|
||||
e.setAttribute('upstream', p.revisionExpr)
|
||||
elif not d.revisionExpr or p.revisionExpr != d.revisionExpr:
|
||||
e.setAttribute('revision', p.revisionExpr)
|
||||
else:
|
||||
revision = self.remotes[remoteName].revision or d.revisionExpr
|
||||
if not revision or revision != p.revisionExpr:
|
||||
e.setAttribute('revision', p.revisionExpr)
|
||||
if p.upstream and p.upstream != p.revisionExpr:
|
||||
e.setAttribute('upstream', p.upstream)
|
||||
|
||||
for c in p.copyfiles:
|
||||
ce = doc.createElement('copyfile')
|
||||
@ -310,7 +326,7 @@ class XmlManifest(object):
|
||||
@property
|
||||
def projects(self):
|
||||
self._Load()
|
||||
return self._paths.values()
|
||||
return list(self._paths.values())
|
||||
|
||||
@property
|
||||
def remotes(self):
|
||||
@ -498,6 +514,23 @@ class XmlManifest(object):
|
||||
if node.nodeName == 'project':
|
||||
project = self._ParseProject(node)
|
||||
recursively_add_projects(project)
|
||||
if node.nodeName == 'extend-project':
|
||||
name = self._reqatt(node, 'name')
|
||||
|
||||
if name not in self._projects:
|
||||
raise ManifestParseError('extend-project element specifies non-existent '
|
||||
'project: %s' % name)
|
||||
|
||||
path = node.getAttribute('path')
|
||||
groups = node.getAttribute('groups')
|
||||
if groups:
|
||||
groups = self._ParseGroups(groups)
|
||||
|
||||
for p in self._projects[name]:
|
||||
if path and p.relpath != path:
|
||||
continue
|
||||
if groups:
|
||||
p.groups.extend(groups)
|
||||
if node.nodeName == 'repo-hooks':
|
||||
# Get the name of the project and the (space-separated) list of enabled.
|
||||
repo_hooks_project = self._reqatt(node, 'in-project')
|
||||
@ -592,8 +625,11 @@ class XmlManifest(object):
|
||||
review = node.getAttribute('review')
|
||||
if review == '':
|
||||
review = None
|
||||
revision = node.getAttribute('revision')
|
||||
if revision == '':
|
||||
revision = None
|
||||
manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
|
||||
return _XmlRemote(name, alias, fetch, manifestUrl, review)
|
||||
return _XmlRemote(name, alias, fetch, manifestUrl, review, revision)
|
||||
|
||||
def _ParseDefault(self, node):
|
||||
"""
|
||||
@ -686,7 +722,7 @@ class XmlManifest(object):
|
||||
raise ManifestParseError("no remote for project %s within %s" %
|
||||
(name, self.manifestFile))
|
||||
|
||||
revisionExpr = node.getAttribute('revision')
|
||||
revisionExpr = node.getAttribute('revision') or remote.revision
|
||||
if not revisionExpr:
|
||||
revisionExpr = self._default.revisionExpr
|
||||
if not revisionExpr:
|
||||
@ -735,7 +771,7 @@ class XmlManifest(object):
|
||||
groups = ''
|
||||
if node.hasAttribute('groups'):
|
||||
groups = node.getAttribute('groups')
|
||||
groups = [x for x in re.split(r'[,\s]+', groups) if x]
|
||||
groups = self._ParseGroups(groups)
|
||||
|
||||
if parent is None:
|
||||
relpath, worktree, gitdir, objdir = self.GetProjectPaths(name, path)
|
||||
@ -872,10 +908,8 @@ class XmlManifest(object):
|
||||
fromProjects = self.paths
|
||||
toProjects = manifest.paths
|
||||
|
||||
fromKeys = fromProjects.keys()
|
||||
fromKeys.sort()
|
||||
toKeys = toProjects.keys()
|
||||
toKeys.sort()
|
||||
fromKeys = sorted(fromProjects.keys())
|
||||
toKeys = sorted(toProjects.keys())
|
||||
|
||||
diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []}
|
||||
|
||||
|
448
project.py
448
project.py
@ -13,7 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import traceback
|
||||
import contextlib
|
||||
import errno
|
||||
import filecmp
|
||||
import os
|
||||
@ -26,6 +26,7 @@ import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from color import Coloring
|
||||
from git_command import GitCommand, git_require
|
||||
@ -46,7 +47,7 @@ if not is_python3():
|
||||
def _lwrite(path, content):
|
||||
lock = '%s.lock' % path
|
||||
|
||||
fd = open(lock, 'wb')
|
||||
fd = open(lock, 'w')
|
||||
try:
|
||||
fd.write(content)
|
||||
finally:
|
||||
@ -84,7 +85,7 @@ def _ProjectHooks():
|
||||
global _project_hook_list
|
||||
if _project_hook_list is None:
|
||||
d = os.path.realpath(os.path.abspath(os.path.dirname(__file__)))
|
||||
d = os.path.join(d , 'hooks')
|
||||
d = os.path.join(d, 'hooks')
|
||||
_project_hook_list = [os.path.join(d, x) for x in os.listdir(d)]
|
||||
return _project_hook_list
|
||||
|
||||
@ -182,28 +183,28 @@ class ReviewableBranch(object):
|
||||
class StatusColoring(Coloring):
|
||||
def __init__(self, config):
|
||||
Coloring.__init__(self, config, 'status')
|
||||
self.project = self.printer('header', attr = 'bold')
|
||||
self.branch = self.printer('header', attr = 'bold')
|
||||
self.nobranch = self.printer('nobranch', fg = 'red')
|
||||
self.important = self.printer('important', fg = 'red')
|
||||
self.project = self.printer('header', attr='bold')
|
||||
self.branch = self.printer('header', attr='bold')
|
||||
self.nobranch = self.printer('nobranch', fg='red')
|
||||
self.important = self.printer('important', fg='red')
|
||||
|
||||
self.added = self.printer('added', fg = 'green')
|
||||
self.changed = self.printer('changed', fg = 'red')
|
||||
self.untracked = self.printer('untracked', fg = 'red')
|
||||
self.added = self.printer('added', fg='green')
|
||||
self.changed = self.printer('changed', fg='red')
|
||||
self.untracked = self.printer('untracked', fg='red')
|
||||
|
||||
|
||||
class DiffColoring(Coloring):
|
||||
def __init__(self, config):
|
||||
Coloring.__init__(self, config, 'diff')
|
||||
self.project = self.printer('header', attr = 'bold')
|
||||
self.project = self.printer('header', attr='bold')
|
||||
|
||||
class _Annotation:
|
||||
class _Annotation(object):
|
||||
def __init__(self, name, value, keep):
|
||||
self.name = name
|
||||
self.value = value
|
||||
self.keep = keep
|
||||
|
||||
class _CopyFile:
|
||||
class _CopyFile(object):
|
||||
def __init__(self, src, dest, abssrc, absdest):
|
||||
self.src = src
|
||||
self.dest = dest
|
||||
@ -231,7 +232,7 @@ class _CopyFile:
|
||||
except IOError:
|
||||
_error('Cannot copy file %s to %s', src, dest)
|
||||
|
||||
class _LinkFile:
|
||||
class _LinkFile(object):
|
||||
def __init__(self, src, dest, abssrc, absdest):
|
||||
self.src = src
|
||||
self.dest = dest
|
||||
@ -258,11 +259,13 @@ class _LinkFile:
|
||||
class RemoteSpec(object):
|
||||
def __init__(self,
|
||||
name,
|
||||
url = None,
|
||||
review = None):
|
||||
url=None,
|
||||
review=None,
|
||||
revision=None):
|
||||
self.name = name
|
||||
self.url = url
|
||||
self.review = review
|
||||
self.revision = revision
|
||||
|
||||
class RepoHook(object):
|
||||
"""A RepoHook contains information about a script to run as a hook.
|
||||
@ -438,7 +441,8 @@ class RepoHook(object):
|
||||
# and convert to a HookError w/ just the failing traceback.
|
||||
context = {}
|
||||
try:
|
||||
execfile(self._script_fullpath, context)
|
||||
exec(compile(open(self._script_fullpath).read(),
|
||||
self._script_fullpath, 'exec'), context)
|
||||
except Exception:
|
||||
raise HookError('%s\nFailed to import %s hook; see traceback above.' % (
|
||||
traceback.format_exc(), self._hook_type))
|
||||
@ -517,15 +521,15 @@ class Project(object):
|
||||
relpath,
|
||||
revisionExpr,
|
||||
revisionId,
|
||||
rebase = True,
|
||||
groups = None,
|
||||
sync_c = False,
|
||||
sync_s = False,
|
||||
clone_depth = None,
|
||||
upstream = None,
|
||||
parent = None,
|
||||
is_derived = False,
|
||||
dest_branch = None):
|
||||
rebase=True,
|
||||
groups=None,
|
||||
sync_c=False,
|
||||
sync_s=False,
|
||||
clone_depth=None,
|
||||
upstream=None,
|
||||
parent=None,
|
||||
is_derived=False,
|
||||
dest_branch=None):
|
||||
"""Init a Project object.
|
||||
|
||||
Args:
|
||||
@ -582,8 +586,8 @@ class Project(object):
|
||||
self.linkfiles = []
|
||||
self.annotations = []
|
||||
self.config = GitConfig.ForRepository(
|
||||
gitdir = self.gitdir,
|
||||
defaults = self.manifest.globalConfig)
|
||||
gitdir=self.gitdir,
|
||||
defaults=self.manifest.globalConfig)
|
||||
|
||||
if self.worktree:
|
||||
self.work_git = self._GitGetByExec(self, bare=False, gitdir=gitdir)
|
||||
@ -733,27 +737,49 @@ class Project(object):
|
||||
return matched
|
||||
|
||||
## Status Display ##
|
||||
def UncommitedFiles(self, get_all=True):
|
||||
"""Returns a list of strings, uncommitted files in the git tree.
|
||||
|
||||
def HasChanges(self):
|
||||
"""Returns true if there are uncommitted changes.
|
||||
Args:
|
||||
get_all: a boolean, if True - get information about all different
|
||||
uncommitted files. If False - return as soon as any kind of
|
||||
uncommitted files is detected.
|
||||
"""
|
||||
details = []
|
||||
self.work_git.update_index('-q',
|
||||
'--unmerged',
|
||||
'--ignore-missing',
|
||||
'--refresh')
|
||||
if self.IsRebaseInProgress():
|
||||
return True
|
||||
details.append("rebase in progress")
|
||||
if not get_all:
|
||||
return details
|
||||
|
||||
if self.work_git.DiffZ('diff-index', '--cached', HEAD):
|
||||
return True
|
||||
changes = self.work_git.DiffZ('diff-index', '--cached', HEAD).keys()
|
||||
if changes:
|
||||
details.extend(changes)
|
||||
if not get_all:
|
||||
return details
|
||||
|
||||
if self.work_git.DiffZ('diff-files'):
|
||||
return True
|
||||
changes = self.work_git.DiffZ('diff-files').keys()
|
||||
if changes:
|
||||
details.extend(changes)
|
||||
if not get_all:
|
||||
return details
|
||||
|
||||
if self.work_git.LsOthers():
|
||||
return True
|
||||
changes = self.work_git.LsOthers()
|
||||
if changes:
|
||||
details.extend(changes)
|
||||
|
||||
return False
|
||||
return details
|
||||
|
||||
def HasChanges(self):
|
||||
"""Returns true if there are uncommitted changes.
|
||||
"""
|
||||
if self.UncommitedFiles(get_all=False):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def PrintWorkTreeStatus(self, output_redir=None):
|
||||
"""Prints the status of the repository to stdout.
|
||||
@ -783,7 +809,7 @@ class Project(object):
|
||||
out = StatusColoring(self.config)
|
||||
if not output_redir == None:
|
||||
out.redirect(output_redir)
|
||||
out.project('project %-40s', self.relpath + '/')
|
||||
out.project('project %-40s', self.relpath + '/ ')
|
||||
|
||||
branch = self.CurrentBranch
|
||||
if branch is None:
|
||||
@ -854,8 +880,8 @@ class Project(object):
|
||||
cmd.append('--')
|
||||
p = GitCommand(self,
|
||||
cmd,
|
||||
capture_stdout = True,
|
||||
capture_stderr = True)
|
||||
capture_stdout=True,
|
||||
capture_stderr=True)
|
||||
has_diff = False
|
||||
for line in p.process.stdout:
|
||||
if not has_diff:
|
||||
@ -940,7 +966,7 @@ class Project(object):
|
||||
return None
|
||||
|
||||
def UploadForReview(self, branch=None,
|
||||
people=([],[]),
|
||||
people=([], []),
|
||||
auto_topic=False,
|
||||
draft=False,
|
||||
dest_branch=None):
|
||||
@ -1001,13 +1027,13 @@ class Project(object):
|
||||
ref_spec = ref_spec + '%' + ','.join(rp)
|
||||
cmd.append(ref_spec)
|
||||
|
||||
if GitCommand(self, cmd, bare = True).Wait() != 0:
|
||||
if GitCommand(self, cmd, bare=True).Wait() != 0:
|
||||
raise UploadError('Upload failed')
|
||||
|
||||
msg = "posted to %s for %s" % (branch.remote.review, dest_branch)
|
||||
self.bare_git.UpdateRef(R_PUB + branch.name,
|
||||
R_HEADS + branch.name,
|
||||
message = msg)
|
||||
message=msg)
|
||||
|
||||
|
||||
## Sync ##
|
||||
@ -1108,7 +1134,7 @@ class Project(object):
|
||||
and not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir,
|
||||
current_branch_only=current_branch_only,
|
||||
no_tags=no_tags)):
|
||||
return False
|
||||
return False
|
||||
|
||||
if self.worktree:
|
||||
self._InitMRef()
|
||||
@ -1304,7 +1330,7 @@ class Project(object):
|
||||
|
||||
if cnt_mine > 0 and self.rebase:
|
||||
def _dorebase():
|
||||
self._Rebase(upstream = '%s^1' % last_mine, onto = revid)
|
||||
self._Rebase(upstream='%s^1' % last_mine, onto=revid)
|
||||
self._CopyAndLinkFiles()
|
||||
syncbuf.later2(self, _dorebase)
|
||||
elif local_changes:
|
||||
@ -1359,11 +1385,11 @@ class Project(object):
|
||||
return True
|
||||
|
||||
all_refs = self.bare_ref.all
|
||||
if (R_HEADS + name) in all_refs:
|
||||
if R_HEADS + name in all_refs:
|
||||
return GitCommand(self,
|
||||
['checkout', name, '--'],
|
||||
capture_stdout = True,
|
||||
capture_stderr = True).Wait() == 0
|
||||
capture_stdout=True,
|
||||
capture_stderr=True).Wait() == 0
|
||||
|
||||
branch = self.GetBranch(name)
|
||||
branch.remote = self.GetRemote(self.remote.name)
|
||||
@ -1390,8 +1416,8 @@ class Project(object):
|
||||
|
||||
if GitCommand(self,
|
||||
['checkout', '-b', branch.name, revid],
|
||||
capture_stdout = True,
|
||||
capture_stderr = True).Wait() == 0:
|
||||
capture_stdout=True,
|
||||
capture_stderr=True).Wait() == 0:
|
||||
branch.Save()
|
||||
return True
|
||||
return False
|
||||
@ -1437,8 +1463,8 @@ class Project(object):
|
||||
|
||||
return GitCommand(self,
|
||||
['checkout', name, '--'],
|
||||
capture_stdout = True,
|
||||
capture_stderr = True).Wait() == 0
|
||||
capture_stdout=True,
|
||||
capture_stderr=True).Wait() == 0
|
||||
|
||||
def AbandonBranch(self, name):
|
||||
"""Destroy a local topic branch.
|
||||
@ -1472,8 +1498,8 @@ class Project(object):
|
||||
|
||||
return GitCommand(self,
|
||||
['branch', '-D', name],
|
||||
capture_stdout = True,
|
||||
capture_stderr = True).Wait() == 0
|
||||
capture_stdout=True,
|
||||
capture_stderr=True).Wait() == 0
|
||||
|
||||
def PruneHeads(self):
|
||||
"""Prune any topic branches already merged into upstream.
|
||||
@ -1490,7 +1516,7 @@ class Project(object):
|
||||
rev = self.GetRevisionId(left)
|
||||
if cb is not None \
|
||||
and not self._revlist(HEAD + '...' + rev) \
|
||||
and not self.IsDirty(consider_untracked = False):
|
||||
and not self.IsDirty(consider_untracked=False):
|
||||
self.work_git.DetachHead(HEAD)
|
||||
kill.append(cb)
|
||||
|
||||
@ -1523,7 +1549,7 @@ class Project(object):
|
||||
|
||||
kept = []
|
||||
for branch in kill:
|
||||
if (R_HEADS + branch) in left:
|
||||
if R_HEADS + branch in left:
|
||||
branch = self.GetBranch(branch)
|
||||
base = branch.LocalMerge
|
||||
if not base:
|
||||
@ -1573,8 +1599,8 @@ class Project(object):
|
||||
def parse_gitmodules(gitdir, rev):
|
||||
cmd = ['cat-file', 'blob', '%s:.gitmodules' % rev]
|
||||
try:
|
||||
p = GitCommand(None, cmd, capture_stdout = True, capture_stderr = True,
|
||||
bare = True, gitdir = gitdir)
|
||||
p = GitCommand(None, cmd, capture_stdout=True, capture_stderr=True,
|
||||
bare=True, gitdir=gitdir)
|
||||
except GitError:
|
||||
return [], []
|
||||
if p.Wait() != 0:
|
||||
@ -1586,8 +1612,8 @@ class Project(object):
|
||||
os.write(fd, p.stdout)
|
||||
os.close(fd)
|
||||
cmd = ['config', '--file', temp_gitmodules_path, '--list']
|
||||
p = GitCommand(None, cmd, capture_stdout = True, capture_stderr = True,
|
||||
bare = True, gitdir = gitdir)
|
||||
p = GitCommand(None, cmd, capture_stdout=True, capture_stderr=True,
|
||||
bare=True, gitdir=gitdir)
|
||||
if p.Wait() != 0:
|
||||
return [], []
|
||||
gitmodules_lines = p.stdout.split('\n')
|
||||
@ -1620,8 +1646,8 @@ class Project(object):
|
||||
cmd = ['ls-tree', rev, '--']
|
||||
cmd.extend(paths)
|
||||
try:
|
||||
p = GitCommand(None, cmd, capture_stdout = True, capture_stderr = True,
|
||||
bare = True, gitdir = gitdir)
|
||||
p = GitCommand(None, cmd, capture_stdout=True, capture_stderr=True,
|
||||
bare=True, gitdir=gitdir)
|
||||
except GitError:
|
||||
return []
|
||||
if p.Wait() != 0:
|
||||
@ -1656,23 +1682,24 @@ class Project(object):
|
||||
continue
|
||||
|
||||
remote = RemoteSpec(self.remote.name,
|
||||
url = url,
|
||||
review = self.remote.review)
|
||||
subproject = Project(manifest = self.manifest,
|
||||
name = name,
|
||||
remote = remote,
|
||||
gitdir = gitdir,
|
||||
objdir = objdir,
|
||||
worktree = worktree,
|
||||
relpath = relpath,
|
||||
revisionExpr = self.revisionExpr,
|
||||
revisionId = rev,
|
||||
rebase = self.rebase,
|
||||
groups = self.groups,
|
||||
sync_c = self.sync_c,
|
||||
sync_s = self.sync_s,
|
||||
parent = self,
|
||||
is_derived = True)
|
||||
url=url,
|
||||
review=self.remote.review,
|
||||
revision=self.remote.revision)
|
||||
subproject = Project(manifest=self.manifest,
|
||||
name=name,
|
||||
remote=remote,
|
||||
gitdir=gitdir,
|
||||
objdir=objdir,
|
||||
worktree=worktree,
|
||||
relpath=relpath,
|
||||
revisionExpr=self.revisionExpr,
|
||||
revisionId=rev,
|
||||
rebase=self.rebase,
|
||||
groups=self.groups,
|
||||
sync_c=self.sync_c,
|
||||
sync_s=self.sync_s,
|
||||
parent=self,
|
||||
is_derived=True)
|
||||
result.append(subproject)
|
||||
result.extend(subproject.GetDerivedSubprojects())
|
||||
return result
|
||||
@ -1702,6 +1729,7 @@ class Project(object):
|
||||
if command.Wait() != 0:
|
||||
raise GitError('git archive %s: %s' % (self.name, command.stderr))
|
||||
|
||||
|
||||
def _RemoteFetch(self, name=None,
|
||||
current_branch_only=False,
|
||||
initial=False,
|
||||
@ -1721,22 +1749,33 @@ class Project(object):
|
||||
depth = self.clone_depth
|
||||
else:
|
||||
depth = self.manifest.manifestProject.config.GetString('repo.depth')
|
||||
# The repo project should never be synced with partial depth
|
||||
if self.relpath == '.repo/repo':
|
||||
depth = None
|
||||
|
||||
if depth:
|
||||
current_branch_only = True
|
||||
|
||||
if ID_RE.match(self.revisionExpr) is not None:
|
||||
is_sha1 = True
|
||||
|
||||
if current_branch_only:
|
||||
if ID_RE.match(self.revisionExpr) is not None:
|
||||
is_sha1 = True
|
||||
elif self.revisionExpr.startswith(R_TAGS):
|
||||
if self.revisionExpr.startswith(R_TAGS):
|
||||
# this is a tag and its sha1 value should never change
|
||||
tag_name = self.revisionExpr[len(R_TAGS):]
|
||||
|
||||
if is_sha1 or tag_name is not None:
|
||||
if self._CheckForSha1():
|
||||
return True
|
||||
if is_sha1 and (not self.upstream or ID_RE.match(self.upstream)):
|
||||
current_branch_only = False
|
||||
if is_sha1 and not depth:
|
||||
# When syncing a specific commit and --depth is not set:
|
||||
# * if upstream is explicitly specified and is not a sha1, fetch only
|
||||
# upstream as users expect only upstream to be fetch.
|
||||
# Note: The commit might not be in upstream in which case the sync
|
||||
# will fail.
|
||||
# * otherwise, fetch all branches to make sure we end up with the
|
||||
# specific commit.
|
||||
current_branch_only = self.upstream and not ID_RE.match(self.upstream)
|
||||
|
||||
if not name:
|
||||
name = self.remote.name
|
||||
@ -1786,9 +1825,7 @@ class Project(object):
|
||||
|
||||
cmd = ['fetch']
|
||||
|
||||
# The --depth option only affects the initial fetch; after that we'll do
|
||||
# full fetches of changes.
|
||||
if depth and initial:
|
||||
if depth:
|
||||
cmd.append('--depth=%s' % depth)
|
||||
|
||||
if quiet:
|
||||
@ -1804,26 +1841,57 @@ class Project(object):
|
||||
else:
|
||||
cmd.append('--tags')
|
||||
|
||||
spec = []
|
||||
if not current_branch_only:
|
||||
# Fetch whole repo
|
||||
cmd.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')))
|
||||
spec.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')))
|
||||
elif tag_name is not None:
|
||||
cmd.append('tag')
|
||||
cmd.append(tag_name)
|
||||
spec.append('tag')
|
||||
spec.append(tag_name)
|
||||
|
||||
branch = self.revisionExpr
|
||||
if is_sha1 and depth:
|
||||
# Shallow checkout of a specific commit, fetch from that commit and not
|
||||
# the heads only as the commit might be deeper in the history.
|
||||
spec.append(branch)
|
||||
else:
|
||||
branch = self.revisionExpr
|
||||
if is_sha1:
|
||||
branch = self.upstream
|
||||
if branch.startswith(R_HEADS):
|
||||
branch = branch[len(R_HEADS):]
|
||||
cmd.append(str((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)))
|
||||
if branch is not None and branch.strip():
|
||||
if not branch.startswith('refs/'):
|
||||
branch = R_HEADS + branch
|
||||
spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch)))
|
||||
cmd.extend(spec)
|
||||
|
||||
shallowfetch = self.config.GetString('repo.shallowfetch')
|
||||
if shallowfetch and shallowfetch != ' '.join(spec):
|
||||
GitCommand(self, ['fetch', '--unshallow', name] + shallowfetch.split(),
|
||||
bare=True, ssh_proxy=ssh_proxy).Wait()
|
||||
if depth:
|
||||
self.config.SetString('repo.shallowfetch', ' '.join(spec))
|
||||
else:
|
||||
self.config.SetString('repo.shallowfetch', None)
|
||||
|
||||
ok = False
|
||||
for _i in range(2):
|
||||
ret = GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy).Wait()
|
||||
gitcmd = GitCommand(self, cmd, bare=True, capture_stderr=True,
|
||||
ssh_proxy=ssh_proxy)
|
||||
ret = gitcmd.Wait()
|
||||
print(gitcmd.stderr, file=sys.stderr, end='')
|
||||
if ret == 0:
|
||||
ok = True
|
||||
break
|
||||
# If needed, run the 'git remote prune' the first time through the loop
|
||||
elif (not _i and
|
||||
"error:" in gitcmd.stderr and
|
||||
"git remote prune" in gitcmd.stderr):
|
||||
prunecmd = GitCommand(self, ['remote', 'prune', name], bare=True,
|
||||
capture_stderr=True, ssh_proxy=ssh_proxy)
|
||||
ret = prunecmd.Wait()
|
||||
print(prunecmd.stderr, file=sys.stderr, end='')
|
||||
if ret:
|
||||
break
|
||||
continue
|
||||
elif current_branch_only and is_sha1 and ret == 128:
|
||||
# Exit code 128 means "couldn't find the ref you asked for"; if we're in sha1
|
||||
# mode, we just tried sync'ing from the upstream field; it doesn't exist, thus
|
||||
@ -1832,11 +1900,6 @@ class Project(object):
|
||||
time.sleep(random.randint(30, 45))
|
||||
|
||||
if initial:
|
||||
# Ensure that some refs exist. Otherwise, we probably aren't looking
|
||||
# at a real git repository and may have a bad url.
|
||||
if not self.bare_ref.all:
|
||||
ok = False
|
||||
|
||||
if alt_dir:
|
||||
if old_packed != '':
|
||||
_lwrite(packed_refs, old_packed)
|
||||
@ -1911,34 +1974,34 @@ class Project(object):
|
||||
os.remove(tmpPath)
|
||||
if 'http_proxy' in os.environ and 'darwin' == sys.platform:
|
||||
cmd += ['--proxy', os.environ['http_proxy']]
|
||||
cookiefile = self._GetBundleCookieFile(srcUrl)
|
||||
if cookiefile:
|
||||
cmd += ['--cookie', cookiefile]
|
||||
if srcUrl.startswith('persistent-'):
|
||||
srcUrl = srcUrl[len('persistent-'):]
|
||||
cmd += [srcUrl]
|
||||
with self._GetBundleCookieFile(srcUrl, quiet) as cookiefile:
|
||||
if cookiefile:
|
||||
cmd += ['--cookie', cookiefile, '--cookie-jar', cookiefile]
|
||||
if srcUrl.startswith('persistent-'):
|
||||
srcUrl = srcUrl[len('persistent-'):]
|
||||
cmd += [srcUrl]
|
||||
|
||||
if IsTrace():
|
||||
Trace('%s', ' '.join(cmd))
|
||||
try:
|
||||
proc = subprocess.Popen(cmd)
|
||||
except OSError:
|
||||
return False
|
||||
if IsTrace():
|
||||
Trace('%s', ' '.join(cmd))
|
||||
try:
|
||||
proc = subprocess.Popen(cmd)
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
curlret = proc.wait()
|
||||
curlret = proc.wait()
|
||||
|
||||
if curlret == 22:
|
||||
# From curl man page:
|
||||
# 22: HTTP page not retrieved. The requested url was not found or
|
||||
# returned another error with the HTTP error code being 400 or above.
|
||||
# This return code only appears if -f, --fail is used.
|
||||
if not quiet:
|
||||
print("Server does not provide clone.bundle; ignoring.",
|
||||
file=sys.stderr)
|
||||
return False
|
||||
if curlret == 22:
|
||||
# From curl man page:
|
||||
# 22: HTTP page not retrieved. The requested url was not found or
|
||||
# returned another error with the HTTP error code being 400 or above.
|
||||
# This return code only appears if -f, --fail is used.
|
||||
if not quiet:
|
||||
print("Server does not provide clone.bundle; ignoring.",
|
||||
file=sys.stderr)
|
||||
return False
|
||||
|
||||
if os.path.exists(tmpPath):
|
||||
if curlret == 0 and self._IsValidBundle(tmpPath):
|
||||
if curlret == 0 and self._IsValidBundle(tmpPath, quiet):
|
||||
os.rename(tmpPath, dstPath)
|
||||
return True
|
||||
else:
|
||||
@ -1947,45 +2010,51 @@ class Project(object):
|
||||
else:
|
||||
return False
|
||||
|
||||
def _IsValidBundle(self, path):
|
||||
def _IsValidBundle(self, path, quiet):
|
||||
try:
|
||||
with open(path) as f:
|
||||
if f.read(16) == '# v2 git bundle\n':
|
||||
return True
|
||||
else:
|
||||
print("Invalid clone.bundle file; ignoring.", file=sys.stderr)
|
||||
if not quiet:
|
||||
print("Invalid clone.bundle file; ignoring.", file=sys.stderr)
|
||||
return False
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
def _GetBundleCookieFile(self, url):
|
||||
@contextlib.contextmanager
|
||||
def _GetBundleCookieFile(self, url, quiet):
|
||||
if url.startswith('persistent-'):
|
||||
try:
|
||||
p = subprocess.Popen(
|
||||
['git-remote-persistent-https', '-print_config', url],
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
p.stdin.close() # Tell subprocess it's ok to close.
|
||||
prefix = 'http.cookiefile='
|
||||
cookiefile = None
|
||||
for line in p.stdout:
|
||||
line = line.strip()
|
||||
if line.startswith(prefix):
|
||||
cookiefile = line[len(prefix):]
|
||||
break
|
||||
if p.wait():
|
||||
err_msg = p.stderr.read()
|
||||
if ' -print_config' in err_msg:
|
||||
pass # Persistent proxy doesn't support -print_config.
|
||||
else:
|
||||
print(err_msg, file=sys.stderr)
|
||||
if cookiefile:
|
||||
return cookiefile
|
||||
try:
|
||||
prefix = 'http.cookiefile='
|
||||
cookiefile = None
|
||||
for line in p.stdout:
|
||||
line = line.strip()
|
||||
if line.startswith(prefix):
|
||||
cookiefile = line[len(prefix):]
|
||||
break
|
||||
# Leave subprocess open, as cookie file may be transient.
|
||||
if cookiefile:
|
||||
yield cookiefile
|
||||
return
|
||||
finally:
|
||||
p.stdin.close()
|
||||
if p.wait():
|
||||
err_msg = p.stderr.read()
|
||||
if ' -print_config' in err_msg:
|
||||
pass # Persistent proxy doesn't support -print_config.
|
||||
elif not quiet:
|
||||
print(err_msg, file=sys.stderr)
|
||||
except OSError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
pass # No persistent proxy.
|
||||
raise
|
||||
return GitConfig.ForUser().GetString('http.cookiefile')
|
||||
yield GitConfig.ForUser().GetString('http.cookiefile')
|
||||
|
||||
def _Checkout(self, rev, quiet=False):
|
||||
cmd = ['checkout']
|
||||
@ -1997,7 +2066,7 @@ class Project(object):
|
||||
if self._allrefs:
|
||||
raise GitError('%s checkout %s ' % (self.name, rev))
|
||||
|
||||
def _CherryPick(self, rev, quiet=False):
|
||||
def _CherryPick(self, rev):
|
||||
cmd = ['cherry-pick']
|
||||
cmd.append(rev)
|
||||
cmd.append('--')
|
||||
@ -2005,7 +2074,7 @@ class Project(object):
|
||||
if self._allrefs:
|
||||
raise GitError('%s cherry-pick %s ' % (self.name, rev))
|
||||
|
||||
def _Revert(self, rev, quiet=False):
|
||||
def _Revert(self, rev):
|
||||
cmd = ['revert']
|
||||
cmd.append('--no-edit')
|
||||
cmd.append(rev)
|
||||
@ -2022,7 +2091,7 @@ class Project(object):
|
||||
if GitCommand(self, cmd).Wait() != 0:
|
||||
raise GitError('%s reset --hard %s ' % (self.name, rev))
|
||||
|
||||
def _Rebase(self, upstream, onto = None):
|
||||
def _Rebase(self, upstream, onto=None):
|
||||
cmd = ['rebase']
|
||||
if onto is not None:
|
||||
cmd.extend(['--onto', onto])
|
||||
@ -2077,7 +2146,7 @@ class Project(object):
|
||||
|
||||
m = self.manifest.manifestProject.config
|
||||
for key in ['user.name', 'user.email']:
|
||||
if m.Has(key, include_defaults = False):
|
||||
if m.Has(key, include_defaults=False):
|
||||
self.config.SetString(key, m.GetString(key))
|
||||
if self.manifest.IsMirror:
|
||||
self.config.SetString('core.bare', 'true')
|
||||
@ -2086,15 +2155,6 @@ class Project(object):
|
||||
|
||||
def _UpdateHooks(self):
|
||||
if os.path.exists(self.gitdir):
|
||||
# Always recreate hooks since they can have been changed
|
||||
# since the latest update.
|
||||
hooks = self._gitdir_path('hooks')
|
||||
try:
|
||||
to_rm = os.listdir(hooks)
|
||||
except OSError:
|
||||
to_rm = []
|
||||
for old_hook in to_rm:
|
||||
os.remove(os.path.join(hooks, old_hook))
|
||||
self._InitHooks()
|
||||
|
||||
def _InitHooks(self):
|
||||
@ -2157,7 +2217,7 @@ class Project(object):
|
||||
if cur != '' or self.bare_ref.get(ref) != self.revisionId:
|
||||
msg = 'manifest set to %s' % self.revisionId
|
||||
dst = self.revisionId + '^0'
|
||||
self.bare_git.UpdateRef(ref, dst, message = msg, detach = True)
|
||||
self.bare_git.UpdateRef(ref, dst, message=msg, detach=True)
|
||||
else:
|
||||
remote = self.GetRemote(self.remote.name)
|
||||
dst = remote.ToLocal(self.revisionExpr)
|
||||
@ -2201,6 +2261,14 @@ class Project(object):
|
||||
if name in symlink_dirs and not os.path.lexists(src):
|
||||
os.makedirs(src)
|
||||
|
||||
# If the source file doesn't exist, ensure the destination
|
||||
# file doesn't either.
|
||||
if name in symlink_files and not os.path.lexists(src):
|
||||
try:
|
||||
os.remove(dst)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
if name in to_symlink:
|
||||
os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst)
|
||||
elif copy_all and not os.path.islink(dst):
|
||||
@ -2293,10 +2361,10 @@ class Project(object):
|
||||
'-z',
|
||||
'--others',
|
||||
'--exclude-standard'],
|
||||
bare = False,
|
||||
bare=False,
|
||||
gitdir=self._gitdir,
|
||||
capture_stdout = True,
|
||||
capture_stderr = True)
|
||||
capture_stdout=True,
|
||||
capture_stderr=True)
|
||||
if p.Wait() == 0:
|
||||
out = p.stdout
|
||||
if out:
|
||||
@ -2311,9 +2379,9 @@ class Project(object):
|
||||
p = GitCommand(self._project,
|
||||
cmd,
|
||||
gitdir=self._gitdir,
|
||||
bare = False,
|
||||
capture_stdout = True,
|
||||
capture_stderr = True)
|
||||
bare=False,
|
||||
capture_stdout=True,
|
||||
capture_stderr=True)
|
||||
try:
|
||||
out = p.process.stdout.read()
|
||||
r = {}
|
||||
@ -2321,8 +2389,8 @@ class Project(object):
|
||||
out = iter(out[:-1].split('\0')) # pylint: disable=W1401
|
||||
while out:
|
||||
try:
|
||||
info = out.next()
|
||||
path = out.next()
|
||||
info = next(out)
|
||||
path = next(out)
|
||||
except StopIteration:
|
||||
break
|
||||
|
||||
@ -2348,7 +2416,7 @@ class Project(object):
|
||||
info = _Info(path, *info)
|
||||
if info.status in ('R', 'C'):
|
||||
info.src_path = info.path
|
||||
info.path = out.next()
|
||||
info.path = next(out)
|
||||
r[info.path] = info
|
||||
return r
|
||||
finally:
|
||||
@ -2419,10 +2487,10 @@ class Project(object):
|
||||
cmdv.extend(args)
|
||||
p = GitCommand(self._project,
|
||||
cmdv,
|
||||
bare = self._bare,
|
||||
bare=self._bare,
|
||||
gitdir=self._gitdir,
|
||||
capture_stdout = True,
|
||||
capture_stderr = True)
|
||||
capture_stdout=True,
|
||||
capture_stderr=True)
|
||||
r = []
|
||||
for line in p.process.stdout:
|
||||
if line[-1] == '\n':
|
||||
@ -2472,10 +2540,10 @@ class Project(object):
|
||||
cmdv.extend(args)
|
||||
p = GitCommand(self._project,
|
||||
cmdv,
|
||||
bare = self._bare,
|
||||
bare=self._bare,
|
||||
gitdir=self._gitdir,
|
||||
capture_stdout = True,
|
||||
capture_stderr = True)
|
||||
capture_stdout=True,
|
||||
capture_stderr=True)
|
||||
if p.Wait() != 0:
|
||||
raise GitError('%s %s: %s' % (
|
||||
self._project.name,
|
||||
@ -2540,9 +2608,9 @@ class _Later(object):
|
||||
class _SyncColoring(Coloring):
|
||||
def __init__(self, config):
|
||||
Coloring.__init__(self, config, 'reposync')
|
||||
self.project = self.printer('header', attr = 'bold')
|
||||
self.info = self.printer('info')
|
||||
self.fail = self.printer('fail', fg='red')
|
||||
self.project = self.printer('header', attr='bold')
|
||||
self.info = self.printer('info')
|
||||
self.fail = self.printer('fail', fg='red')
|
||||
|
||||
class SyncBuffer(object):
|
||||
def __init__(self, config, detach_head=False):
|
||||
@ -2604,16 +2672,16 @@ class MetaProject(Project):
|
||||
"""
|
||||
def __init__(self, manifest, name, gitdir, worktree):
|
||||
Project.__init__(self,
|
||||
manifest = manifest,
|
||||
name = name,
|
||||
gitdir = gitdir,
|
||||
objdir = gitdir,
|
||||
worktree = worktree,
|
||||
remote = RemoteSpec('origin'),
|
||||
relpath = '.repo/%s' % name,
|
||||
revisionExpr = 'refs/heads/master',
|
||||
revisionId = None,
|
||||
groups = None)
|
||||
manifest=manifest,
|
||||
name=name,
|
||||
gitdir=gitdir,
|
||||
objdir=gitdir,
|
||||
worktree=worktree,
|
||||
remote=RemoteSpec('origin'),
|
||||
relpath='.repo/%s' % name,
|
||||
revisionExpr='refs/heads/master',
|
||||
revisionId=None,
|
||||
groups=None)
|
||||
|
||||
def PreSync(self):
|
||||
if self.Exists:
|
||||
@ -2624,20 +2692,20 @@ class MetaProject(Project):
|
||||
self.revisionExpr = base
|
||||
self.revisionId = None
|
||||
|
||||
def MetaBranchSwitch(self, target):
|
||||
def MetaBranchSwitch(self):
|
||||
""" Prepare MetaProject for manifest branch switch
|
||||
"""
|
||||
|
||||
# detach and delete manifest branch, allowing a new
|
||||
# branch to take over
|
||||
syncbuf = SyncBuffer(self.config, detach_head = True)
|
||||
syncbuf = SyncBuffer(self.config, detach_head=True)
|
||||
self.Sync_LocalHalf(syncbuf)
|
||||
syncbuf.Finish()
|
||||
|
||||
return GitCommand(self,
|
||||
['update-ref', '-d', 'refs/heads/default'],
|
||||
capture_stdout = True,
|
||||
capture_stderr = True).Wait() == 0
|
||||
capture_stdout=True,
|
||||
capture_stderr=True).Wait() == 0
|
||||
|
||||
|
||||
@property
|
||||
|
12
repo
12
repo
@ -139,10 +139,6 @@ def _print(*objects, **kwargs):
|
||||
|
||||
# Python version check
|
||||
ver = sys.version_info
|
||||
if ver[0] == 3:
|
||||
_print('warning: Python 3 support is currently experimental. YMMV.\n'
|
||||
'Please use Python 2.6 - 2.7 instead.',
|
||||
file=sys.stderr)
|
||||
if (ver[0], ver[1]) < MIN_PYTHON_VERSION:
|
||||
_print('error: Python version %s unsupported.\n'
|
||||
'Please use Python 2.6 - 2.7 instead.'
|
||||
@ -466,7 +462,7 @@ def _DownloadBundle(url, local, quiet):
|
||||
try:
|
||||
r = urllib.request.urlopen(url)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code in [403, 404]:
|
||||
if e.code in [401, 403, 404]:
|
||||
return False
|
||||
_print('fatal: Cannot get %s' % url, file=sys.stderr)
|
||||
_print('fatal: HTTP error %s' % e.code, file=sys.stderr)
|
||||
@ -742,7 +738,7 @@ def main(orig_args):
|
||||
try:
|
||||
_Init(args)
|
||||
except CloneFailure:
|
||||
shutil.rmtree(repodir, ignore_errors=True)
|
||||
shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True)
|
||||
sys.exit(1)
|
||||
repo_main, rel_repo_dir = _FindRepo()
|
||||
else:
|
||||
@ -768,4 +764,8 @@ def main(orig_args):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if ver[0] == 3:
|
||||
_print('warning: Python 3 support is currently experimental. YMMV.\n'
|
||||
'Please use Python 2.6 - 2.7 instead.',
|
||||
file=sys.stderr)
|
||||
main(sys.argv[1:])
|
||||
|
@ -46,6 +46,10 @@ class BranchInfo(object):
|
||||
def IsCurrent(self):
|
||||
return self.current > 0
|
||||
|
||||
@property
|
||||
def IsSplitCurrent(self):
|
||||
return self.current != 0 and self.current != len(self.projects)
|
||||
|
||||
@property
|
||||
def IsPublished(self):
|
||||
return self.published > 0
|
||||
@ -139,10 +143,14 @@ is shown, then the branch appears in all projects.
|
||||
if in_cnt < project_cnt:
|
||||
fmt = out.write
|
||||
paths = []
|
||||
if in_cnt < project_cnt - in_cnt:
|
||||
non_cur_paths = []
|
||||
if i.IsSplitCurrent or (in_cnt < project_cnt - in_cnt):
|
||||
in_type = 'in'
|
||||
for b in i.projects:
|
||||
paths.append(b.project.relpath)
|
||||
if not i.IsSplitCurrent or b.current:
|
||||
paths.append(b.project.relpath)
|
||||
else:
|
||||
non_cur_paths.append(b.project.relpath)
|
||||
else:
|
||||
fmt = out.notinproject
|
||||
in_type = 'not in'
|
||||
@ -154,13 +162,19 @@ is shown, then the branch appears in all projects.
|
||||
paths.append(p.relpath)
|
||||
|
||||
s = ' %s %s' % (in_type, ', '.join(paths))
|
||||
if width + 7 + len(s) < 80:
|
||||
if not i.IsSplitCurrent and (width + 7 + len(s) < 80):
|
||||
fmt = out.current if i.IsCurrent else fmt
|
||||
fmt(s)
|
||||
else:
|
||||
fmt(' %s:' % in_type)
|
||||
fmt = out.current if i.IsCurrent else out.write
|
||||
for p in paths:
|
||||
out.nl()
|
||||
fmt(width*' ' + ' %s' % p)
|
||||
fmt = out.write
|
||||
for p in non_cur_paths:
|
||||
out.nl()
|
||||
fmt(width*' ' + ' %s' % p)
|
||||
else:
|
||||
out.write(' in all projects')
|
||||
out.nl()
|
||||
|
@ -93,6 +93,7 @@ makes it available in your project's local working directory.
|
||||
except GitError:
|
||||
print('[%s] Could not complete the cherry-pick of %s' \
|
||||
% (project.name, dl.commit), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
elif opt.revert:
|
||||
project._Revert(dl.commit)
|
||||
|
@ -14,7 +14,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import errno
|
||||
import fcntl
|
||||
import multiprocessing
|
||||
import re
|
||||
import os
|
||||
import select
|
||||
@ -31,6 +33,7 @@ _CAN_COLOR = [
|
||||
'log',
|
||||
]
|
||||
|
||||
|
||||
class ForallColoring(Coloring):
|
||||
def __init__(self, config):
|
||||
Coloring.__init__(self, config, 'forall')
|
||||
@ -132,9 +135,31 @@ without iterating through the remaining projects.
|
||||
g.add_option('-v', '--verbose',
|
||||
dest='verbose', action='store_true',
|
||||
help='Show command error messages')
|
||||
g.add_option('-j', '--jobs',
|
||||
dest='jobs', action='store', type='int', default=1,
|
||||
help='number of commands to execute simultaneously')
|
||||
|
||||
def WantPager(self, opt):
|
||||
return opt.project_header
|
||||
return opt.project_header and opt.jobs == 1
|
||||
|
||||
def _SerializeProject(self, project):
|
||||
""" Serialize a project._GitGetByExec instance.
|
||||
|
||||
project._GitGetByExec is not pickle-able. Instead of trying to pass it
|
||||
around between processes, make a dict ourselves containing only the
|
||||
attributes that we need.
|
||||
|
||||
"""
|
||||
return {
|
||||
'name': project.name,
|
||||
'relpath': project.relpath,
|
||||
'remote_name': project.remote.name,
|
||||
'lrev': project.GetRevisionId(),
|
||||
'rrev': project.revisionExpr,
|
||||
'annotations': dict((a.name, a.value) for a in project.annotations),
|
||||
'gitdir': project.gitdir,
|
||||
'worktree': project.worktree,
|
||||
}
|
||||
|
||||
def Execute(self, opt, args):
|
||||
if not opt.command:
|
||||
@ -173,11 +198,7 @@ without iterating through the remaining projects.
|
||||
# pylint: enable=W0631
|
||||
|
||||
mirror = self.manifest.IsMirror
|
||||
out = ForallColoring(self.manifest.manifestProject.config)
|
||||
out.redirect(sys.stdout)
|
||||
|
||||
rc = 0
|
||||
first = True
|
||||
|
||||
if not opt.regex:
|
||||
projects = self.GetProjects(args)
|
||||
@ -186,113 +207,156 @@ without iterating through the remaining projects.
|
||||
|
||||
os.environ['REPO_COUNT'] = str(len(projects))
|
||||
|
||||
for (cnt, project) in enumerate(projects):
|
||||
env = os.environ.copy()
|
||||
def setenv(name, val):
|
||||
if val is None:
|
||||
val = ''
|
||||
env[name] = val.encode()
|
||||
|
||||
setenv('REPO_PROJECT', project.name)
|
||||
setenv('REPO_PATH', project.relpath)
|
||||
setenv('REPO_REMOTE', project.remote.name)
|
||||
setenv('REPO_LREV', project.GetRevisionId())
|
||||
setenv('REPO_RREV', project.revisionExpr)
|
||||
setenv('REPO_I', str(cnt + 1))
|
||||
for a in project.annotations:
|
||||
setenv("REPO__%s" % (a.name), a.value)
|
||||
|
||||
if mirror:
|
||||
setenv('GIT_DIR', project.gitdir)
|
||||
cwd = project.gitdir
|
||||
else:
|
||||
cwd = project.worktree
|
||||
|
||||
if not os.path.exists(cwd):
|
||||
if (opt.project_header and opt.verbose) \
|
||||
or not opt.project_header:
|
||||
print('skipping %s/' % project.relpath, file=sys.stderr)
|
||||
continue
|
||||
|
||||
if opt.project_header:
|
||||
stdin = subprocess.PIPE
|
||||
stdout = subprocess.PIPE
|
||||
stderr = subprocess.PIPE
|
||||
else:
|
||||
stdin = None
|
||||
stdout = None
|
||||
stderr = None
|
||||
|
||||
p = subprocess.Popen(cmd,
|
||||
cwd = cwd,
|
||||
shell = shell,
|
||||
env = env,
|
||||
stdin = stdin,
|
||||
stdout = stdout,
|
||||
stderr = stderr)
|
||||
|
||||
if opt.project_header:
|
||||
class sfd(object):
|
||||
def __init__(self, fd, dest):
|
||||
self.fd = fd
|
||||
self.dest = dest
|
||||
def fileno(self):
|
||||
return self.fd.fileno()
|
||||
|
||||
empty = True
|
||||
errbuf = ''
|
||||
|
||||
p.stdin.close()
|
||||
s_in = [sfd(p.stdout, sys.stdout),
|
||||
sfd(p.stderr, sys.stderr)]
|
||||
|
||||
for s in s_in:
|
||||
flags = fcntl.fcntl(s.fd, fcntl.F_GETFL)
|
||||
fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
|
||||
|
||||
while s_in:
|
||||
in_ready, _out_ready, _err_ready = select.select(s_in, [], [])
|
||||
for s in in_ready:
|
||||
buf = s.fd.read(4096)
|
||||
if not buf:
|
||||
s.fd.close()
|
||||
s_in.remove(s)
|
||||
continue
|
||||
|
||||
if not opt.verbose:
|
||||
if s.fd != p.stdout:
|
||||
errbuf += buf
|
||||
continue
|
||||
|
||||
if empty:
|
||||
if first:
|
||||
first = False
|
||||
else:
|
||||
out.nl()
|
||||
|
||||
if mirror:
|
||||
project_header_path = project.name
|
||||
else:
|
||||
project_header_path = project.relpath
|
||||
out.project('project %s/', project_header_path)
|
||||
out.nl()
|
||||
out.flush()
|
||||
if errbuf:
|
||||
sys.stderr.write(errbuf)
|
||||
sys.stderr.flush()
|
||||
errbuf = ''
|
||||
empty = False
|
||||
|
||||
s.dest.write(buf)
|
||||
s.dest.flush()
|
||||
|
||||
r = p.wait()
|
||||
if r != 0:
|
||||
if r != rc:
|
||||
rc = r
|
||||
if opt.abort_on_errors:
|
||||
print("error: %s: Aborting due to previous error" % project.relpath,
|
||||
file=sys.stderr)
|
||||
sys.exit(r)
|
||||
pool = multiprocessing.Pool(opt.jobs)
|
||||
try:
|
||||
config = self.manifest.manifestProject.config
|
||||
results_it = pool.imap(
|
||||
DoWorkWrapper,
|
||||
[[mirror, opt, cmd, shell, cnt, config, self._SerializeProject(p)]
|
||||
for cnt, p in enumerate(projects)]
|
||||
)
|
||||
pool.close()
|
||||
for r in results_it:
|
||||
rc = rc or r
|
||||
if r != 0 and opt.abort_on_errors:
|
||||
raise Exception('Aborting due to previous error')
|
||||
except (KeyboardInterrupt, WorkerKeyboardInterrupt):
|
||||
# Catch KeyboardInterrupt raised inside and outside of workers
|
||||
print('Interrupted - terminating the pool')
|
||||
pool.terminate()
|
||||
rc = rc or errno.EINTR
|
||||
except Exception as e:
|
||||
# Catch any other exceptions raised
|
||||
print('Got an error, terminating the pool: %r' % e,
|
||||
file=sys.stderr)
|
||||
pool.terminate()
|
||||
rc = rc or getattr(e, 'errno', 1)
|
||||
finally:
|
||||
pool.join()
|
||||
if rc != 0:
|
||||
sys.exit(rc)
|
||||
|
||||
|
||||
class WorkerKeyboardInterrupt(Exception):
|
||||
""" Keyboard interrupt exception for worker processes. """
|
||||
pass
|
||||
|
||||
|
||||
def DoWorkWrapper(args):
|
||||
""" A wrapper around the DoWork() method.
|
||||
|
||||
Catch the KeyboardInterrupt exceptions here and re-raise them as a different,
|
||||
``Exception``-based exception to stop it flooding the console with stacktraces
|
||||
and making the parent hang indefinitely.
|
||||
|
||||
"""
|
||||
project = args.pop()
|
||||
try:
|
||||
return DoWork(project, *args)
|
||||
except KeyboardInterrupt:
|
||||
print('%s: Worker interrupted' % project['name'])
|
||||
raise WorkerKeyboardInterrupt()
|
||||
|
||||
|
||||
def DoWork(project, mirror, opt, cmd, shell, cnt, config):
|
||||
env = os.environ.copy()
|
||||
def setenv(name, val):
|
||||
if val is None:
|
||||
val = ''
|
||||
env[name] = val.encode()
|
||||
|
||||
setenv('REPO_PROJECT', project['name'])
|
||||
setenv('REPO_PATH', project['relpath'])
|
||||
setenv('REPO_REMOTE', project['remote_name'])
|
||||
setenv('REPO_LREV', project['lrev'])
|
||||
setenv('REPO_RREV', project['rrev'])
|
||||
setenv('REPO_I', str(cnt + 1))
|
||||
for name in project['annotations']:
|
||||
setenv("REPO__%s" % (name), project['annotations'][name])
|
||||
|
||||
if mirror:
|
||||
setenv('GIT_DIR', project['gitdir'])
|
||||
cwd = project['gitdir']
|
||||
else:
|
||||
cwd = project['worktree']
|
||||
|
||||
if not os.path.exists(cwd):
|
||||
if (opt.project_header and opt.verbose) \
|
||||
or not opt.project_header:
|
||||
print('skipping %s/' % project['relpath'], file=sys.stderr)
|
||||
return
|
||||
|
||||
if opt.project_header:
|
||||
stdin = subprocess.PIPE
|
||||
stdout = subprocess.PIPE
|
||||
stderr = subprocess.PIPE
|
||||
else:
|
||||
stdin = None
|
||||
stdout = None
|
||||
stderr = None
|
||||
|
||||
p = subprocess.Popen(cmd,
|
||||
cwd=cwd,
|
||||
shell=shell,
|
||||
env=env,
|
||||
stdin=stdin,
|
||||
stdout=stdout,
|
||||
stderr=stderr)
|
||||
|
||||
if opt.project_header:
|
||||
out = ForallColoring(config)
|
||||
out.redirect(sys.stdout)
|
||||
class sfd(object):
|
||||
def __init__(self, fd, dest):
|
||||
self.fd = fd
|
||||
self.dest = dest
|
||||
def fileno(self):
|
||||
return self.fd.fileno()
|
||||
|
||||
empty = True
|
||||
errbuf = ''
|
||||
|
||||
p.stdin.close()
|
||||
s_in = [sfd(p.stdout, sys.stdout),
|
||||
sfd(p.stderr, sys.stderr)]
|
||||
|
||||
for s in s_in:
|
||||
flags = fcntl.fcntl(s.fd, fcntl.F_GETFL)
|
||||
fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
|
||||
|
||||
while s_in:
|
||||
in_ready, _out_ready, _err_ready = select.select(s_in, [], [])
|
||||
for s in in_ready:
|
||||
buf = s.fd.read(4096)
|
||||
if not buf:
|
||||
s.fd.close()
|
||||
s_in.remove(s)
|
||||
continue
|
||||
|
||||
if not opt.verbose:
|
||||
if s.fd != p.stdout:
|
||||
errbuf += buf
|
||||
continue
|
||||
|
||||
if empty and out:
|
||||
if not cnt == 0:
|
||||
out.nl()
|
||||
|
||||
if mirror:
|
||||
project_header_path = project['name']
|
||||
else:
|
||||
project_header_path = project['relpath']
|
||||
out.project('project %s/', project_header_path)
|
||||
out.nl()
|
||||
out.flush()
|
||||
if errbuf:
|
||||
sys.stderr.write(errbuf)
|
||||
sys.stderr.flush()
|
||||
errbuf = ''
|
||||
empty = False
|
||||
|
||||
s.dest.write(buf)
|
||||
s.dest.flush()
|
||||
|
||||
r = p.wait()
|
||||
return r
|
||||
|
@ -233,7 +233,7 @@ to update the working directory files.
|
||||
sys.exit(1)
|
||||
|
||||
if opt.manifest_branch:
|
||||
m.MetaBranchSwitch(opt.manifest_branch)
|
||||
m.MetaBranchSwitch()
|
||||
|
||||
syncbuf = SyncBuffer(m.config)
|
||||
m.Sync_LocalHalf(syncbuf)
|
||||
|
@ -59,9 +59,13 @@ revision specified in the manifest.
|
||||
for project in all_projects:
|
||||
pm.update()
|
||||
# If the current revision is a specific SHA1 then we can't push back
|
||||
# to it so substitute the manifest default revision instead.
|
||||
# to it; so substitute with dest_branch if defined, or with manifest
|
||||
# default revision instead.
|
||||
if IsId(project.revisionExpr):
|
||||
project.revisionExpr = self.manifest.default.revisionExpr
|
||||
if project.dest_branch:
|
||||
project.revisionExpr = project.dest_branch
|
||||
else:
|
||||
project.revisionExpr = self.manifest.default.revisionExpr
|
||||
if not project.StartBranch(nb):
|
||||
err.append(project)
|
||||
pm.end()
|
||||
|
@ -113,7 +113,7 @@ the following meanings:
|
||||
try:
|
||||
state = project.PrintWorkTreeStatus(output)
|
||||
if state == 'CLEAN':
|
||||
clean_counter.next()
|
||||
next(clean_counter)
|
||||
finally:
|
||||
sem.release()
|
||||
|
||||
@ -141,7 +141,7 @@ the following meanings:
|
||||
for project in all_projects:
|
||||
state = project.PrintWorkTreeStatus()
|
||||
if state == 'CLEAN':
|
||||
counter.next()
|
||||
next(counter)
|
||||
else:
|
||||
sem = _threading.Semaphore(opt.jobs)
|
||||
threads_and_output = []
|
||||
@ -164,7 +164,7 @@ the following meanings:
|
||||
t.join()
|
||||
output.dump(sys.stdout)
|
||||
output.close()
|
||||
if len(all_projects) == counter.next():
|
||||
if len(all_projects) == next(counter):
|
||||
print('nothing to commit (working directory clean)')
|
||||
|
||||
if opt.orphans:
|
||||
|
@ -14,10 +14,10 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import json
|
||||
import netrc
|
||||
from optparse import SUPPRESS_HELP
|
||||
import os
|
||||
import pickle
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
@ -128,6 +128,9 @@ HTTP client or proxy configuration, but the Git binary works.
|
||||
The --fetch-submodules option enables fetching Git submodules
|
||||
of a project from server.
|
||||
|
||||
The -c/--current-branch option can be used to only fetch objects that
|
||||
are on the branch specified by a project's revision.
|
||||
|
||||
SSH Connections
|
||||
---------------
|
||||
|
||||
@ -558,7 +561,10 @@ later is required to fix a server side protocol bug.
|
||||
branch = branch[len(R_HEADS):]
|
||||
|
||||
env = os.environ.copy()
|
||||
if 'TARGET_PRODUCT' in env and 'TARGET_BUILD_VARIANT' in env:
|
||||
if 'SYNC_TARGET' in env:
|
||||
target = env['SYNC_TARGET']
|
||||
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
||||
elif 'TARGET_PRODUCT' in env and 'TARGET_BUILD_VARIANT' in env:
|
||||
target = '%s-%s' % (env['TARGET_PRODUCT'],
|
||||
env['TARGET_BUILD_VARIANT'])
|
||||
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
||||
@ -760,7 +766,7 @@ class _FetchTimes(object):
|
||||
_ALPHA = 0.5
|
||||
|
||||
def __init__(self, manifest):
|
||||
self._path = os.path.join(manifest.repodir, '.repopickle_fetchtimes')
|
||||
self._path = os.path.join(manifest.repodir, '.repo_fetchtimes.json')
|
||||
self._times = None
|
||||
self._seen = set()
|
||||
|
||||
@ -779,22 +785,17 @@ class _FetchTimes(object):
|
||||
def _Load(self):
|
||||
if self._times is None:
|
||||
try:
|
||||
f = open(self._path, 'rb')
|
||||
except IOError:
|
||||
self._times = {}
|
||||
return self._times
|
||||
try:
|
||||
f = open(self._path)
|
||||
try:
|
||||
self._times = pickle.load(f)
|
||||
except IOError:
|
||||
try:
|
||||
os.remove(self._path)
|
||||
except OSError:
|
||||
pass
|
||||
self._times = {}
|
||||
finally:
|
||||
f.close()
|
||||
return self._times
|
||||
self._times = json.load(f)
|
||||
finally:
|
||||
f.close()
|
||||
except (IOError, ValueError):
|
||||
try:
|
||||
os.remove(self._path)
|
||||
except OSError:
|
||||
pass
|
||||
self._times = {}
|
||||
|
||||
def Save(self):
|
||||
if self._times is None:
|
||||
@ -808,13 +809,13 @@ class _FetchTimes(object):
|
||||
del self._times[name]
|
||||
|
||||
try:
|
||||
f = open(self._path, 'wb')
|
||||
f = open(self._path, 'w')
|
||||
try:
|
||||
pickle.dump(self._times, f)
|
||||
except (IOError, OSError, pickle.PickleError):
|
||||
try:
|
||||
os.remove(self._path)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
f.close()
|
||||
json.dump(self._times, f, indent=2)
|
||||
finally:
|
||||
f.close()
|
||||
except (IOError, TypeError):
|
||||
try:
|
||||
os.remove(self._path)
|
||||
except OSError:
|
||||
pass
|
||||
|
@ -25,10 +25,12 @@ from git_command import GitCommand
|
||||
from project import RepoHook
|
||||
|
||||
from pyversion import is_python3
|
||||
# pylint:disable=W0622
|
||||
if not is_python3():
|
||||
# pylint:disable=W0622
|
||||
input = raw_input
|
||||
# pylint:enable=W0622
|
||||
else:
|
||||
unicode = str
|
||||
# pylint:enable=W0622
|
||||
|
||||
UNUSUAL_COMMIT_THRESHOLD = 5
|
||||
|
||||
@ -337,13 +339,17 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
||||
self._AppendAutoList(branch, people)
|
||||
|
||||
# Check if there are local changes that may have been forgotten
|
||||
if branch.project.HasChanges():
|
||||
changes = branch.project.UncommitedFiles()
|
||||
if changes:
|
||||
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) ')
|
||||
sys.stdout.write('Uncommitted changes in ' + branch.project.name)
|
||||
sys.stdout.write(' (did you forget to amend?):\n')
|
||||
sys.stdout.write('\n'.join(changes) + '\n')
|
||||
sys.stdout.write('Continue uploading? (y/N) ')
|
||||
a = sys.stdin.readline().strip().lower()
|
||||
if a not in ('y', 'yes', 't', 'true', 'on'):
|
||||
print("skipping upload", file=sys.stderr)
|
||||
|
Reference in New Issue
Block a user