mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-26 20:17:52 +00:00
Compare commits
168 Commits
Author | SHA1 | Date | |
---|---|---|---|
745b4ad660 | |||
4c5f74e452 | |||
b1ad2190a2 | |||
f231db11a2 | |||
79360640f4 | |||
7b01b2fd01 | |||
aad84232ca | |||
3c03580607 | |||
54527e7e30 | |||
5ea32d1359 | |||
5cc384034d | |||
0375523331 | |||
c32ba1961e | |||
250303b437 | |||
029eaf3bac | |||
ba72d8301e | |||
fee390eea2 | |||
9ff2ece6ab | |||
2487cb7b2c | |||
8ce5041596 | |||
f7a51898d3 | |||
b9a1b73425 | |||
dc2545cad6 | |||
f33929d014 | |||
3010e5ba64 | |||
ba7bc738c1 | |||
f4599a2a3d | |||
022a1d4e6e | |||
41d1baac31 | |||
46496d8761 | |||
7c9263bce0 | |||
dab9e99f0f | |||
c5f15bf7c0 | |||
6d35d676db | |||
0745bb2657 | |||
25857b8988 | |||
bdb5271de3 | |||
884092225d | |||
5d0c3a614e | |||
1efc2b4a01 | |||
2635c0e3b6 | |||
43322283dc | |||
f9b7683a3b | |||
eeab6860f1 | |||
7e59de2bcc | |||
163fdbf2fd | |||
555be54790 | |||
c5cd433daf | |||
2a3e15217a | |||
0369a069ad | |||
abaa7f312f | |||
7cccfb2cf0 | |||
57f43f4944 | |||
17af578d72 | |||
b1a07b8276 | |||
4e16c24981 | |||
b3d6e67196 | |||
503d66d8af | |||
679bac4bf3 | |||
97836cf09f | |||
80e3a37ab5 | |||
bb4a1b5274 | |||
551dfecea9 | |||
6944cdb8d1 | |||
59b417493e | |||
30d13eea86 | |||
727cc3e324 | |||
c5ceeb1625 | |||
db75704bfc | |||
87ea5913f2 | |||
185307d1dd | |||
c116f94261 | |||
7993f3cdda | |||
b1d1fd778d | |||
be4456cf24 | |||
cf738ed4a1 | |||
6cfc68e1e6 | |||
4c426ef1d4 | |||
472ce9f5fa | |||
0184dcc510 | |||
c4b301f988 | |||
31a7be561e | |||
384b3c5948 | |||
35de228f33 | |||
ace097c36e | |||
b155354034 | |||
382582728e | |||
b4d43b9f66 | |||
4ccad7554b | |||
403b64edf4 | |||
a38769cda8 | |||
44859d0267 | |||
6ad6dbefe7 | |||
33fe4e99f9 | |||
4214585073 | |||
b51f07cd06 | |||
04f2f0e186 | |||
cb07ba7e3d | |||
23ff7df6a7 | |||
cc1b1a703d | |||
bdf7ed2301 | |||
9c76f67f13 | |||
52b99aa91d | |||
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 | |||
666d534636 | |||
f2af756425 | |||
4e4d40f7c0 |
@ -61,9 +61,6 @@ disable=R0903,R0912,R0913,R0914,R0915,W0141,C0111,C0103,W0603,W0703,R0911,C0301,
|
||||
# (visual studio) and html
|
||||
output-format=text
|
||||
|
||||
# Include message's id in output
|
||||
include-ids=yes
|
||||
|
||||
# Put messages in a separate file for each module / package specified on the
|
||||
# command line instead of printing them on stdout. Reports (if any) will be
|
||||
# written in a file name "pylint_global.[txt|html]".
|
||||
|
71
color.py
71
color.py
@ -18,41 +18,43 @@ import sys
|
||||
|
||||
import pager
|
||||
|
||||
COLORS = {None :-1,
|
||||
'normal' :-1,
|
||||
'black' : 0,
|
||||
'red' : 1,
|
||||
'green' : 2,
|
||||
'yellow' : 3,
|
||||
'blue' : 4,
|
||||
COLORS = {None: -1,
|
||||
'normal': -1,
|
||||
'black': 0,
|
||||
'red': 1,
|
||||
'green': 2,
|
||||
'yellow': 3,
|
||||
'blue': 4,
|
||||
'magenta': 5,
|
||||
'cyan' : 6,
|
||||
'white' : 7}
|
||||
'cyan': 6,
|
||||
'white': 7}
|
||||
|
||||
ATTRS = {None :-1,
|
||||
'bold' : 1,
|
||||
'dim' : 2,
|
||||
'ul' : 4,
|
||||
'blink' : 5,
|
||||
ATTRS = {None: -1,
|
||||
'bold': 1,
|
||||
'dim': 2,
|
||||
'ul': 4,
|
||||
'blink': 5,
|
||||
'reverse': 7}
|
||||
|
||||
RESET = "\033[m" # pylint: disable=W1401
|
||||
# backslash is not anomalous
|
||||
RESET = "\033[m"
|
||||
|
||||
|
||||
def is_color(s):
|
||||
return s in COLORS
|
||||
|
||||
|
||||
def is_attr(s):
|
||||
return s in ATTRS
|
||||
|
||||
def _Color(fg = None, bg = None, attr = None):
|
||||
|
||||
def _Color(fg=None, bg=None, attr=None):
|
||||
fg = COLORS[fg]
|
||||
bg = COLORS[bg]
|
||||
attr = ATTRS[attr]
|
||||
|
||||
if attr >= 0 or fg >= 0 or bg >= 0:
|
||||
need_sep = False
|
||||
code = "\033[" #pylint: disable=W1401
|
||||
code = "\033["
|
||||
|
||||
if attr >= 0:
|
||||
code += chr(ord('0') + attr)
|
||||
@ -71,7 +73,6 @@ def _Color(fg = None, bg = None, attr = None):
|
||||
if bg >= 0:
|
||||
if need_sep:
|
||||
code += ';'
|
||||
need_sep = True
|
||||
|
||||
if bg < 8:
|
||||
code += '4%c' % (ord('0') + bg)
|
||||
@ -82,6 +83,27 @@ def _Color(fg = None, bg = None, attr = None):
|
||||
code = ''
|
||||
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):
|
||||
@ -89,9 +111,11 @@ class Coloring(object):
|
||||
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):
|
||||
@ -122,6 +146,7 @@ class Coloring(object):
|
||||
def printer(self, opt=None, fg=None, bg=None, attr=None):
|
||||
s = self
|
||||
c = self.colorer(opt, fg, bg, attr)
|
||||
|
||||
def f(fmt, *args):
|
||||
s._out.write(c(fmt, *args))
|
||||
return f
|
||||
@ -129,6 +154,7 @@ class Coloring(object):
|
||||
def nofmt_printer(self, opt=None, fg=None, bg=None, attr=None):
|
||||
s = self
|
||||
c = self.nofmt_colorer(opt, fg, bg, attr)
|
||||
|
||||
def f(fmt):
|
||||
s._out.write(c(fmt))
|
||||
return f
|
||||
@ -136,11 +162,13 @@ class Coloring(object):
|
||||
def colorer(self, opt=None, fg=None, bg=None, attr=None):
|
||||
if self._on:
|
||||
c = self._parse(opt, fg, bg, attr)
|
||||
|
||||
def f(fmt, *args):
|
||||
output = fmt % args
|
||||
return ''.join([c, output, RESET])
|
||||
return f
|
||||
else:
|
||||
|
||||
def f(fmt, *args):
|
||||
return fmt % args
|
||||
return f
|
||||
@ -148,6 +176,7 @@ class Coloring(object):
|
||||
def nofmt_colorer(self, opt=None, fg=None, bg=None, attr=None):
|
||||
if self._on:
|
||||
c = self._parse(opt, fg, bg, attr)
|
||||
|
||||
def f(fmt):
|
||||
return ''.join([c, fmt, RESET])
|
||||
return f
|
||||
|
32
command.py
32
command.py
@ -106,13 +106,13 @@ class Command(object):
|
||||
def _UpdatePathToProjectMap(self, project):
|
||||
self._by_path[project.worktree] = project
|
||||
|
||||
def _GetProjectByPath(self, path):
|
||||
def _GetProjectByPath(self, manifest, path):
|
||||
project = None
|
||||
if os.path.exists(path):
|
||||
oldpath = None
|
||||
while path \
|
||||
and path != oldpath \
|
||||
and path != self.manifest.topdir:
|
||||
and path != manifest.topdir:
|
||||
try:
|
||||
project = self._by_path[path]
|
||||
break
|
||||
@ -126,15 +126,19 @@ class Command(object):
|
||||
pass
|
||||
return project
|
||||
|
||||
def GetProjects(self, args, missing_ok=False, submodules_ok=False):
|
||||
def GetProjects(self, args, manifest=None, groups='', missing_ok=False,
|
||||
submodules_ok=False):
|
||||
"""A list of projects that match the arguments.
|
||||
"""
|
||||
all_projects_list = self.manifest.projects
|
||||
if not manifest:
|
||||
manifest = self.manifest
|
||||
all_projects_list = manifest.projects
|
||||
result = []
|
||||
|
||||
mp = self.manifest.manifestProject
|
||||
mp = manifest.manifestProject
|
||||
|
||||
groups = mp.config.GetString('manifest.groups')
|
||||
if not groups:
|
||||
groups = mp.config.GetString('manifest.groups')
|
||||
if not groups:
|
||||
groups = 'default,platform-' + platform.system().lower()
|
||||
groups = [x for x in re.split(r'[,\s]+', groups) if x]
|
||||
@ -154,11 +158,11 @@ class Command(object):
|
||||
self._ResetPathToProjectMap(all_projects_list)
|
||||
|
||||
for arg in args:
|
||||
projects = self.manifest.GetProjectsWithName(arg)
|
||||
projects = manifest.GetProjectsWithName(arg)
|
||||
|
||||
if not projects:
|
||||
path = os.path.abspath(arg).replace('\\', '/')
|
||||
project = self._GetProjectByPath(path)
|
||||
project = self._GetProjectByPath(manifest, path)
|
||||
|
||||
# If it's not a derived project, update path->project mapping and
|
||||
# search again, as arg might actually point to a derived subproject.
|
||||
@ -169,7 +173,7 @@ class Command(object):
|
||||
self._UpdatePathToProjectMap(subproject)
|
||||
search_again = True
|
||||
if search_again:
|
||||
project = self._GetProjectByPath(path) or project
|
||||
project = self._GetProjectByPath(manifest, path) or project
|
||||
|
||||
if project:
|
||||
projects = [project]
|
||||
@ -226,3 +230,13 @@ class MirrorSafeCommand(object):
|
||||
"""Command permits itself to run within a mirror,
|
||||
and does not require a working directory.
|
||||
"""
|
||||
|
||||
class GitcAvailableCommand(object):
|
||||
"""Command that requires GITC to be available, but does
|
||||
not require the local client to be a GITC client.
|
||||
"""
|
||||
|
||||
class GitcClientCommand(object):
|
||||
"""Command that requires the local client to be a GITC
|
||||
client.
|
||||
"""
|
||||
|
@ -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>
|
||||
@ -48,7 +50,9 @@ following DTD:
|
||||
<!ATTLIST url CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT project (annotation*,
|
||||
project*)>
|
||||
project*,
|
||||
copyfile?,
|
||||
linkfile?)>
|
||||
<!ATTLIST project name CDATA #REQUIRED>
|
||||
<!ATTLIST project path CDATA #IMPLIED>
|
||||
<!ATTLIST project remote IDREF #IMPLIED>
|
||||
@ -66,6 +70,19 @@ following DTD:
|
||||
<!ATTLIST annotation value CDATA #REQUIRED>
|
||||
<!ATTLIST annotation keep CDATA "true">
|
||||
|
||||
<!ELEMENT copyfile (EMPTY)>
|
||||
<!ATTLIST src value CDATA #REQUIRED>
|
||||
<!ATTLIST dest value CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT linkfile (EMPTY)>
|
||||
<!ATTLIST src value CDATA #REQUIRED>
|
||||
<!ATTLIST dest value CDATA #REQUIRED>
|
||||
|
||||
<!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 +129,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 +153,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 +229,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 +248,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 +268,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
|
||||
------------------
|
||||
|
||||
@ -257,6 +295,21 @@ prefixed with REPO__. In addition, there is an optional attribute
|
||||
"false". This attribute determines whether or not the annotation will
|
||||
be kept when exported with the manifest subcommand.
|
||||
|
||||
Element copyfile
|
||||
----------------
|
||||
|
||||
Zero or more copyfile elements may be specified as children of a
|
||||
project element. Each element describes a src-dest pair of files;
|
||||
the "src" file will be copied to the "dest" place during 'repo sync'
|
||||
command.
|
||||
"src" is project relative, "dest" is relative to the top of the tree.
|
||||
|
||||
Element linkfile
|
||||
----------------
|
||||
|
||||
It's just like copyfile and runs at the same time as copyfile but
|
||||
instead of copying it creates a symlink.
|
||||
|
||||
Element remove-project
|
||||
----------------------
|
||||
|
||||
|
4
error.py
4
error.py
@ -80,7 +80,7 @@ class NoSuchProjectError(Exception):
|
||||
self.name = name
|
||||
|
||||
def __str__(self):
|
||||
if self.Name is None:
|
||||
if self.name is None:
|
||||
return 'in current directory'
|
||||
return self.name
|
||||
|
||||
@ -93,7 +93,7 @@ class InvalidProjectGroupsError(Exception):
|
||||
self.name = name
|
||||
|
||||
def __str__(self):
|
||||
if self.Name is None:
|
||||
if self.name is None:
|
||||
return 'in current directory'
|
||||
return self.name
|
||||
|
||||
|
@ -14,7 +14,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import fcntl
|
||||
import os
|
||||
import select
|
||||
import sys
|
||||
import subprocess
|
||||
import tempfile
|
||||
@ -76,17 +78,30 @@ def terminate_ssh_clients():
|
||||
|
||||
_git_version = None
|
||||
|
||||
class _sfd(object):
|
||||
"""select file descriptor class"""
|
||||
def __init__(self, fd, dest, std_name):
|
||||
assert std_name in ('stdout', 'stderr')
|
||||
self.fd = fd
|
||||
self.dest = dest
|
||||
self.std_name = std_name
|
||||
def fileno(self):
|
||||
return self.fd.fileno()
|
||||
|
||||
class _GitCall(object):
|
||||
def version(self):
|
||||
p = GitCommand(None, ['--version'], capture_stdout=True)
|
||||
if p.Wait() == 0:
|
||||
return p.stdout
|
||||
if hasattr(p.stdout, 'decode'):
|
||||
return p.stdout.decode('utf-8')
|
||||
else:
|
||||
return p.stdout
|
||||
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)
|
||||
@ -139,6 +154,9 @@ class GitCommand(object):
|
||||
if key in env:
|
||||
del env[key]
|
||||
|
||||
# If we are not capturing std* then need to print it.
|
||||
self.tee = {'stdout': not capture_stdout, 'stderr': not capture_stderr}
|
||||
|
||||
if disable_editor:
|
||||
_setenv(env, 'GIT_EDITOR', ':')
|
||||
if ssh_proxy:
|
||||
@ -162,22 +180,21 @@ class GitCommand(object):
|
||||
if gitdir:
|
||||
_setenv(env, GIT_DIR, gitdir)
|
||||
cwd = None
|
||||
command.extend(cmdv)
|
||||
command.append(cmdv[0])
|
||||
# Need to use the --progress flag for fetch/clone so output will be
|
||||
# displayed as by default git only does progress output if stderr is a TTY.
|
||||
if sys.stderr.isatty() and cmdv[0] in ('fetch', 'clone'):
|
||||
if '--progress' not in cmdv and '--quiet' not in cmdv:
|
||||
command.append('--progress')
|
||||
command.extend(cmdv[1:])
|
||||
|
||||
if provide_stdin:
|
||||
stdin = subprocess.PIPE
|
||||
else:
|
||||
stdin = None
|
||||
|
||||
if capture_stdout:
|
||||
stdout = subprocess.PIPE
|
||||
else:
|
||||
stdout = None
|
||||
|
||||
if capture_stderr:
|
||||
stderr = subprocess.PIPE
|
||||
else:
|
||||
stderr = None
|
||||
stdout = subprocess.PIPE
|
||||
stderr = subprocess.PIPE
|
||||
|
||||
if IsTrace():
|
||||
global LAST_CWD
|
||||
@ -226,8 +243,36 @@ class GitCommand(object):
|
||||
def Wait(self):
|
||||
try:
|
||||
p = self.process
|
||||
(self.stdout, self.stderr) = p.communicate()
|
||||
rc = p.returncode
|
||||
rc = self._CaptureOutput()
|
||||
finally:
|
||||
_remove_ssh_client(p)
|
||||
return rc
|
||||
|
||||
def _CaptureOutput(self):
|
||||
p = self.process
|
||||
s_in = [_sfd(p.stdout, sys.stdout, 'stdout'),
|
||||
_sfd(p.stderr, sys.stderr, 'stderr')]
|
||||
self.stdout = ''
|
||||
self.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, _, _ = select.select(s_in, [], [])
|
||||
for s in in_ready:
|
||||
buf = s.fd.read(4096)
|
||||
if not buf:
|
||||
s_in.remove(s)
|
||||
continue
|
||||
if not hasattr(buf, 'encode'):
|
||||
buf = buf.decode()
|
||||
if s.std_name == 'stdout':
|
||||
self.stdout += buf
|
||||
else:
|
||||
self.stderr += buf
|
||||
if self.tee[s.std_name]:
|
||||
s.dest.write(buf)
|
||||
s.dest.flush()
|
||||
return p.wait()
|
||||
|
111
git_config.py
111
git_config.py
@ -15,8 +15,10 @@
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import pickle
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
@ -80,7 +82,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 +90,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 +218,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 +249,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):
|
||||
"""
|
||||
@ -512,6 +504,43 @@ def GetSchemeFromUrl(url):
|
||||
return m.group(1)
|
||||
return None
|
||||
|
||||
@contextlib.contextmanager
|
||||
def GetUrlCookieFile(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)
|
||||
try:
|
||||
cookieprefix = 'http.cookiefile='
|
||||
proxyprefix = 'http.proxy='
|
||||
cookiefile = None
|
||||
proxy = None
|
||||
for line in p.stdout:
|
||||
line = line.strip()
|
||||
if line.startswith(cookieprefix):
|
||||
cookiefile = line[len(cookieprefix):]
|
||||
if line.startswith(proxyprefix):
|
||||
proxy = line[len(proxyprefix):]
|
||||
# Leave subprocess open, as cookie file may be transient.
|
||||
if cookiefile or proxy:
|
||||
yield cookiefile, proxy
|
||||
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
|
||||
yield GitConfig.ForUser().GetString('http.cookiefile'), None
|
||||
|
||||
def _preconnect(url):
|
||||
m = URI_ALL.match(url)
|
||||
if m:
|
||||
@ -576,6 +605,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 +658,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 +667,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 +740,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:
|
||||
|
148
gitc_utils.py
Normal file
148
gitc_utils.py
Normal file
@ -0,0 +1,148 @@
|
||||
#
|
||||
# Copyright (C) 2015 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 __future__ import print_function
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
import git_command
|
||||
import git_config
|
||||
import wrapper
|
||||
|
||||
NUM_BATCH_RETRIEVE_REVISIONID = 300
|
||||
|
||||
def get_gitc_manifest_dir():
|
||||
return wrapper.Wrapper().get_gitc_manifest_dir()
|
||||
|
||||
def parse_clientdir(gitc_fs_path):
|
||||
return wrapper.Wrapper().gitc_parse_clientdir(gitc_fs_path)
|
||||
|
||||
def _set_project_revisions(projects):
|
||||
"""Sets the revisionExpr for a list of projects.
|
||||
|
||||
Because of the limit of open file descriptors allowed, length of projects
|
||||
should not be overly large. Recommend calling this function multiple times
|
||||
with each call not exceeding NUM_BATCH_RETRIEVE_REVISIONID projects.
|
||||
|
||||
@param projects: List of project objects to set the revionExpr for.
|
||||
"""
|
||||
# Retrieve the commit id for each project based off of it's current
|
||||
# revisionExpr and it is not already a commit id.
|
||||
project_gitcmds = [(
|
||||
project, git_command.GitCommand(None,
|
||||
['ls-remote',
|
||||
project.remote.url,
|
||||
project.revisionExpr],
|
||||
capture_stdout=True, cwd='/tmp'))
|
||||
for project in projects if not git_config.IsId(project.revisionExpr)]
|
||||
for proj, gitcmd in project_gitcmds:
|
||||
if gitcmd.Wait():
|
||||
print('FATAL: Failed to retrieve revisionExpr for %s' % proj)
|
||||
sys.exit(1)
|
||||
proj.revisionExpr = gitcmd.stdout.split('\t')[0]
|
||||
|
||||
def _manifest_groups(manifest):
|
||||
"""Returns the manifest group string that should be synced
|
||||
|
||||
This is the same logic used by Command.GetProjects(), which is used during
|
||||
repo sync
|
||||
|
||||
@param manifest: The XmlManifest object
|
||||
"""
|
||||
mp = manifest.manifestProject
|
||||
groups = mp.config.GetString('manifest.groups')
|
||||
if not groups:
|
||||
groups = 'default,platform-' + platform.system().lower()
|
||||
return groups
|
||||
|
||||
def generate_gitc_manifest(gitc_manifest, manifest, paths=None):
|
||||
"""Generate a manifest for shafsd to use for this GITC client.
|
||||
|
||||
@param gitc_manifest: Current gitc manifest, or None if there isn't one yet.
|
||||
@param manifest: A GitcManifest object loaded with the current repo manifest.
|
||||
@param paths: List of project paths we want to update.
|
||||
"""
|
||||
|
||||
print('Generating GITC Manifest by fetching revision SHAs for each '
|
||||
'project.')
|
||||
if paths is None:
|
||||
paths = manifest.paths.keys()
|
||||
|
||||
groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x]
|
||||
|
||||
# Convert the paths to projects, and filter them to the matched groups.
|
||||
projects = [manifest.paths[p] for p in paths]
|
||||
projects = [p for p in projects if p.MatchesGroups(groups)]
|
||||
|
||||
if gitc_manifest is not None:
|
||||
for path, proj in manifest.paths.iteritems():
|
||||
if not proj.MatchesGroups(groups):
|
||||
continue
|
||||
|
||||
if not proj.upstream and not git_config.IsId(proj.revisionExpr):
|
||||
proj.upstream = proj.revisionExpr
|
||||
|
||||
if not path in gitc_manifest.paths:
|
||||
# Any new projects need their first revision, even if we weren't asked
|
||||
# for them.
|
||||
projects.append(proj)
|
||||
elif not path in paths:
|
||||
# And copy revisions from the previous manifest if we're not updating
|
||||
# them now.
|
||||
gitc_proj = gitc_manifest.paths[path]
|
||||
if gitc_proj.old_revision:
|
||||
proj.revisionExpr = None
|
||||
proj.old_revision = gitc_proj.old_revision
|
||||
else:
|
||||
proj.revisionExpr = gitc_proj.revisionExpr
|
||||
|
||||
index = 0
|
||||
while index < len(projects):
|
||||
_set_project_revisions(
|
||||
projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)])
|
||||
index += NUM_BATCH_RETRIEVE_REVISIONID
|
||||
|
||||
if gitc_manifest is not None:
|
||||
for path, proj in gitc_manifest.paths.iteritems():
|
||||
if proj.old_revision and path in paths:
|
||||
# If we updated a project that has been started, keep the old-revision
|
||||
# updated.
|
||||
repo_proj = manifest.paths[path]
|
||||
repo_proj.old_revision = repo_proj.revisionExpr
|
||||
repo_proj.revisionExpr = None
|
||||
|
||||
# Convert URLs from relative to absolute.
|
||||
for name, remote in manifest.remotes.iteritems():
|
||||
remote.fetchUrl = remote.resolvedFetchUrl
|
||||
|
||||
# Save the manifest.
|
||||
save_manifest(manifest)
|
||||
|
||||
def save_manifest(manifest, client_dir=None):
|
||||
"""Save the manifest file in the client_dir.
|
||||
|
||||
@param client_dir: Client directory to save the manifest in.
|
||||
@param manifest: Manifest object to save.
|
||||
"""
|
||||
if not client_dir:
|
||||
client_dir = manifest.gitc_client_dir
|
||||
with open(os.path.join(client_dir, '.manifest'), 'w') as f:
|
||||
manifest.Save(f, groups=_manifest_groups(manifest))
|
||||
# TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
|
||||
# Give the GITC filesystem time to register the manifest changes.
|
||||
time.sleep(3)
|
@ -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
|
||||
|
33
main.py
33
main.py
@ -36,20 +36,24 @@ 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
|
||||
from command import InteractiveCommand
|
||||
from command import MirrorSafeCommand
|
||||
from command import GitcAvailableCommand, GitcClientCommand
|
||||
from subcmds.version import Version
|
||||
from editor import Editor
|
||||
from error import DownloadError
|
||||
from error import InvalidProjectGroupsError
|
||||
from error import ManifestInvalidRevisionError
|
||||
from error import ManifestParseError
|
||||
from error import NoManifestException
|
||||
from error import NoSuchProjectError
|
||||
from error import RepoChangedException
|
||||
from manifest_xml import XmlManifest
|
||||
import gitc_utils
|
||||
from manifest_xml import GitcManifest, XmlManifest
|
||||
from pager import RunPager
|
||||
from wrapper import WrapperPath, Wrapper
|
||||
|
||||
@ -69,6 +73,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 +120,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:
|
||||
@ -122,6 +131,12 @@ class _Repo(object):
|
||||
|
||||
cmd.repodir = self.repodir
|
||||
cmd.manifest = XmlManifest(cmd.repodir)
|
||||
cmd.gitc_manifest = None
|
||||
gitc_client_name = gitc_utils.parse_clientdir(os.getcwd())
|
||||
if gitc_client_name:
|
||||
cmd.gitc_manifest = GitcManifest(cmd.repodir, gitc_client_name)
|
||||
cmd.manifest.isGitcClient = True
|
||||
|
||||
Editor.globalConfig = cmd.manifest.globalConfig
|
||||
|
||||
if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
|
||||
@ -129,6 +144,16 @@ class _Repo(object):
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if isinstance(cmd, GitcAvailableCommand) and not gitc_utils.get_gitc_manifest_dir():
|
||||
print("fatal: '%s' requires GITC to be available" % name,
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if isinstance(cmd, GitcClientCommand) and not gitc_client_name:
|
||||
print("fatal: '%s' requires a GITC client" % name,
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
|
||||
try:
|
||||
copts, cargs = cmd.OptionParser.parse_args(argv)
|
||||
copts = cmd.ReadEnvironmentOptions(copts)
|
||||
@ -167,6 +192,12 @@ class _Repo(object):
|
||||
else:
|
||||
print('error: no project in current directory', file=sys.stderr)
|
||||
result = 1
|
||||
except InvalidProjectGroupsError as e:
|
||||
if e.name:
|
||||
print('error: project group must be enabled for project %s' % e.name, file=sys.stderr)
|
||||
else:
|
||||
print('error: project group must be enabled for the project in the current directory', file=sys.stderr)
|
||||
result = 1
|
||||
finally:
|
||||
elapsed = time.time() - start
|
||||
hours, remainder = divmod(elapsed, 3600)
|
||||
|
140
manifest_xml.py
140
manifest_xml.py
@ -29,6 +29,7 @@ else:
|
||||
urllib = imp.new_module('urllib')
|
||||
urllib.parse = urlparse
|
||||
|
||||
import gitc_utils
|
||||
from git_config import GitConfig
|
||||
from git_refs import R_HEADS, HEAD
|
||||
from project import RemoteSpec, Project, MetaProject
|
||||
@ -38,8 +39,9 @@ MANIFEST_FILE_NAME = 'manifest.xml'
|
||||
LOCAL_MANIFEST_NAME = 'local_manifest.xml'
|
||||
LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
|
||||
|
||||
urllib.parse.uses_relative.extend(['ssh', 'git'])
|
||||
urllib.parse.uses_netloc.extend(['ssh', 'git'])
|
||||
# urljoin gets confused if the scheme is not known.
|
||||
urllib.parse.uses_relative.extend(['ssh', 'git', 'persistent-https', 'rpc'])
|
||||
urllib.parse.uses_netloc.extend(['ssh', 'git', 'persistent-https', 'rpc'])
|
||||
|
||||
class _Default(object):
|
||||
"""Project defaults within the manifest."""
|
||||
@ -63,12 +65,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):
|
||||
@ -83,17 +87,14 @@ class _XmlRemote(object):
|
||||
# urljoin will gets confused over quite a few things. The ones we care
|
||||
# about here are:
|
||||
# * no scheme in the base url, like <hostname:port>
|
||||
# * persistent-https://
|
||||
# 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
|
||||
# We handle no scheme by replacing it with an obscure protocol, gopher
|
||||
# and then replacing it with the original when we are done.
|
||||
|
||||
if manifestUrl.find(':') != manifestUrl.find('/') - 1:
|
||||
manifestUrl = 'gopher://' + manifestUrl
|
||||
manifestUrl = re.sub(r'^persistent-https://', 'wais://', manifestUrl)
|
||||
url = urllib.parse.urljoin(manifestUrl, url)
|
||||
url = re.sub(r'^gopher://', '', url)
|
||||
url = re.sub(r'^wais://', 'persistent-https://', url)
|
||||
url = urllib.parse.urljoin('gopher://' + manifestUrl, url)
|
||||
url = re.sub(r'^gopher://', '', url)
|
||||
else:
|
||||
url = urllib.parse.urljoin(manifestUrl, url)
|
||||
return url
|
||||
|
||||
def ToRemoteSpec(self, projectName):
|
||||
@ -112,6 +113,7 @@ class XmlManifest(object):
|
||||
self.manifestFile = os.path.join(self.repodir, MANIFEST_FILE_NAME)
|
||||
self.globalConfig = GitConfig.ForUser()
|
||||
self.localManifestWarning = False
|
||||
self.isGitcClient = False
|
||||
|
||||
self.repoProject = MetaProject(self, 'repo',
|
||||
gitdir = os.path.join(repodir, 'repo/.git'),
|
||||
@ -159,15 +161,21 @@ 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 Save(self, fd, peg_rev=False, peg_rev_upstream=True):
|
||||
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, groups=None):
|
||||
"""Write the current manifest out to the given file descriptor.
|
||||
"""
|
||||
mp = self.manifestProject
|
||||
|
||||
groups = mp.config.GetString('manifest.groups')
|
||||
if groups is None:
|
||||
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')
|
||||
@ -197,6 +205,9 @@ class XmlManifest(object):
|
||||
if d.revisionExpr:
|
||||
have_default = True
|
||||
e.setAttribute('revision', d.revisionExpr)
|
||||
if d.destBranchExpr:
|
||||
have_default = True
|
||||
e.setAttribute('dest-branch', d.destBranchExpr)
|
||||
if d.sync_j > 1:
|
||||
have_default = True
|
||||
e.setAttribute('sync-j', '%d' % d.sync_j)
|
||||
@ -240,20 +251,30 @@ 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')
|
||||
else:
|
||||
value = p.work_git.rev_parse(HEAD + '^0')
|
||||
e.setAttribute('revision', value)
|
||||
if peg_rev_upstream and value != p.revisionExpr:
|
||||
# Only save the origin if the origin is not a sha1, and the default
|
||||
# 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)
|
||||
if peg_rev_upstream:
|
||||
if p.upstream:
|
||||
e.setAttribute('upstream', p.upstream)
|
||||
elif value != p.revisionExpr:
|
||||
# Only save the origin if the origin is not a sha1, and the default
|
||||
# isn't our value
|
||||
e.setAttribute('upstream', 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)
|
||||
|
||||
if p.dest_branch and p.dest_branch != d.destBranchExpr:
|
||||
e.setAttribute('dest-branch', p.dest_branch)
|
||||
|
||||
for c in p.copyfiles:
|
||||
ce = doc.createElement('copyfile')
|
||||
@ -285,6 +306,11 @@ class XmlManifest(object):
|
||||
if p.sync_s:
|
||||
e.setAttribute('sync-s', 'true')
|
||||
|
||||
if p.clone_depth:
|
||||
e.setAttribute('clone-depth', str(p.clone_depth))
|
||||
|
||||
self._output_manifest_project_extras(p, e)
|
||||
|
||||
if p.subprojects:
|
||||
subprojects = set(subp.name for subp in p.subprojects)
|
||||
output_projects(p, e, list(sorted(subprojects)))
|
||||
@ -302,6 +328,10 @@ class XmlManifest(object):
|
||||
|
||||
doc.writexml(fd, '', ' ', '\n', 'UTF-8')
|
||||
|
||||
def _output_manifest_project_extras(self, p, e):
|
||||
"""Manifests can modify e if they support extra project attributes."""
|
||||
pass
|
||||
|
||||
@property
|
||||
def paths(self):
|
||||
self._Load()
|
||||
@ -310,7 +340,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 +528,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 +639,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):
|
||||
"""
|
||||
@ -671,7 +721,7 @@ class XmlManifest(object):
|
||||
def _UnjoinName(self, parent_name, name):
|
||||
return os.path.relpath(name, parent_name)
|
||||
|
||||
def _ParseProject(self, node, parent = None):
|
||||
def _ParseProject(self, node, parent = None, **extra_proj_attrs):
|
||||
"""
|
||||
reads a <project> element from the manifest file
|
||||
"""
|
||||
@ -686,7 +736,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 +785,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)
|
||||
@ -766,7 +816,8 @@ class XmlManifest(object):
|
||||
clone_depth = clone_depth,
|
||||
upstream = upstream,
|
||||
parent = parent,
|
||||
dest_branch = dest_branch)
|
||||
dest_branch = dest_branch,
|
||||
**extra_proj_attrs)
|
||||
|
||||
for n in node.childNodes:
|
||||
if n.nodeName == 'copyfile':
|
||||
@ -872,10 +923,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': []}
|
||||
|
||||
@ -899,3 +948,26 @@ class XmlManifest(object):
|
||||
diff['added'].append(toProjects[proj])
|
||||
|
||||
return diff
|
||||
|
||||
|
||||
class GitcManifest(XmlManifest):
|
||||
|
||||
def __init__(self, repodir, gitc_client_name):
|
||||
"""Initialize the GitcManifest object."""
|
||||
super(GitcManifest, self).__init__(repodir)
|
||||
self.isGitcClient = True
|
||||
self.gitc_client_name = gitc_client_name
|
||||
self.gitc_client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
|
||||
gitc_client_name)
|
||||
self.manifestFile = os.path.join(self.gitc_client_dir, '.manifest')
|
||||
|
||||
def _ParseProject(self, node, parent = None):
|
||||
"""Override _ParseProject and add support for GITC specific attributes."""
|
||||
return super(GitcManifest, self)._ParseProject(
|
||||
node, parent=parent, old_revision=node.getAttribute('old-revision'))
|
||||
|
||||
def _output_manifest_project_extras(self, p, e):
|
||||
"""Output GITC Specific Project attributes"""
|
||||
if p.old_revision:
|
||||
e.setAttribute('old-revision', str(p.old_revision))
|
||||
|
||||
|
760
project.py
760
project.py
File diff suppressed because it is too large
Load Diff
117
repo
117
repo
@ -20,7 +20,7 @@ REPO_REV = 'stable'
|
||||
# limitations under the License.
|
||||
|
||||
# increment this whenever we make important changes to this script
|
||||
VERSION = (1, 21)
|
||||
VERSION = (1, 22)
|
||||
|
||||
# increment this if the MAINTAINER_KEYS block is modified
|
||||
KEYRING_VERSION = (1, 2)
|
||||
@ -108,6 +108,8 @@ S_repo = 'repo' # special repo repository
|
||||
S_manifests = 'manifests' # special manifest repository
|
||||
REPO_MAIN = S_repo + '/main.py' # main script
|
||||
MIN_PYTHON_VERSION = (2, 6) # minimum supported python version
|
||||
GITC_CONFIG_FILE = '/gitc/.config'
|
||||
GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
|
||||
|
||||
|
||||
import errno
|
||||
@ -139,10 +141,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.'
|
||||
@ -216,14 +214,63 @@ group.add_option('--config-name',
|
||||
dest='config_name', action="store_true", default=False,
|
||||
help='Always prompt for name/e-mail')
|
||||
|
||||
def _GitcInitOptions(init_optparse):
|
||||
init_optparse.set_usage("repo gitc-init -u url -c client [options]")
|
||||
g = init_optparse.add_option_group('GITC options')
|
||||
g.add_option('-f', '--manifest-file',
|
||||
dest='manifest_file',
|
||||
help='Optional manifest file to use for this GITC client.')
|
||||
g.add_option('-c', '--gitc-client',
|
||||
dest='gitc_client',
|
||||
help='The name of the gitc_client instance to create or modify.')
|
||||
|
||||
_gitc_manifest_dir = None
|
||||
def get_gitc_manifest_dir():
|
||||
global _gitc_manifest_dir
|
||||
if _gitc_manifest_dir is None:
|
||||
_gitc_manifest_dir = ''
|
||||
try:
|
||||
with open(GITC_CONFIG_FILE, 'r') as gitc_config:
|
||||
for line in gitc_config:
|
||||
match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line)
|
||||
if match:
|
||||
_gitc_manifest_dir = match.group('gitc_manifest_dir')
|
||||
except IOError:
|
||||
pass
|
||||
return _gitc_manifest_dir
|
||||
|
||||
def gitc_parse_clientdir(gitc_fs_path):
|
||||
"""Parse a path in the GITC FS and return its client name.
|
||||
|
||||
@param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR.
|
||||
|
||||
@returns: The GITC client name
|
||||
"""
|
||||
if gitc_fs_path == GITC_FS_ROOT_DIR:
|
||||
return None
|
||||
if not gitc_fs_path.startswith(GITC_FS_ROOT_DIR):
|
||||
manifest_dir = get_gitc_manifest_dir()
|
||||
if manifest_dir == '':
|
||||
return None
|
||||
if manifest_dir[-1] != '/':
|
||||
manifest_dir += '/'
|
||||
if gitc_fs_path == manifest_dir:
|
||||
return None
|
||||
if not gitc_fs_path.startswith(manifest_dir):
|
||||
return None
|
||||
return gitc_fs_path.split(manifest_dir)[1].split('/')[0]
|
||||
return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0]
|
||||
|
||||
class CloneFailure(Exception):
|
||||
"""Indicate the remote clone of repo itself failed.
|
||||
"""
|
||||
|
||||
|
||||
def _Init(args):
|
||||
def _Init(args, gitc_init=False):
|
||||
"""Installs repo by cloning it over the network.
|
||||
"""
|
||||
if gitc_init:
|
||||
_GitcInitOptions(init_optparse)
|
||||
opt, args = init_optparse.parse_args(args)
|
||||
if args:
|
||||
init_optparse.print_usage()
|
||||
@ -246,6 +293,26 @@ def _Init(args):
|
||||
raise CloneFailure()
|
||||
|
||||
try:
|
||||
if gitc_init:
|
||||
gitc_manifest_dir = get_gitc_manifest_dir()
|
||||
if not gitc_manifest_dir:
|
||||
_print('fatal: GITC filesystem is not available. Exiting...',
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
gitc_client = opt.gitc_client
|
||||
if not gitc_client:
|
||||
gitc_client = gitc_parse_clientdir(os.getcwd())
|
||||
if not gitc_client:
|
||||
_print('fatal: GITC client (-c) is required.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
client_dir = os.path.join(gitc_manifest_dir, gitc_client)
|
||||
if not os.path.exists(client_dir):
|
||||
os.makedirs(client_dir)
|
||||
os.chdir(client_dir)
|
||||
if os.path.exists(repodir):
|
||||
# This GITC Client has already initialized repo so continue.
|
||||
return
|
||||
|
||||
os.mkdir(repodir)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
@ -466,7 +533,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)
|
||||
@ -526,8 +593,7 @@ def _Clone(url, local, quiet):
|
||||
'+refs/heads/*:refs/remotes/origin/*')
|
||||
if _DownloadBundle(url, local, quiet):
|
||||
_ImportBundle(local)
|
||||
else:
|
||||
_Fetch(url, local, 'origin', quiet)
|
||||
_Fetch(url, local, 'origin', quiet)
|
||||
|
||||
|
||||
def _Verify(cwd, branch, quiet):
|
||||
@ -644,6 +710,10 @@ def _ParseArguments(args):
|
||||
|
||||
|
||||
def _Usage():
|
||||
gitc_usage = ""
|
||||
if get_gitc_manifest_dir():
|
||||
gitc_usage = " gitc-init Initialize a GITC Client.\n"
|
||||
|
||||
_print(
|
||||
"""usage: repo COMMAND [ARGS]
|
||||
|
||||
@ -652,7 +722,8 @@ repo is not yet installed. Use "repo init" to install it here.
|
||||
The most commonly used repo commands are:
|
||||
|
||||
init Install repo in the current working directory
|
||||
help Display detailed help on a command
|
||||
""" + gitc_usage +
|
||||
""" help Display detailed help on a command
|
||||
|
||||
For access to the full online help, install repo ("repo init").
|
||||
""", file=sys.stderr)
|
||||
@ -664,6 +735,10 @@ def _Help(args):
|
||||
if args[0] == 'init':
|
||||
init_optparse.print_help()
|
||||
sys.exit(0)
|
||||
elif args[0] == 'gitc-init':
|
||||
_GitcInitOptions(init_optparse)
|
||||
init_optparse.print_help()
|
||||
sys.exit(0)
|
||||
else:
|
||||
_print("error: '%s' is not a bootstrap command.\n"
|
||||
' For access to online help, install repo ("repo init").'
|
||||
@ -723,12 +798,22 @@ def _SetDefaultsTo(gitdir):
|
||||
|
||||
|
||||
def main(orig_args):
|
||||
repo_main, rel_repo_dir = _FindRepo()
|
||||
cmd, opt, args = _ParseArguments(orig_args)
|
||||
|
||||
repo_main, rel_repo_dir = None, None
|
||||
# Don't use the local repo copy, make sure to switch to the gitc client first.
|
||||
if cmd != 'gitc-init':
|
||||
repo_main, rel_repo_dir = _FindRepo()
|
||||
|
||||
wrapper_path = os.path.abspath(__file__)
|
||||
my_main, my_git = _RunSelf(wrapper_path)
|
||||
|
||||
cwd = os.getcwd()
|
||||
if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()):
|
||||
_print('error: repo cannot be used in the GITC local manifest directory.'
|
||||
'\nIf you want to work on this GITC client please rerun this '
|
||||
'command from the corresponding client under /gitc/', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if not repo_main:
|
||||
if opt.help:
|
||||
_Usage()
|
||||
@ -736,13 +821,13 @@ def main(orig_args):
|
||||
_Help(args)
|
||||
if not cmd:
|
||||
_NotInstalled()
|
||||
if cmd == 'init':
|
||||
if cmd == 'init' or cmd == 'gitc-init':
|
||||
if my_git:
|
||||
_SetDefaultsTo(my_git)
|
||||
try:
|
||||
_Init(args)
|
||||
_Init(args, gitc_init=(cmd == 'gitc-init'))
|
||||
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 +853,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()
|
||||
|
@ -76,6 +76,7 @@ change id will be added.
|
||||
capture_stdout = True,
|
||||
capture_stderr = True)
|
||||
p.stdin.write(new_msg)
|
||||
p.stdin.close()
|
||||
if p.Wait() != 0:
|
||||
print("error: Failed to update commit message", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
@ -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,10 +14,13 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import errno
|
||||
import fcntl
|
||||
import multiprocessing
|
||||
import re
|
||||
import os
|
||||
import select
|
||||
import signal
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
@ -31,6 +34,7 @@ _CAN_COLOR = [
|
||||
'log',
|
||||
]
|
||||
|
||||
|
||||
class ForallColoring(Coloring):
|
||||
def __init__(self, config):
|
||||
Coloring.__init__(self, config, 'forall')
|
||||
@ -116,6 +120,9 @@ without iterating through the remaining projects.
|
||||
p.add_option('-r', '--regex',
|
||||
dest='regex', action='store_true',
|
||||
help="Execute the command only on projects matching regex or wildcard expression")
|
||||
p.add_option('-g', '--groups',
|
||||
dest='groups',
|
||||
help="Execute the command only on projects matching the specified groups")
|
||||
p.add_option('-c', '--command',
|
||||
help='Command (and arguments) to execute',
|
||||
dest='command',
|
||||
@ -132,9 +139,35 @@ 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.
|
||||
|
||||
"""
|
||||
if not self.manifest.IsMirror:
|
||||
lrev = project.GetRevisionId()
|
||||
else:
|
||||
lrev = None
|
||||
return {
|
||||
'name': project.name,
|
||||
'relpath': project.relpath,
|
||||
'remote_name': project.remote.name,
|
||||
'lrev': lrev,
|
||||
'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,126 +206,188 @@ 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
|
||||
|
||||
smart_sync_manifest_name = "smart_sync_override.xml"
|
||||
smart_sync_manifest_path = os.path.join(
|
||||
self.manifest.manifestProject.worktree, smart_sync_manifest_name)
|
||||
|
||||
if os.path.isfile(smart_sync_manifest_path):
|
||||
self.manifest.Override(smart_sync_manifest_path)
|
||||
|
||||
if not opt.regex:
|
||||
projects = self.GetProjects(args)
|
||||
projects = self.GetProjects(args, groups=opt.groups)
|
||||
else:
|
||||
projects = self.FindProjects(args)
|
||||
|
||||
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, InitWorker)
|
||||
try:
|
||||
config = self.manifest.manifestProject.config
|
||||
results_it = pool.imap(
|
||||
DoWorkWrapper,
|
||||
self.ProjectArgs(projects, mirror, opt, cmd, shell, config))
|
||||
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)
|
||||
|
||||
def ProjectArgs(self, projects, mirror, opt, cmd, shell, config):
|
||||
for cnt, p in enumerate(projects):
|
||||
try:
|
||||
project = self._SerializeProject(p)
|
||||
except Exception as e:
|
||||
print('Project list error: %r' % e,
|
||||
file=sys.stderr)
|
||||
return
|
||||
except KeyboardInterrupt:
|
||||
print('Project list interrupted',
|
||||
file=sys.stderr)
|
||||
return
|
||||
yield [mirror, opt, cmd, shell, cnt, config, project]
|
||||
|
||||
class WorkerKeyboardInterrupt(Exception):
|
||||
""" Keyboard interrupt exception for worker processes. """
|
||||
pass
|
||||
|
||||
|
||||
def InitWorker():
|
||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||
|
||||
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 = ''
|
||||
if hasattr(val, 'encode'):
|
||||
val = val.encode()
|
||||
env[name] = val
|
||||
|
||||
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
|
||||
|
55
subcmds/gitc_delete.py
Normal file
55
subcmds/gitc_delete.py
Normal file
@ -0,0 +1,55 @@
|
||||
#
|
||||
# Copyright (C) 2015 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 __future__ import print_function
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from command import Command, GitcClientCommand
|
||||
import gitc_utils
|
||||
|
||||
from pyversion import is_python3
|
||||
if not is_python3():
|
||||
# pylint:disable=W0622
|
||||
input = raw_input
|
||||
# pylint:enable=W0622
|
||||
|
||||
class GitcDelete(Command, GitcClientCommand):
|
||||
common = True
|
||||
visible_everywhere = False
|
||||
helpSummary = "Delete a GITC Client."
|
||||
helpUsage = """
|
||||
%prog
|
||||
"""
|
||||
helpDescription = """
|
||||
This subcommand deletes the current GITC client, deleting the GITC manifest
|
||||
and all locally downloaded sources.
|
||||
"""
|
||||
|
||||
def _Options(self, p):
|
||||
p.add_option('-f', '--force',
|
||||
dest='force', action='store_true',
|
||||
help='Force the deletion (no prompt).')
|
||||
|
||||
def Execute(self, opt, args):
|
||||
if not opt.force:
|
||||
prompt = ('This will delete GITC client: %s\nAre you sure? (yes/no) ' %
|
||||
self.gitc_manifest.gitc_client_name)
|
||||
response = input(prompt).lower()
|
||||
if not response == 'yes':
|
||||
print('Response was not "yes"\n Exiting...')
|
||||
sys.exit(1)
|
||||
shutil.rmtree(self.gitc_manifest.gitc_client_dir)
|
82
subcmds/gitc_init.py
Normal file
82
subcmds/gitc_init.py
Normal file
@ -0,0 +1,82 @@
|
||||
#
|
||||
# Copyright (C) 2015 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 __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
|
||||
import gitc_utils
|
||||
from command import GitcAvailableCommand
|
||||
from manifest_xml import GitcManifest
|
||||
from subcmds import init
|
||||
import wrapper
|
||||
|
||||
|
||||
class GitcInit(init.Init, GitcAvailableCommand):
|
||||
common = True
|
||||
helpSummary = "Initialize a GITC Client."
|
||||
helpUsage = """
|
||||
%prog [options] [client name]
|
||||
"""
|
||||
helpDescription = """
|
||||
The '%prog' command is ran to initialize a new GITC client for use
|
||||
with the GITC file system.
|
||||
|
||||
This command will setup the client directory, initialize repo, just
|
||||
like repo init does, and then downloads the manifest collection
|
||||
and installs it in the .repo/directory of the GITC client.
|
||||
|
||||
Once this is done, a GITC manifest is generated by pulling the HEAD
|
||||
SHA for each project and generates the properly formatted XML file
|
||||
and installs it as .manifest in the GITC client directory.
|
||||
|
||||
The -c argument is required to specify the GITC client name.
|
||||
|
||||
The optional -f argument can be used to specify the manifest file to
|
||||
use for this GITC client.
|
||||
"""
|
||||
|
||||
def _Options(self, p):
|
||||
super(GitcInit, self)._Options(p)
|
||||
g = p.add_option_group('GITC options')
|
||||
g.add_option('-f', '--manifest-file',
|
||||
dest='manifest_file',
|
||||
help='Optional manifest file to use for this GITC client.')
|
||||
g.add_option('-c', '--gitc-client',
|
||||
dest='gitc_client',
|
||||
help='The name of the gitc_client instance to create or modify.')
|
||||
|
||||
def Execute(self, opt, args):
|
||||
gitc_client = gitc_utils.parse_clientdir(os.getcwd())
|
||||
if not gitc_client or (opt.gitc_client and gitc_client != opt.gitc_client):
|
||||
print('fatal: Please update your repo command. See go/gitc for instructions.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
self.client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
|
||||
gitc_client)
|
||||
super(GitcInit, self).Execute(opt, args)
|
||||
|
||||
manifest_file = self.manifest.manifestFile
|
||||
if opt.manifest_file:
|
||||
if not os.path.exists(opt.manifest_file):
|
||||
print('fatal: Specified manifest file %s does not exist.' %
|
||||
opt.manifest_file)
|
||||
sys.exit(1)
|
||||
manifest_file = opt.manifest_file
|
||||
|
||||
manifest = GitcManifest(self.repodir, gitc_client)
|
||||
manifest.Override(manifest_file)
|
||||
gitc_utils.generate_gitc_manifest(None, manifest)
|
||||
print('Please run `cd %s` to view your GITC client.' %
|
||||
os.path.join(wrapper.Wrapper().GITC_FS_ROOT_DIR, gitc_client))
|
@ -19,7 +19,8 @@ import sys
|
||||
from formatter import AbstractFormatter, DumbWriter
|
||||
|
||||
from color import Coloring
|
||||
from command import PagedCommand, MirrorSafeCommand
|
||||
from command import PagedCommand, MirrorSafeCommand, GitcAvailableCommand, GitcClientCommand
|
||||
import gitc_utils
|
||||
|
||||
class Help(PagedCommand, MirrorSafeCommand):
|
||||
common = False
|
||||
@ -54,9 +55,21 @@ Displays detailed usage information about a command.
|
||||
def _PrintCommonCommands(self):
|
||||
print('usage: repo COMMAND [ARGS]')
|
||||
print('The most commonly used repo commands are:')
|
||||
|
||||
def gitc_supported(cmd):
|
||||
if not isinstance(cmd, GitcAvailableCommand) and not isinstance(cmd, GitcClientCommand):
|
||||
return True
|
||||
if self.manifest.isGitcClient:
|
||||
return True
|
||||
if isinstance(cmd, GitcClientCommand):
|
||||
return False
|
||||
if gitc_utils.get_gitc_manifest_dir():
|
||||
return True
|
||||
return False
|
||||
|
||||
commandNames = list(sorted([name
|
||||
for name, command in self.commands.items()
|
||||
if command.common]))
|
||||
if command.common and gitc_supported(command)]))
|
||||
|
||||
maxlen = 0
|
||||
for name in commandNames:
|
||||
|
@ -59,7 +59,8 @@ class Info(PagedCommand):
|
||||
or 'all,-notdefault')
|
||||
|
||||
self.heading("Manifest branch: ")
|
||||
self.headtext(self.manifest.default.revisionExpr)
|
||||
if self.manifest.default.revisionExpr:
|
||||
self.headtext(self.manifest.default.revisionExpr)
|
||||
self.out.nl()
|
||||
self.heading("Manifest merge branch: ")
|
||||
self.headtext(mergeBranch)
|
||||
|
@ -27,7 +27,7 @@ else:
|
||||
import imp
|
||||
import urlparse
|
||||
urllib = imp.new_module('urllib')
|
||||
urllib.parse = urlparse.urlparse
|
||||
urllib.parse = urlparse
|
||||
|
||||
from color import Coloring
|
||||
from command import InteractiveCommand, MirrorSafeCommand
|
||||
@ -153,7 +153,7 @@ to update the working directory files.
|
||||
# server where this git is located, so let's save that here.
|
||||
mirrored_manifest_git = None
|
||||
if opt.reference:
|
||||
manifest_git_path = urllib.parse(opt.manifest_url).path[1:]
|
||||
manifest_git_path = urllib.parse.urlparse(opt.manifest_url).path[1:]
|
||||
mirrored_manifest_git = os.path.join(opt.reference, manifest_git_path)
|
||||
if not mirrored_manifest_git.endswith(".git"):
|
||||
mirrored_manifest_git += ".git"
|
||||
@ -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)
|
||||
|
@ -35,6 +35,9 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
|
||||
p.add_option('-r', '--regex',
|
||||
dest='regex', action='store_true',
|
||||
help="Filter the project list based on regex or wildcard matching of strings")
|
||||
p.add_option('-g', '--groups',
|
||||
dest='groups',
|
||||
help="Filter the project list based on the groups the project is in")
|
||||
p.add_option('-f', '--fullpath',
|
||||
dest='fullpath', action='store_true',
|
||||
help="Display the full work tree path instead of the relative path")
|
||||
@ -62,7 +65,7 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
|
||||
sys.exit(1)
|
||||
|
||||
if not opt.regex:
|
||||
projects = self.GetProjects(args)
|
||||
projects = self.GetProjects(args, groups=opt.groups)
|
||||
else:
|
||||
projects = self.FindProjects(args)
|
||||
|
||||
|
@ -14,11 +14,15 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
|
||||
from command import Command
|
||||
from git_config import IsId
|
||||
from git_command import git
|
||||
import gitc_utils
|
||||
from progress import Progress
|
||||
from project import SyncBuffer
|
||||
|
||||
class Start(Command):
|
||||
common = True
|
||||
@ -53,16 +57,50 @@ revision specified in the manifest.
|
||||
print("error: at least one project must be specified", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
all_projects = self.GetProjects(projects)
|
||||
if self.gitc_manifest:
|
||||
all_projects = self.GetProjects(projects, manifest=self.gitc_manifest,
|
||||
missing_ok=True)
|
||||
for project in all_projects:
|
||||
if project.old_revision:
|
||||
project.already_synced = True
|
||||
else:
|
||||
project.already_synced = False
|
||||
project.old_revision = project.revisionExpr
|
||||
project.revisionExpr = None
|
||||
# Save the GITC manifest.
|
||||
gitc_utils.save_manifest(self.gitc_manifest)
|
||||
|
||||
all_projects = self.GetProjects(projects,
|
||||
missing_ok=bool(self.gitc_manifest))
|
||||
pm = Progress('Starting %s' % nb, len(all_projects))
|
||||
for project in all_projects:
|
||||
pm.update()
|
||||
|
||||
if self.gitc_manifest:
|
||||
gitc_project = self.gitc_manifest.paths[project.relpath]
|
||||
# Sync projects that have not been opened.
|
||||
if not gitc_project.already_synced:
|
||||
proj_localdir = os.path.join(self.gitc_manifest.gitc_client_dir,
|
||||
project.relpath)
|
||||
project.worktree = proj_localdir
|
||||
if not os.path.exists(proj_localdir):
|
||||
os.makedirs(proj_localdir)
|
||||
project.Sync_NetworkHalf()
|
||||
sync_buf = SyncBuffer(self.manifest.manifestProject.config)
|
||||
project.Sync_LocalHalf(sync_buf)
|
||||
project.revisionId = gitc_project.old_revision
|
||||
|
||||
# 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.
|
||||
branch_merge = ''
|
||||
if IsId(project.revisionExpr):
|
||||
project.revisionExpr = self.manifest.default.revisionExpr
|
||||
if not project.StartBranch(nb):
|
||||
if project.dest_branch:
|
||||
branch_merge = project.dest_branch
|
||||
else:
|
||||
branch_merge = self.manifest.default.revisionExpr
|
||||
|
||||
if not project.StartBranch(nb, branch_merge=branch_merge):
|
||||
err.append(project)
|
||||
pm.end()
|
||||
|
||||
|
@ -22,15 +22,8 @@ except ImportError:
|
||||
|
||||
import glob
|
||||
|
||||
from pyversion import is_python3
|
||||
if is_python3():
|
||||
import io
|
||||
else:
|
||||
import StringIO as io
|
||||
|
||||
import itertools
|
||||
import os
|
||||
import sys
|
||||
|
||||
from color import Coloring
|
||||
|
||||
@ -97,7 +90,7 @@ the following meanings:
|
||||
dest='orphans', action='store_true',
|
||||
help="include objects in working directory outside of repo projects")
|
||||
|
||||
def _StatusHelper(self, project, clean_counter, sem, output):
|
||||
def _StatusHelper(self, project, clean_counter, sem):
|
||||
"""Obtains the status for a specific project.
|
||||
|
||||
Obtains the status for a project, redirecting the output to
|
||||
@ -111,9 +104,9 @@ the following meanings:
|
||||
output: Where to output the status.
|
||||
"""
|
||||
try:
|
||||
state = project.PrintWorkTreeStatus(output)
|
||||
state = project.PrintWorkTreeStatus()
|
||||
if state == 'CLEAN':
|
||||
clean_counter.next()
|
||||
next(clean_counter)
|
||||
finally:
|
||||
sem.release()
|
||||
|
||||
@ -122,16 +115,16 @@ the following meanings:
|
||||
status_header = ' --\t'
|
||||
for item in dirs:
|
||||
if not os.path.isdir(item):
|
||||
outstring.write(''.join([status_header, item]))
|
||||
outstring.append(''.join([status_header, item]))
|
||||
continue
|
||||
if item in proj_dirs:
|
||||
continue
|
||||
if item in proj_dirs_parents:
|
||||
self._FindOrphans(glob.glob('%s/.*' % item) + \
|
||||
glob.glob('%s/*' % item), \
|
||||
self._FindOrphans(glob.glob('%s/.*' % item) +
|
||||
glob.glob('%s/*' % item),
|
||||
proj_dirs, proj_dirs_parents, outstring)
|
||||
continue
|
||||
outstring.write(''.join([status_header, item, '/']))
|
||||
outstring.append(''.join([status_header, item, '/']))
|
||||
|
||||
def Execute(self, opt, args):
|
||||
all_projects = self.GetProjects(args)
|
||||
@ -141,30 +134,21 @@ 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 = []
|
||||
threads = []
|
||||
for project in all_projects:
|
||||
sem.acquire()
|
||||
|
||||
class BufList(io.StringIO):
|
||||
def dump(self, ostream):
|
||||
for entry in self.buflist:
|
||||
ostream.write(entry)
|
||||
|
||||
output = BufList()
|
||||
|
||||
t = _threading.Thread(target=self._StatusHelper,
|
||||
args=(project, counter, sem, output))
|
||||
threads_and_output.append((t, output))
|
||||
args=(project, counter, sem))
|
||||
threads.append(t)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
for (t, output) in threads_and_output:
|
||||
for t in threads:
|
||||
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:
|
||||
@ -188,23 +172,21 @@ the following meanings:
|
||||
try:
|
||||
os.chdir(self.manifest.topdir)
|
||||
|
||||
outstring = io.StringIO()
|
||||
self._FindOrphans(glob.glob('.*') + \
|
||||
glob.glob('*'), \
|
||||
outstring = []
|
||||
self._FindOrphans(glob.glob('.*') +
|
||||
glob.glob('*'),
|
||||
proj_dirs, proj_dirs_parents, outstring)
|
||||
|
||||
if outstring.buflist:
|
||||
if outstring:
|
||||
output = StatusColoring(self.manifest.globalConfig)
|
||||
output.project('Objects not within a project (orphans)')
|
||||
output.nl()
|
||||
for entry in outstring.buflist:
|
||||
for entry in outstring:
|
||||
output.untracked(entry)
|
||||
output.nl()
|
||||
else:
|
||||
print('No orphan files or directories')
|
||||
|
||||
outstring.close()
|
||||
|
||||
finally:
|
||||
# Restore CWD.
|
||||
os.chdir(orig_path)
|
||||
|
271
subcmds/sync.py
271
subcmds/sync.py
@ -14,27 +14,35 @@
|
||||
# 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
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from pyversion import is_python3
|
||||
if is_python3():
|
||||
import http.cookiejar as cookielib
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import xmlrpc.client
|
||||
else:
|
||||
import cookielib
|
||||
import imp
|
||||
import urllib2
|
||||
import urlparse
|
||||
import xmlrpclib
|
||||
urllib = imp.new_module('urllib')
|
||||
urllib.error = urllib2
|
||||
urllib.parse = urlparse
|
||||
urllib.request = urllib2
|
||||
xmlrpc = imp.new_module('xmlrpc')
|
||||
xmlrpc.client = xmlrpclib
|
||||
|
||||
@ -57,7 +65,9 @@ except ImportError:
|
||||
multiprocessing = None
|
||||
|
||||
from git_command import GIT, git_require
|
||||
from git_config import GetUrlCookieFile
|
||||
from git_refs import R_HEADS, HEAD
|
||||
import gitc_utils
|
||||
from project import Project
|
||||
from project import RemoteSpec
|
||||
from command import Command, MirrorSafeCommand
|
||||
@ -65,6 +75,7 @@ from error import RepoChangedException, GitError, ManifestParseError
|
||||
from project import SyncBuffer
|
||||
from progress import Progress
|
||||
from wrapper import Wrapper
|
||||
from manifest_xml import GitcManifest
|
||||
|
||||
_ONE_DAY_S = 24 * 60 * 60
|
||||
|
||||
@ -119,6 +130,11 @@ credentials.
|
||||
The -f/--force-broken option can be used to proceed with syncing
|
||||
other projects if a project sync fails.
|
||||
|
||||
The --force-sync option can be used to overwrite existing git
|
||||
directories if they have previously been linked to a different
|
||||
object direcotry. WARNING: This may cause data to be lost since
|
||||
refs may be removed when overwriting.
|
||||
|
||||
The --no-clone-bundle option disables any attempt to use
|
||||
$URL/clone.bundle to bootstrap a new Git repository from a
|
||||
resumeable bundle file on a content delivery network. This
|
||||
@ -128,6 +144,13 @@ 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.
|
||||
|
||||
The --optimized-fetch option can be used to only fetch projects that
|
||||
are fixed to a sha1 revision if the sha1 revision does not already
|
||||
exist locally.
|
||||
|
||||
SSH Connections
|
||||
---------------
|
||||
|
||||
@ -167,6 +190,11 @@ later is required to fix a server side protocol bug.
|
||||
p.add_option('-f', '--force-broken',
|
||||
dest='force_broken', action='store_true',
|
||||
help="continue sync even if a project fails to sync")
|
||||
p.add_option('--force-sync',
|
||||
dest='force_sync', action='store_true',
|
||||
help="overwrite an existing git directory if it needs to "
|
||||
"point to a different object directory. WARNING: this "
|
||||
"may cause loss of data")
|
||||
p.add_option('-l', '--local-only',
|
||||
dest='local_only', action='store_true',
|
||||
help="only update working tree, don't fetch")
|
||||
@ -203,6 +231,9 @@ later is required to fix a server side protocol bug.
|
||||
p.add_option('--no-tags',
|
||||
dest='no_tags', action='store_true',
|
||||
help="don't fetch tags")
|
||||
p.add_option('--optimized-fetch',
|
||||
dest='optimized_fetch', action='store_true',
|
||||
help='only fetch projects fixed to sha1 if revision does not exist locally')
|
||||
if show_smart:
|
||||
p.add_option('-s', '--smart-sync',
|
||||
dest='smart_sync', action='store_true',
|
||||
@ -271,8 +302,10 @@ later is required to fix a server side protocol bug.
|
||||
success = project.Sync_NetworkHalf(
|
||||
quiet=opt.quiet,
|
||||
current_branch_only=opt.current_branch_only,
|
||||
force_sync=opt.force_sync,
|
||||
clone_bundle=not opt.no_clone_bundle,
|
||||
no_tags=opt.no_tags, archive=self.manifest.IsArchive)
|
||||
no_tags=opt.no_tags, archive=self.manifest.IsArchive,
|
||||
optimized_fetch=opt.optimized_fetch)
|
||||
self._fetch_times.Set(project, time.time() - start)
|
||||
|
||||
# Lock around all the rest of the code, since printing, updating a set
|
||||
@ -292,7 +325,9 @@ later is required to fix a server side protocol bug.
|
||||
pm.update()
|
||||
except _FetchError:
|
||||
err_event.set()
|
||||
except:
|
||||
except Exception as e:
|
||||
print('error: Cannot fetch %s (%s: %s)' \
|
||||
% (project.name, type(e).__name__, str(e)), file=sys.stderr)
|
||||
err_event.set()
|
||||
raise
|
||||
finally:
|
||||
@ -506,6 +541,9 @@ later is required to fix a server side protocol bug.
|
||||
self.manifest.Override(opt.manifest_name)
|
||||
|
||||
manifest_name = opt.manifest_name
|
||||
smart_sync_manifest_name = "smart_sync_override.xml"
|
||||
smart_sync_manifest_path = os.path.join(
|
||||
self.manifest.manifestProject.worktree, smart_sync_manifest_name)
|
||||
|
||||
if opt.smart_sync or opt.smart_tag:
|
||||
if not self.manifest.manifest_server:
|
||||
@ -527,19 +565,18 @@ later is required to fix a server side protocol bug.
|
||||
try:
|
||||
info = netrc.netrc()
|
||||
except IOError:
|
||||
print('.netrc file does not exist or could not be opened',
|
||||
file=sys.stderr)
|
||||
# .netrc file does not exist or could not be opened
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
parse_result = urllib.parse.urlparse(manifest_server)
|
||||
if parse_result.hostname:
|
||||
username, _account, password = \
|
||||
info.authenticators(parse_result.hostname)
|
||||
except TypeError:
|
||||
# TypeError is raised when the given hostname is not present
|
||||
# in the .netrc file.
|
||||
print('No credentials found for %s in .netrc'
|
||||
% parse_result.hostname, file=sys.stderr)
|
||||
auth = info.authenticators(parse_result.hostname)
|
||||
if auth:
|
||||
username, _account, password = auth
|
||||
else:
|
||||
print('No credentials found for %s in .netrc'
|
||||
% parse_result.hostname, file=sys.stderr)
|
||||
except netrc.NetrcParseError as e:
|
||||
print('Error parsing .netrc file: %s' % e, file=sys.stderr)
|
||||
|
||||
@ -548,8 +585,12 @@ later is required to fix a server side protocol bug.
|
||||
(username, password),
|
||||
1)
|
||||
|
||||
transport = PersistentTransport(manifest_server)
|
||||
if manifest_server.startswith('persistent-'):
|
||||
manifest_server = manifest_server[len('persistent-'):]
|
||||
|
||||
try:
|
||||
server = xmlrpc.client.Server(manifest_server)
|
||||
server = xmlrpc.client.Server(manifest_server, transport=transport)
|
||||
if opt.smart_sync:
|
||||
p = self.manifest.manifestProject
|
||||
b = p.GetBranch(p.CurrentBranch)
|
||||
@ -558,7 +599,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)
|
||||
@ -569,17 +613,16 @@ later is required to fix a server side protocol bug.
|
||||
[success, manifest_str] = server.GetManifest(opt.smart_tag)
|
||||
|
||||
if success:
|
||||
manifest_name = "smart_sync_override.xml"
|
||||
manifest_path = os.path.join(self.manifest.manifestProject.worktree,
|
||||
manifest_name)
|
||||
manifest_name = smart_sync_manifest_name
|
||||
try:
|
||||
f = open(manifest_path, 'w')
|
||||
f = open(smart_sync_manifest_path, 'w')
|
||||
try:
|
||||
f.write(manifest_str)
|
||||
finally:
|
||||
f.close()
|
||||
except IOError:
|
||||
print('error: cannot write manifest to %s' % manifest_path,
|
||||
except IOError as e:
|
||||
print('error: cannot write manifest to %s:\n%s'
|
||||
% (smart_sync_manifest_path, e),
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
self._ReloadManifest(manifest_name)
|
||||
@ -596,6 +639,13 @@ later is required to fix a server side protocol bug.
|
||||
% (self.manifest.manifest_server, e.errcode, e.errmsg),
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
else: # Not smart sync or smart tag mode
|
||||
if os.path.isfile(smart_sync_manifest_path):
|
||||
try:
|
||||
os.remove(smart_sync_manifest_path)
|
||||
except OSError as e:
|
||||
print('error: failed to remove existing smart sync override manifest: %s' %
|
||||
e, file=sys.stderr)
|
||||
|
||||
rp = self.manifest.repoProject
|
||||
rp.PreSync()
|
||||
@ -609,7 +659,8 @@ later is required to fix a server side protocol bug.
|
||||
if not opt.local_only:
|
||||
mp.Sync_NetworkHalf(quiet=opt.quiet,
|
||||
current_branch_only=opt.current_branch_only,
|
||||
no_tags=opt.no_tags)
|
||||
no_tags=opt.no_tags,
|
||||
optimized_fetch=opt.optimized_fetch)
|
||||
|
||||
if mp.HasChanges:
|
||||
syncbuf = SyncBuffer(mp.config)
|
||||
@ -619,6 +670,42 @@ later is required to fix a server side protocol bug.
|
||||
self._ReloadManifest(manifest_name)
|
||||
if opt.jobs is None:
|
||||
self.jobs = self.manifest.default.sync_j
|
||||
|
||||
if self.gitc_manifest:
|
||||
gitc_manifest_projects = self.GetProjects(args,
|
||||
missing_ok=True)
|
||||
gitc_projects = []
|
||||
opened_projects = []
|
||||
for project in gitc_manifest_projects:
|
||||
if project.relpath in self.gitc_manifest.paths and \
|
||||
self.gitc_manifest.paths[project.relpath].old_revision:
|
||||
opened_projects.append(project.relpath)
|
||||
else:
|
||||
gitc_projects.append(project.relpath)
|
||||
|
||||
if not args:
|
||||
gitc_projects = None
|
||||
|
||||
if gitc_projects != [] and not opt.local_only:
|
||||
print('Updating GITC client: %s' % self.gitc_manifest.gitc_client_name)
|
||||
manifest = GitcManifest(self.repodir, self.gitc_manifest.gitc_client_name)
|
||||
if manifest_name:
|
||||
manifest.Override(manifest_name)
|
||||
else:
|
||||
manifest.Override(self.manifest.manifestFile)
|
||||
gitc_utils.generate_gitc_manifest(self.gitc_manifest,
|
||||
manifest,
|
||||
gitc_projects)
|
||||
print('GITC client successfully synced.')
|
||||
|
||||
# The opened projects need to be synced as normal, therefore we
|
||||
# generate a new args list to represent the opened projects.
|
||||
# TODO: make this more reliable -- if there's a project name/path overlap,
|
||||
# this may choose the wrong project.
|
||||
args = [os.path.relpath(self.manifest.paths[p].worktree, os.getcwd())
|
||||
for p in opened_projects]
|
||||
if not args:
|
||||
return
|
||||
all_projects = self.GetProjects(args,
|
||||
missing_ok=True,
|
||||
submodules_ok=opt.fetch_submodules)
|
||||
@ -672,7 +759,7 @@ later is required to fix a server side protocol bug.
|
||||
for project in all_projects:
|
||||
pm.update()
|
||||
if project.worktree:
|
||||
project.Sync_LocalHalf(syncbuf)
|
||||
project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
|
||||
pm.end()
|
||||
print(file=sys.stderr)
|
||||
if not syncbuf.Finish():
|
||||
@ -760,7 +847,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 +866,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 +890,110 @@ 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):
|
||||
json.dump(self._times, f, indent=2)
|
||||
finally:
|
||||
f.close()
|
||||
except (IOError, TypeError):
|
||||
try:
|
||||
os.remove(self._path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# This is a replacement for xmlrpc.client.Transport using urllib2
|
||||
# and supporting persistent-http[s]. It cannot change hosts from
|
||||
# request to request like the normal transport, the real url
|
||||
# is passed during initialization.
|
||||
class PersistentTransport(xmlrpc.client.Transport):
|
||||
def __init__(self, orig_host):
|
||||
self.orig_host = orig_host
|
||||
|
||||
def request(self, host, handler, request_body, verbose=False):
|
||||
with GetUrlCookieFile(self.orig_host, not verbose) as (cookiefile, proxy):
|
||||
# Python doesn't understand cookies with the #HttpOnly_ prefix
|
||||
# Since we're only using them for HTTP, copy the file temporarily,
|
||||
# stripping those prefixes away.
|
||||
if cookiefile:
|
||||
tmpcookiefile = tempfile.NamedTemporaryFile()
|
||||
tmpcookiefile.write("# HTTP Cookie File")
|
||||
try:
|
||||
os.remove(self._path)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
f.close()
|
||||
with open(cookiefile) as f:
|
||||
for line in f:
|
||||
if line.startswith("#HttpOnly_"):
|
||||
line = line[len("#HttpOnly_"):]
|
||||
tmpcookiefile.write(line)
|
||||
tmpcookiefile.flush()
|
||||
|
||||
cookiejar = cookielib.MozillaCookieJar(tmpcookiefile.name)
|
||||
try:
|
||||
cookiejar.load()
|
||||
except cookielib.LoadError:
|
||||
cookiejar = cookielib.CookieJar()
|
||||
finally:
|
||||
tmpcookiefile.close()
|
||||
else:
|
||||
cookiejar = cookielib.CookieJar()
|
||||
|
||||
proxyhandler = urllib.request.ProxyHandler
|
||||
if proxy:
|
||||
proxyhandler = urllib.request.ProxyHandler({
|
||||
"http": proxy,
|
||||
"https": proxy })
|
||||
|
||||
opener = urllib.request.build_opener(
|
||||
urllib.request.HTTPCookieProcessor(cookiejar),
|
||||
proxyhandler)
|
||||
|
||||
url = urllib.parse.urljoin(self.orig_host, handler)
|
||||
parse_results = urllib.parse.urlparse(url)
|
||||
|
||||
scheme = parse_results.scheme
|
||||
if scheme == 'persistent-http':
|
||||
scheme = 'http'
|
||||
if scheme == 'persistent-https':
|
||||
# If we're proxying through persistent-https, use http. The
|
||||
# proxy itself will do the https.
|
||||
if proxy:
|
||||
scheme = 'http'
|
||||
else:
|
||||
scheme = 'https'
|
||||
|
||||
# Parse out any authentication information using the base class
|
||||
host, extra_headers, _ = self.get_host_info(parse_results.netloc)
|
||||
|
||||
url = urllib.parse.urlunparse((
|
||||
scheme,
|
||||
host,
|
||||
parse_results.path,
|
||||
parse_results.params,
|
||||
parse_results.query,
|
||||
parse_results.fragment))
|
||||
|
||||
request = urllib.request.Request(url, request_body)
|
||||
if extra_headers is not None:
|
||||
for (name, header) in extra_headers:
|
||||
request.add_header(name, header)
|
||||
request.add_header('Content-Type', 'text/xml')
|
||||
try:
|
||||
response = opener.open(request)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code == 501:
|
||||
# We may have been redirected through a login process
|
||||
# but our POST turned into a GET. Retry.
|
||||
response = opener.open(request)
|
||||
else:
|
||||
raise
|
||||
|
||||
p, u = xmlrpc.client.getparser()
|
||||
while 1:
|
||||
data = response.read(1024)
|
||||
if not data:
|
||||
break
|
||||
p.feed(data)
|
||||
p.close()
|
||||
return u.close()
|
||||
|
||||
def close(self):
|
||||
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)
|
||||
|
1
tests/fixtures/gitc_config
vendored
Normal file
1
tests/fixtures/gitc_config
vendored
Normal file
@ -0,0 +1 @@
|
||||
gitc_dir=/test/usr/local/google/gitc
|
75
tests/test_wrapper.py
Normal file
75
tests/test_wrapper.py
Normal file
@ -0,0 +1,75 @@
|
||||
#
|
||||
# Copyright (C) 2015 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import wrapper
|
||||
|
||||
def fixture(*paths):
|
||||
"""Return a path relative to tests/fixtures.
|
||||
"""
|
||||
return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
|
||||
|
||||
class RepoWrapperUnitTest(unittest.TestCase):
|
||||
"""Tests helper functions in the repo wrapper
|
||||
"""
|
||||
def setUp(self):
|
||||
"""Load the wrapper module every time
|
||||
"""
|
||||
wrapper._wrapper_module = None
|
||||
self.wrapper = wrapper.Wrapper()
|
||||
|
||||
def test_get_gitc_manifest_dir_no_gitc(self):
|
||||
"""
|
||||
Test reading a missing gitc config file
|
||||
"""
|
||||
self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
|
||||
val = self.wrapper.get_gitc_manifest_dir()
|
||||
self.assertEqual(val, '')
|
||||
|
||||
def test_get_gitc_manifest_dir(self):
|
||||
"""
|
||||
Test reading the gitc config file and parsing the directory
|
||||
"""
|
||||
self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
|
||||
val = self.wrapper.get_gitc_manifest_dir()
|
||||
self.assertEqual(val, '/test/usr/local/google/gitc')
|
||||
|
||||
def test_gitc_parse_clientdir_no_gitc(self):
|
||||
"""
|
||||
Test parsing the gitc clientdir without gitc running
|
||||
"""
|
||||
self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
|
||||
|
||||
def test_gitc_parse_clientdir(self):
|
||||
"""
|
||||
Test parsing the gitc clientdir
|
||||
"""
|
||||
self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/'), 'test')
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/extra'), 'test')
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test'), 'test')
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/'), 'test')
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/extra'), 'test')
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/'), None)
|
||||
self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user