mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-30 20:17:08 +00:00
Compare commits
133 Commits
Author | SHA1 | Date | |
---|---|---|---|
97836cf09f | |||
80e3a37ab5 | |||
bb4a1b5274 | |||
551dfecea9 | |||
6944cdb8d1 | |||
59b417493e | |||
30d13eea86 | |||
727cc3e324 | |||
c5ceeb1625 | |||
db75704bfc | |||
87ea5913f2 | |||
185307d1dd | |||
c116f94261 | |||
7993f3cdda | |||
b1d1fd778d | |||
be4456cf24 | |||
cf738ed4a1 | |||
6cfc68e1e6 | |||
4c426ef1d4 | |||
472ce9f5fa | |||
0184dcc510 | |||
c4b301f988 | |||
31a7be561e | |||
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 | |||
544e7b0a97 | |||
e0df232da7 | |||
5a7c3afa73 | |||
9bc422f130 | |||
e81bc030bb | |||
eb5acc9ae9 | |||
26c45a7958 | |||
68425f4da8 | |||
53e902a19b | |||
4e4d40f7c0 | |||
093fdb6587 | |||
2fb6466f79 | |||
724aafb52d | |||
ccd218cd8f | |||
dd6542268a | |||
baca5f7e88 | |||
89ece429fb | |||
565480588d | |||
1829101e28 | |||
1966133f8e | |||
f1027e23b4 | |||
2cd38a0bf8 | |||
1b46cc9b6d | |||
1242e60bdd | |||
2d0f508648 | |||
143d8a7249 |
@ -61,9 +61,6 @@ disable=R0903,R0912,R0913,R0914,R0915,W0141,C0111,C0103,W0603,W0703,R0911,C0301,
|
|||||||
# (visual studio) and html
|
# (visual studio) and html
|
||||||
output-format=text
|
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
|
# 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
|
# command line instead of printing them on stdout. Reports (if any) will be
|
||||||
# written in a file name "pylint_global.[txt|html]".
|
# written in a file name "pylint_global.[txt|html]".
|
||||||
|
71
color.py
71
color.py
@ -18,41 +18,43 @@ import sys
|
|||||||
|
|
||||||
import pager
|
import pager
|
||||||
|
|
||||||
COLORS = {None :-1,
|
COLORS = {None: -1,
|
||||||
'normal' :-1,
|
'normal': -1,
|
||||||
'black' : 0,
|
'black': 0,
|
||||||
'red' : 1,
|
'red': 1,
|
||||||
'green' : 2,
|
'green': 2,
|
||||||
'yellow' : 3,
|
'yellow': 3,
|
||||||
'blue' : 4,
|
'blue': 4,
|
||||||
'magenta': 5,
|
'magenta': 5,
|
||||||
'cyan' : 6,
|
'cyan': 6,
|
||||||
'white' : 7}
|
'white': 7}
|
||||||
|
|
||||||
ATTRS = {None :-1,
|
ATTRS = {None: -1,
|
||||||
'bold' : 1,
|
'bold': 1,
|
||||||
'dim' : 2,
|
'dim': 2,
|
||||||
'ul' : 4,
|
'ul': 4,
|
||||||
'blink' : 5,
|
'blink': 5,
|
||||||
'reverse': 7}
|
'reverse': 7}
|
||||||
|
|
||||||
RESET = "\033[m" # pylint: disable=W1401
|
RESET = "\033[m"
|
||||||
# backslash is not anomalous
|
|
||||||
|
|
||||||
def is_color(s):
|
def is_color(s):
|
||||||
return s in COLORS
|
return s in COLORS
|
||||||
|
|
||||||
|
|
||||||
def is_attr(s):
|
def is_attr(s):
|
||||||
return s in ATTRS
|
return s in ATTRS
|
||||||
|
|
||||||
def _Color(fg = None, bg = None, attr = None):
|
|
||||||
|
def _Color(fg=None, bg=None, attr=None):
|
||||||
fg = COLORS[fg]
|
fg = COLORS[fg]
|
||||||
bg = COLORS[bg]
|
bg = COLORS[bg]
|
||||||
attr = ATTRS[attr]
|
attr = ATTRS[attr]
|
||||||
|
|
||||||
if attr >= 0 or fg >= 0 or bg >= 0:
|
if attr >= 0 or fg >= 0 or bg >= 0:
|
||||||
need_sep = False
|
need_sep = False
|
||||||
code = "\033[" #pylint: disable=W1401
|
code = "\033["
|
||||||
|
|
||||||
if attr >= 0:
|
if attr >= 0:
|
||||||
code += chr(ord('0') + attr)
|
code += chr(ord('0') + attr)
|
||||||
@ -71,7 +73,6 @@ def _Color(fg = None, bg = None, attr = None):
|
|||||||
if bg >= 0:
|
if bg >= 0:
|
||||||
if need_sep:
|
if need_sep:
|
||||||
code += ';'
|
code += ';'
|
||||||
need_sep = True
|
|
||||||
|
|
||||||
if bg < 8:
|
if bg < 8:
|
||||||
code += '4%c' % (ord('0') + bg)
|
code += '4%c' % (ord('0') + bg)
|
||||||
@ -82,6 +83,27 @@ def _Color(fg = None, bg = None, attr = None):
|
|||||||
code = ''
|
code = ''
|
||||||
return 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):
|
class Coloring(object):
|
||||||
def __init__(self, config, section_type):
|
def __init__(self, config, section_type):
|
||||||
@ -89,9 +111,11 @@ class Coloring(object):
|
|||||||
self._config = config
|
self._config = config
|
||||||
self._out = sys.stdout
|
self._out = sys.stdout
|
||||||
|
|
||||||
on = self._config.GetString(self._section)
|
on = DEFAULT
|
||||||
if on is None:
|
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 on == 'auto':
|
||||||
if pager.active or os.isatty(1):
|
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):
|
def printer(self, opt=None, fg=None, bg=None, attr=None):
|
||||||
s = self
|
s = self
|
||||||
c = self.colorer(opt, fg, bg, attr)
|
c = self.colorer(opt, fg, bg, attr)
|
||||||
|
|
||||||
def f(fmt, *args):
|
def f(fmt, *args):
|
||||||
s._out.write(c(fmt, *args))
|
s._out.write(c(fmt, *args))
|
||||||
return f
|
return f
|
||||||
@ -129,6 +154,7 @@ class Coloring(object):
|
|||||||
def nofmt_printer(self, opt=None, fg=None, bg=None, attr=None):
|
def nofmt_printer(self, opt=None, fg=None, bg=None, attr=None):
|
||||||
s = self
|
s = self
|
||||||
c = self.nofmt_colorer(opt, fg, bg, attr)
|
c = self.nofmt_colorer(opt, fg, bg, attr)
|
||||||
|
|
||||||
def f(fmt):
|
def f(fmt):
|
||||||
s._out.write(c(fmt))
|
s._out.write(c(fmt))
|
||||||
return f
|
return f
|
||||||
@ -136,11 +162,13 @@ class Coloring(object):
|
|||||||
def colorer(self, opt=None, fg=None, bg=None, attr=None):
|
def colorer(self, opt=None, fg=None, bg=None, attr=None):
|
||||||
if self._on:
|
if self._on:
|
||||||
c = self._parse(opt, fg, bg, attr)
|
c = self._parse(opt, fg, bg, attr)
|
||||||
|
|
||||||
def f(fmt, *args):
|
def f(fmt, *args):
|
||||||
output = fmt % args
|
output = fmt % args
|
||||||
return ''.join([c, output, RESET])
|
return ''.join([c, output, RESET])
|
||||||
return f
|
return f
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def f(fmt, *args):
|
def f(fmt, *args):
|
||||||
return fmt % args
|
return fmt % args
|
||||||
return f
|
return f
|
||||||
@ -148,6 +176,7 @@ class Coloring(object):
|
|||||||
def nofmt_colorer(self, opt=None, fg=None, bg=None, attr=None):
|
def nofmt_colorer(self, opt=None, fg=None, bg=None, attr=None):
|
||||||
if self._on:
|
if self._on:
|
||||||
c = self._parse(opt, fg, bg, attr)
|
c = self._parse(opt, fg, bg, attr)
|
||||||
|
|
||||||
def f(fmt):
|
def f(fmt):
|
||||||
return ''.join([c, fmt, RESET])
|
return ''.join([c, fmt, RESET])
|
||||||
return f
|
return f
|
||||||
|
@ -26,6 +26,7 @@ following DTD:
|
|||||||
manifest-server?,
|
manifest-server?,
|
||||||
remove-project*,
|
remove-project*,
|
||||||
project*,
|
project*,
|
||||||
|
extend-project*,
|
||||||
repo-hooks?)>
|
repo-hooks?)>
|
||||||
|
|
||||||
<!ELEMENT notice (#PCDATA)>
|
<!ELEMENT notice (#PCDATA)>
|
||||||
@ -35,6 +36,7 @@ following DTD:
|
|||||||
<!ATTLIST remote alias CDATA #IMPLIED>
|
<!ATTLIST remote alias CDATA #IMPLIED>
|
||||||
<!ATTLIST remote fetch CDATA #REQUIRED>
|
<!ATTLIST remote fetch CDATA #REQUIRED>
|
||||||
<!ATTLIST remote review CDATA #IMPLIED>
|
<!ATTLIST remote review CDATA #IMPLIED>
|
||||||
|
<!ATTLIST remote revision CDATA #IMPLIED>
|
||||||
|
|
||||||
<!ELEMENT default (EMPTY)>
|
<!ELEMENT default (EMPTY)>
|
||||||
<!ATTLIST default remote IDREF #IMPLIED>
|
<!ATTLIST default remote IDREF #IMPLIED>
|
||||||
@ -66,6 +68,11 @@ following DTD:
|
|||||||
<!ATTLIST annotation value CDATA #REQUIRED>
|
<!ATTLIST annotation value CDATA #REQUIRED>
|
||||||
<!ATTLIST annotation keep CDATA "true">
|
<!ATTLIST annotation keep CDATA "true">
|
||||||
|
|
||||||
|
<!ELEMENT extend-project>
|
||||||
|
<!ATTLIST extend-project name CDATA #REQUIRED>
|
||||||
|
<!ATTLIST extend-project path CDATA #IMPLIED>
|
||||||
|
<!ATTLIST extend-project groups CDATA #IMPLIED>
|
||||||
|
|
||||||
<!ELEMENT remove-project (EMPTY)>
|
<!ELEMENT remove-project (EMPTY)>
|
||||||
<!ATTLIST remove-project name CDATA #REQUIRED>
|
<!ATTLIST remove-project name CDATA #REQUIRED>
|
||||||
|
|
||||||
@ -112,6 +119,10 @@ Attribute `review`: Hostname of the Gerrit server where reviews
|
|||||||
are uploaded to by `repo upload`. This attribute is optional;
|
are uploaded to by `repo upload`. This attribute is optional;
|
||||||
if not specified then `repo upload` will not function.
|
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
|
Element default
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
@ -132,14 +143,14 @@ Project elements not setting their own `dest-branch` will inherit
|
|||||||
this value. If this value is not set, projects will use `revision`
|
this value. If this value is not set, projects will use `revision`
|
||||||
by default instead.
|
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
|
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.
|
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
|
Element manifest-server
|
||||||
@ -208,7 +219,8 @@ to track for this project. Names can be relative to refs/heads
|
|||||||
(e.g. just "master") or absolute (e.g. "refs/heads/master").
|
(e.g. just "master") or absolute (e.g. "refs/heads/master").
|
||||||
Tags and/or explicit SHA-1s should work in theory, but have not
|
Tags and/or explicit SHA-1s should work in theory, but have not
|
||||||
been extensively tested. If not supplied the revision given by
|
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`).
|
Attribute `dest-branch`: Name of a Git branch (e.g. `master`).
|
||||||
When using `repo upload`, changes will be submitted for code
|
When using `repo upload`, changes will be submitted for code
|
||||||
@ -226,13 +238,13 @@ group "notdefault", it will not be automatically downloaded by repo.
|
|||||||
If the project has a parent element, the `name` and `path` here
|
If the project has a parent element, the `name` and `path` here
|
||||||
are the prefixed ones.
|
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
|
branch (specified in the `revision` attribute) rather than the
|
||||||
whole ref space.
|
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
|
can be found. Used when syncing a revision locked manifest in
|
||||||
-c mode to avoid having to sync the entire ref space.
|
-c mode to avoid having to sync the entire ref space.
|
||||||
|
|
||||||
@ -246,6 +258,22 @@ rather than the `name` attribute. This attribute only applies to the
|
|||||||
local mirrors syncing, it will be ignored when syncing the projects in a
|
local mirrors syncing, it will be ignored when syncing the projects in a
|
||||||
client working directory.
|
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
|
Element annotation
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
11
error.py
11
error.py
@ -24,6 +24,13 @@ class ManifestInvalidRevisionError(Exception):
|
|||||||
class NoManifestException(Exception):
|
class NoManifestException(Exception):
|
||||||
"""The required manifest does not exist.
|
"""The required manifest does not exist.
|
||||||
"""
|
"""
|
||||||
|
def __init__(self, path, reason):
|
||||||
|
super(NoManifestException, self).__init__()
|
||||||
|
self.path = path
|
||||||
|
self.reason = reason
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.reason
|
||||||
|
|
||||||
class EditorError(Exception):
|
class EditorError(Exception):
|
||||||
"""Unspecified error from the user's text editor.
|
"""Unspecified error from the user's text editor.
|
||||||
@ -73,7 +80,7 @@ class NoSuchProjectError(Exception):
|
|||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.Name is None:
|
if self.name is None:
|
||||||
return 'in current directory'
|
return 'in current directory'
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@ -86,7 +93,7 @@ class InvalidProjectGroupsError(Exception):
|
|||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.Name is None:
|
if self.name is None:
|
||||||
return 'in current directory'
|
return 'in current directory'
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import fcntl
|
||||||
import os
|
import os
|
||||||
|
import select
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -76,17 +78,30 @@ def terminate_ssh_clients():
|
|||||||
|
|
||||||
_git_version = None
|
_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):
|
class _GitCall(object):
|
||||||
def version(self):
|
def version(self):
|
||||||
p = GitCommand(None, ['--version'], capture_stdout=True)
|
p = GitCommand(None, ['--version'], capture_stdout=True)
|
||||||
if p.Wait() == 0:
|
if p.Wait() == 0:
|
||||||
return p.stdout
|
if hasattr(p.stdout, 'decode'):
|
||||||
|
return p.stdout.decode('utf-8')
|
||||||
|
else:
|
||||||
|
return p.stdout
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def version_tuple(self):
|
def version_tuple(self):
|
||||||
global _git_version
|
global _git_version
|
||||||
if _git_version is None:
|
if _git_version is None:
|
||||||
ver_str = git.version().decode('utf-8')
|
ver_str = git.version()
|
||||||
_git_version = Wrapper().ParseGitVersion(ver_str)
|
_git_version = Wrapper().ParseGitVersion(ver_str)
|
||||||
if _git_version is None:
|
if _git_version is None:
|
||||||
print('fatal: "%s" unsupported' % ver_str, file=sys.stderr)
|
print('fatal: "%s" unsupported' % ver_str, file=sys.stderr)
|
||||||
@ -139,6 +154,9 @@ class GitCommand(object):
|
|||||||
if key in env:
|
if key in env:
|
||||||
del env[key]
|
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:
|
if disable_editor:
|
||||||
_setenv(env, 'GIT_EDITOR', ':')
|
_setenv(env, 'GIT_EDITOR', ':')
|
||||||
if ssh_proxy:
|
if ssh_proxy:
|
||||||
@ -162,22 +180,21 @@ class GitCommand(object):
|
|||||||
if gitdir:
|
if gitdir:
|
||||||
_setenv(env, GIT_DIR, gitdir)
|
_setenv(env, GIT_DIR, gitdir)
|
||||||
cwd = None
|
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:
|
if provide_stdin:
|
||||||
stdin = subprocess.PIPE
|
stdin = subprocess.PIPE
|
||||||
else:
|
else:
|
||||||
stdin = None
|
stdin = None
|
||||||
|
|
||||||
if capture_stdout:
|
stdout = subprocess.PIPE
|
||||||
stdout = subprocess.PIPE
|
stderr = subprocess.PIPE
|
||||||
else:
|
|
||||||
stdout = None
|
|
||||||
|
|
||||||
if capture_stderr:
|
|
||||||
stderr = subprocess.PIPE
|
|
||||||
else:
|
|
||||||
stderr = None
|
|
||||||
|
|
||||||
if IsTrace():
|
if IsTrace():
|
||||||
global LAST_CWD
|
global LAST_CWD
|
||||||
@ -226,8 +243,36 @@ class GitCommand(object):
|
|||||||
def Wait(self):
|
def Wait(self):
|
||||||
try:
|
try:
|
||||||
p = self.process
|
p = self.process
|
||||||
(self.stdout, self.stderr) = p.communicate()
|
rc = self._CaptureOutput()
|
||||||
rc = p.returncode
|
|
||||||
finally:
|
finally:
|
||||||
_remove_ssh_client(p)
|
_remove_ssh_client(p)
|
||||||
return rc
|
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()
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import pickle
|
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -80,7 +80,7 @@ class GitConfig(object):
|
|||||||
return cls(configfile = os.path.join(gitdir, 'config'),
|
return cls(configfile = os.path.join(gitdir, 'config'),
|
||||||
defaults = defaults)
|
defaults = defaults)
|
||||||
|
|
||||||
def __init__(self, configfile, defaults=None, pickleFile=None):
|
def __init__(self, configfile, defaults=None, jsonFile=None):
|
||||||
self.file = configfile
|
self.file = configfile
|
||||||
self.defaults = defaults
|
self.defaults = defaults
|
||||||
self._cache_dict = None
|
self._cache_dict = None
|
||||||
@ -88,12 +88,11 @@ class GitConfig(object):
|
|||||||
self._remotes = {}
|
self._remotes = {}
|
||||||
self._branches = {}
|
self._branches = {}
|
||||||
|
|
||||||
if pickleFile is None:
|
self._json = jsonFile
|
||||||
self._pickle = os.path.join(
|
if self._json is None:
|
||||||
|
self._json = os.path.join(
|
||||||
os.path.dirname(self.file),
|
os.path.dirname(self.file),
|
||||||
'.repopickle_' + os.path.basename(self.file))
|
'.repo_' + os.path.basename(self.file) + '.json')
|
||||||
else:
|
|
||||||
self._pickle = pickleFile
|
|
||||||
|
|
||||||
def Has(self, name, include_defaults = True):
|
def Has(self, name, include_defaults = True):
|
||||||
"""Return true if this configuration file has the key.
|
"""Return true if this configuration file has the key.
|
||||||
@ -217,9 +216,9 @@ class GitConfig(object):
|
|||||||
"""Resolve any url.*.insteadof references.
|
"""Resolve any url.*.insteadof references.
|
||||||
"""
|
"""
|
||||||
for new_url in self.GetSubSections('url'):
|
for new_url in self.GetSubSections('url'):
|
||||||
old_url = self.GetString('url.%s.insteadof' % new_url)
|
for old_url in self.GetString('url.%s.insteadof' % new_url, True):
|
||||||
if old_url is not None and url.startswith(old_url):
|
if old_url is not None and url.startswith(old_url):
|
||||||
return new_url + url[len(old_url):]
|
return new_url + url[len(old_url):]
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -248,50 +247,41 @@ class GitConfig(object):
|
|||||||
return self._cache_dict
|
return self._cache_dict
|
||||||
|
|
||||||
def _Read(self):
|
def _Read(self):
|
||||||
d = self._ReadPickle()
|
d = self._ReadJson()
|
||||||
if d is None:
|
if d is None:
|
||||||
d = self._ReadGit()
|
d = self._ReadGit()
|
||||||
self._SavePickle(d)
|
self._SaveJson(d)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _ReadPickle(self):
|
def _ReadJson(self):
|
||||||
try:
|
try:
|
||||||
if os.path.getmtime(self._pickle) \
|
if os.path.getmtime(self._json) \
|
||||||
<= os.path.getmtime(self.file):
|
<= os.path.getmtime(self.file):
|
||||||
os.remove(self._pickle)
|
os.remove(self._json)
|
||||||
return None
|
return None
|
||||||
except OSError:
|
except OSError:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
Trace(': unpickle %s', self.file)
|
Trace(': parsing %s', self.file)
|
||||||
fd = open(self._pickle, 'rb')
|
fd = open(self._json)
|
||||||
try:
|
try:
|
||||||
return pickle.load(fd)
|
return json.load(fd)
|
||||||
finally:
|
finally:
|
||||||
fd.close()
|
fd.close()
|
||||||
except EOFError:
|
except (IOError, ValueError):
|
||||||
os.remove(self._pickle)
|
os.remove(self._json)
|
||||||
return None
|
|
||||||
except IOError:
|
|
||||||
os.remove(self._pickle)
|
|
||||||
return None
|
|
||||||
except pickle.PickleError:
|
|
||||||
os.remove(self._pickle)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _SavePickle(self, cache):
|
def _SaveJson(self, cache):
|
||||||
try:
|
try:
|
||||||
fd = open(self._pickle, 'wb')
|
fd = open(self._json, 'w')
|
||||||
try:
|
try:
|
||||||
pickle.dump(cache, fd, pickle.HIGHEST_PROTOCOL)
|
json.dump(cache, fd, indent=2)
|
||||||
finally:
|
finally:
|
||||||
fd.close()
|
fd.close()
|
||||||
except IOError:
|
except (IOError, TypeError):
|
||||||
if os.path.exists(self._pickle):
|
if os.path.exists(self._json):
|
||||||
os.remove(self._pickle)
|
os.remove(self._json)
|
||||||
except pickle.PickleError:
|
|
||||||
if os.path.exists(self._pickle):
|
|
||||||
os.remove(self._pickle)
|
|
||||||
|
|
||||||
def _ReadGit(self):
|
def _ReadGit(self):
|
||||||
"""
|
"""
|
||||||
@ -576,7 +566,9 @@ class Remote(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
u = self.review
|
u = self.review
|
||||||
if not u.startswith('http:') and not u.startswith('https:'):
|
if u.startswith('persistent-'):
|
||||||
|
u = u[len('persistent-'):]
|
||||||
|
if u.split(':')[0] not in ('http', 'https', 'sso'):
|
||||||
u = 'http://%s' % u
|
u = 'http://%s' % u
|
||||||
if u.endswith('/Gerrit'):
|
if u.endswith('/Gerrit'):
|
||||||
u = u[:len(u) - len('/Gerrit')]
|
u = u[:len(u) - len('/Gerrit')]
|
||||||
@ -592,6 +584,9 @@ class Remote(object):
|
|||||||
host, port = os.environ['REPO_HOST_PORT_INFO'].split()
|
host, port = os.environ['REPO_HOST_PORT_INFO'].split()
|
||||||
self._review_url = self._SshReviewUrl(userEmail, host, port)
|
self._review_url = self._SshReviewUrl(userEmail, host, port)
|
||||||
REVIEW_CACHE[u] = self._review_url
|
REVIEW_CACHE[u] = self._review_url
|
||||||
|
elif u.startswith('sso:'):
|
||||||
|
self._review_url = u # Assume it's right
|
||||||
|
REVIEW_CACHE[u] = self._review_url
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
info_url = u + 'ssh_info'
|
info_url = u + 'ssh_info'
|
||||||
@ -601,7 +596,7 @@ class Remote(object):
|
|||||||
# of HTML response back, like maybe a login page.
|
# of HTML response back, like maybe a login page.
|
||||||
#
|
#
|
||||||
# Assume HTTP if SSH is not enabled or ssh_info doesn't look right.
|
# Assume HTTP if SSH is not enabled or ssh_info doesn't look right.
|
||||||
self._review_url = http_url + 'p/'
|
self._review_url = http_url
|
||||||
else:
|
else:
|
||||||
host, port = info.split()
|
host, port = info.split()
|
||||||
self._review_url = self._SshReviewUrl(userEmail, host, port)
|
self._review_url = self._SshReviewUrl(userEmail, host, port)
|
||||||
@ -624,9 +619,7 @@ class Remote(object):
|
|||||||
def ToLocal(self, rev):
|
def ToLocal(self, rev):
|
||||||
"""Convert a remote revision string to something we have locally.
|
"""Convert a remote revision string to something we have locally.
|
||||||
"""
|
"""
|
||||||
if IsId(rev):
|
if self.name == '.' or IsId(rev):
|
||||||
return rev
|
|
||||||
if rev.startswith(R_TAGS):
|
|
||||||
return rev
|
return rev
|
||||||
|
|
||||||
if not rev.startswith('refs/'):
|
if not rev.startswith('refs/'):
|
||||||
@ -635,6 +628,10 @@ class Remote(object):
|
|||||||
for spec in self.fetch:
|
for spec in self.fetch:
|
||||||
if spec.SourceMatches(rev):
|
if spec.SourceMatches(rev):
|
||||||
return spec.MapSource(rev)
|
return spec.MapSource(rev)
|
||||||
|
|
||||||
|
if not rev.startswith(R_HEADS):
|
||||||
|
return rev
|
||||||
|
|
||||||
raise GitError('remote %s does not have %s' % (self.name, rev))
|
raise GitError('remote %s does not have %s' % (self.name, rev))
|
||||||
|
|
||||||
def WritesTo(self, ref):
|
def WritesTo(self, ref):
|
||||||
@ -704,7 +701,7 @@ class Branch(object):
|
|||||||
self._Set('merge', self.merge)
|
self._Set('merge', self.merge)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
fd = open(self._config.file, 'ab')
|
fd = open(self._config.file, 'a')
|
||||||
try:
|
try:
|
||||||
fd.write('[branch "%s"]\n' % self.name)
|
fd.write('[branch "%s"]\n' % self.name)
|
||||||
if self.remote:
|
if self.remote:
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# From Gerrit Code Review 2.6
|
|
||||||
#
|
#
|
||||||
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
|
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
|
||||||
#
|
#
|
||||||
@ -27,7 +26,7 @@ MSG="$1"
|
|||||||
#
|
#
|
||||||
add_ChangeId() {
|
add_ChangeId() {
|
||||||
clean_message=`sed -e '
|
clean_message=`sed -e '
|
||||||
/^diff --git a\/.*/{
|
/^diff --git .*/{
|
||||||
s///
|
s///
|
||||||
q
|
q
|
||||||
}
|
}
|
||||||
@ -39,6 +38,11 @@ add_ChangeId() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "false" = "`git config --bool --get gerrit.createChangeId`"
|
||||||
|
then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# Does Change-Id: already exist? if so, exit (no change).
|
# Does Change-Id: already exist? if so, exit (no change).
|
||||||
if grep -i '^Change-Id:' "$MSG" >/dev/null
|
if grep -i '^Change-Id:' "$MSG" >/dev/null
|
||||||
then
|
then
|
||||||
@ -77,7 +81,7 @@ add_ChangeId() {
|
|||||||
# Skip the line starting with the diff command and everything after it,
|
# 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.
|
# 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.
|
# If more than one line before the diff was empty, strip all but one.
|
||||||
/^diff --git a/ {
|
/^diff --git / {
|
||||||
blankLines = 0
|
blankLines = 0
|
||||||
while (getline) { }
|
while (getline) { }
|
||||||
next
|
next
|
||||||
|
127
main.py
127
main.py
@ -31,6 +31,12 @@ else:
|
|||||||
urllib = imp.new_module('urllib')
|
urllib = imp.new_module('urllib')
|
||||||
urllib.request = urllib2
|
urllib.request = urllib2
|
||||||
|
|
||||||
|
try:
|
||||||
|
import kerberos
|
||||||
|
except ImportError:
|
||||||
|
kerberos = None
|
||||||
|
|
||||||
|
from color import SetDefaultColoring
|
||||||
from trace import SetTrace
|
from trace import SetTrace
|
||||||
from git_command import git, GitCommand
|
from git_command import git, GitCommand
|
||||||
from git_config import init_ssh, close_ssh
|
from git_config import init_ssh, close_ssh
|
||||||
@ -39,6 +45,7 @@ from command import MirrorSafeCommand
|
|||||||
from subcmds.version import Version
|
from subcmds.version import Version
|
||||||
from editor import Editor
|
from editor import Editor
|
||||||
from error import DownloadError
|
from error import DownloadError
|
||||||
|
from error import InvalidProjectGroupsError
|
||||||
from error import ManifestInvalidRevisionError
|
from error import ManifestInvalidRevisionError
|
||||||
from error import ManifestParseError
|
from error import ManifestParseError
|
||||||
from error import NoManifestException
|
from error import NoManifestException
|
||||||
@ -64,6 +71,9 @@ global_options.add_option('-p', '--paginate',
|
|||||||
global_options.add_option('--no-pager',
|
global_options.add_option('--no-pager',
|
||||||
dest='no_pager', action='store_true',
|
dest='no_pager', action='store_true',
|
||||||
help='disable the pager')
|
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',
|
global_options.add_option('--trace',
|
||||||
dest='trace', action='store_true',
|
dest='trace', action='store_true',
|
||||||
help='trace git command execution')
|
help='trace git command execution')
|
||||||
@ -108,6 +118,8 @@ class _Repo(object):
|
|||||||
print('fatal: invalid usage of --version', file=sys.stderr)
|
print('fatal: invalid usage of --version', file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
SetDefaultColoring(gopts.color)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = self.commands[name]
|
cmd = self.commands[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -124,8 +136,15 @@ class _Repo(object):
|
|||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
copts, cargs = cmd.OptionParser.parse_args(argv)
|
try:
|
||||||
copts = cmd.ReadEnvironmentOptions(copts)
|
copts, cargs = cmd.OptionParser.parse_args(argv)
|
||||||
|
copts = cmd.ReadEnvironmentOptions(copts)
|
||||||
|
except NoManifestException as e:
|
||||||
|
print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
|
||||||
|
file=sys.stderr)
|
||||||
|
print('error: manifest missing or unreadable -- please run init',
|
||||||
|
file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
|
if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
|
||||||
config = cmd.manifest.globalConfig
|
config = cmd.manifest.globalConfig
|
||||||
@ -141,15 +160,13 @@ class _Repo(object):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
try:
|
try:
|
||||||
result = cmd.Execute(copts, cargs)
|
result = cmd.Execute(copts, cargs)
|
||||||
except DownloadError as e:
|
except (DownloadError, ManifestInvalidRevisionError,
|
||||||
print('error: %s' % str(e), file=sys.stderr)
|
NoManifestException) as e:
|
||||||
result = 1
|
print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
|
||||||
except ManifestInvalidRevisionError as e:
|
file=sys.stderr)
|
||||||
print('error: %s' % str(e), file=sys.stderr)
|
if isinstance(e, NoManifestException):
|
||||||
result = 1
|
print('error: manifest missing or unreadable -- please run init',
|
||||||
except NoManifestException as e:
|
file=sys.stderr)
|
||||||
print('error: manifest required for this command -- please run init',
|
|
||||||
file=sys.stderr)
|
|
||||||
result = 1
|
result = 1
|
||||||
except NoSuchProjectError as e:
|
except NoSuchProjectError as e:
|
||||||
if e.name:
|
if e.name:
|
||||||
@ -157,6 +174,12 @@ class _Repo(object):
|
|||||||
else:
|
else:
|
||||||
print('error: no project in current directory', file=sys.stderr)
|
print('error: no project in current directory', file=sys.stderr)
|
||||||
result = 1
|
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:
|
finally:
|
||||||
elapsed = time.time() - start
|
elapsed = time.time() - start
|
||||||
hours, remainder = divmod(elapsed, 3600)
|
hours, remainder = divmod(elapsed, 3600)
|
||||||
@ -332,6 +355,86 @@ class _DigestAuthHandler(urllib.request.HTTPDigestAuthHandler):
|
|||||||
self.retried = 0
|
self.retried = 0
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
class _KerberosAuthHandler(urllib.request.BaseHandler):
|
||||||
|
def __init__(self):
|
||||||
|
self.retried = 0
|
||||||
|
self.context = None
|
||||||
|
self.handler_order = urllib.request.BaseHandler.handler_order - 50
|
||||||
|
|
||||||
|
def http_error_401(self, req, fp, code, msg, headers):
|
||||||
|
host = req.get_host()
|
||||||
|
retry = self.http_error_auth_reqed('www-authenticate', host, req, headers)
|
||||||
|
return retry
|
||||||
|
|
||||||
|
def http_error_auth_reqed(self, auth_header, host, req, headers):
|
||||||
|
try:
|
||||||
|
spn = "HTTP@%s" % host
|
||||||
|
authdata = self._negotiate_get_authdata(auth_header, headers)
|
||||||
|
|
||||||
|
if self.retried > 3:
|
||||||
|
raise urllib.request.HTTPError(req.get_full_url(), 401,
|
||||||
|
"Negotiate auth failed", headers, None)
|
||||||
|
else:
|
||||||
|
self.retried += 1
|
||||||
|
|
||||||
|
neghdr = self._negotiate_get_svctk(spn, authdata)
|
||||||
|
if neghdr is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
req.add_unredirected_header('Authorization', neghdr)
|
||||||
|
response = self.parent.open(req)
|
||||||
|
|
||||||
|
srvauth = self._negotiate_get_authdata(auth_header, response.info())
|
||||||
|
if self._validate_response(srvauth):
|
||||||
|
return response
|
||||||
|
except kerberos.GSSError:
|
||||||
|
return None
|
||||||
|
except:
|
||||||
|
self.reset_retry_count()
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
self._clean_context()
|
||||||
|
|
||||||
|
def reset_retry_count(self):
|
||||||
|
self.retried = 0
|
||||||
|
|
||||||
|
def _negotiate_get_authdata(self, auth_header, headers):
|
||||||
|
authhdr = headers.get(auth_header, None)
|
||||||
|
if authhdr is not None:
|
||||||
|
for mech_tuple in authhdr.split(","):
|
||||||
|
mech, __, authdata = mech_tuple.strip().partition(" ")
|
||||||
|
if mech.lower() == "negotiate":
|
||||||
|
return authdata.strip()
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _negotiate_get_svctk(self, spn, authdata):
|
||||||
|
if authdata is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
result, self.context = kerberos.authGSSClientInit(spn)
|
||||||
|
if result < kerberos.AUTH_GSS_COMPLETE:
|
||||||
|
return None
|
||||||
|
|
||||||
|
result = kerberos.authGSSClientStep(self.context, authdata)
|
||||||
|
if result < kerberos.AUTH_GSS_CONTINUE:
|
||||||
|
return None
|
||||||
|
|
||||||
|
response = kerberos.authGSSClientResponse(self.context)
|
||||||
|
return "Negotiate %s" % response
|
||||||
|
|
||||||
|
def _validate_response(self, authdata):
|
||||||
|
if authdata is None:
|
||||||
|
return None
|
||||||
|
result = kerberos.authGSSClientStep(self.context, authdata)
|
||||||
|
if result == kerberos.AUTH_GSS_COMPLETE:
|
||||||
|
return True
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _clean_context(self):
|
||||||
|
if self.context is not None:
|
||||||
|
kerberos.authGSSClientClean(self.context)
|
||||||
|
self.context = None
|
||||||
|
|
||||||
def init_http():
|
def init_http():
|
||||||
handlers = [_UserAgentHandler()]
|
handlers = [_UserAgentHandler()]
|
||||||
|
|
||||||
@ -348,6 +451,8 @@ def init_http():
|
|||||||
pass
|
pass
|
||||||
handlers.append(_BasicAuthHandler(mgr))
|
handlers.append(_BasicAuthHandler(mgr))
|
||||||
handlers.append(_DigestAuthHandler(mgr))
|
handlers.append(_DigestAuthHandler(mgr))
|
||||||
|
if kerberos:
|
||||||
|
handlers.append(_KerberosAuthHandler())
|
||||||
|
|
||||||
if 'http_proxy' in os.environ:
|
if 'http_proxy' in os.environ:
|
||||||
url = os.environ['http_proxy']
|
url = os.environ['http_proxy']
|
||||||
|
142
manifest_xml.py
142
manifest_xml.py
@ -32,14 +32,15 @@ else:
|
|||||||
from git_config import GitConfig
|
from git_config import GitConfig
|
||||||
from git_refs import R_HEADS, HEAD
|
from git_refs import R_HEADS, HEAD
|
||||||
from project import RemoteSpec, Project, MetaProject
|
from project import RemoteSpec, Project, MetaProject
|
||||||
from error import ManifestParseError
|
from error import ManifestParseError, ManifestInvalidRevisionError
|
||||||
|
|
||||||
MANIFEST_FILE_NAME = 'manifest.xml'
|
MANIFEST_FILE_NAME = 'manifest.xml'
|
||||||
LOCAL_MANIFEST_NAME = 'local_manifest.xml'
|
LOCAL_MANIFEST_NAME = 'local_manifest.xml'
|
||||||
LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
|
LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
|
||||||
|
|
||||||
urllib.parse.uses_relative.extend(['ssh', 'git'])
|
# urljoin gets confused if the scheme is not known.
|
||||||
urllib.parse.uses_netloc.extend(['ssh', 'git'])
|
urllib.parse.uses_relative.extend(['ssh', 'git', 'persistent-https', 'rpc'])
|
||||||
|
urllib.parse.uses_netloc.extend(['ssh', 'git', 'persistent-https', 'rpc'])
|
||||||
|
|
||||||
class _Default(object):
|
class _Default(object):
|
||||||
"""Project defaults within the manifest."""
|
"""Project defaults within the manifest."""
|
||||||
@ -63,12 +64,14 @@ class _XmlRemote(object):
|
|||||||
alias=None,
|
alias=None,
|
||||||
fetch=None,
|
fetch=None,
|
||||||
manifestUrl=None,
|
manifestUrl=None,
|
||||||
review=None):
|
review=None,
|
||||||
|
revision=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.fetchUrl = fetch
|
self.fetchUrl = fetch
|
||||||
self.manifestUrl = manifestUrl
|
self.manifestUrl = manifestUrl
|
||||||
self.remoteAlias = alias
|
self.remoteAlias = alias
|
||||||
self.reviewUrl = review
|
self.reviewUrl = review
|
||||||
|
self.revision = revision
|
||||||
self.resolvedFetchUrl = self._resolveFetchUrl()
|
self.resolvedFetchUrl = self._resolveFetchUrl()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
@ -80,18 +83,17 @@ class _XmlRemote(object):
|
|||||||
def _resolveFetchUrl(self):
|
def _resolveFetchUrl(self):
|
||||||
url = self.fetchUrl.rstrip('/')
|
url = self.fetchUrl.rstrip('/')
|
||||||
manifestUrl = self.manifestUrl.rstrip('/')
|
manifestUrl = self.manifestUrl.rstrip('/')
|
||||||
p = manifestUrl.startswith('persistent-http')
|
# urljoin will gets confused over quite a few things. The ones we care
|
||||||
if p:
|
# about here are:
|
||||||
manifestUrl = manifestUrl[len('persistent-'):]
|
# * no scheme in the base url, like <hostname:port>
|
||||||
|
# We handle no scheme by replacing it with an obscure protocol, gopher
|
||||||
|
# and then replacing it with the original when we are done.
|
||||||
|
|
||||||
# urljoin will get confused if there is no scheme in the base url
|
|
||||||
# ie, if manifestUrl is of the form <hostname:port>
|
|
||||||
if manifestUrl.find(':') != manifestUrl.find('/') - 1:
|
if manifestUrl.find(':') != manifestUrl.find('/') - 1:
|
||||||
manifestUrl = 'gopher://' + manifestUrl
|
url = urllib.parse.urljoin('gopher://' + manifestUrl, url)
|
||||||
url = urllib.parse.urljoin(manifestUrl, url)
|
url = re.sub(r'^gopher://', '', url)
|
||||||
url = re.sub(r'^gopher://', '', url)
|
else:
|
||||||
if p:
|
url = urllib.parse.urljoin(manifestUrl, url)
|
||||||
url = 'persistent-' + url
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def ToRemoteSpec(self, projectName):
|
def ToRemoteSpec(self, projectName):
|
||||||
@ -157,6 +159,11 @@ class XmlManifest(object):
|
|||||||
e.setAttribute('alias', r.remoteAlias)
|
e.setAttribute('alias', r.remoteAlias)
|
||||||
if r.reviewUrl is not None:
|
if r.reviewUrl is not None:
|
||||||
e.setAttribute('review', r.reviewUrl)
|
e.setAttribute('review', r.reviewUrl)
|
||||||
|
if r.revision is not None:
|
||||||
|
e.setAttribute('revision', r.revision)
|
||||||
|
|
||||||
|
def _ParseGroups(self, groups):
|
||||||
|
return [x for x in re.split(r'[,\s]+', groups) if x]
|
||||||
|
|
||||||
def Save(self, fd, peg_rev=False, peg_rev_upstream=True):
|
def Save(self, fd, peg_rev=False, peg_rev_upstream=True):
|
||||||
"""Write the current manifest out to the given file descriptor.
|
"""Write the current manifest out to the given file descriptor.
|
||||||
@ -165,7 +172,7 @@ class XmlManifest(object):
|
|||||||
|
|
||||||
groups = mp.config.GetString('manifest.groups')
|
groups = mp.config.GetString('manifest.groups')
|
||||||
if groups:
|
if groups:
|
||||||
groups = [x for x in re.split(r'[,\s]+', groups) if x]
|
groups = self._ParseGroups(groups)
|
||||||
|
|
||||||
doc = xml.dom.minidom.Document()
|
doc = xml.dom.minidom.Document()
|
||||||
root = doc.createElement('manifest')
|
root = doc.createElement('manifest')
|
||||||
@ -238,20 +245,27 @@ class XmlManifest(object):
|
|||||||
if d.remote:
|
if d.remote:
|
||||||
remoteName = d.remote.remoteAlias or d.remote.name
|
remoteName = d.remote.remoteAlias or d.remote.name
|
||||||
if not d.remote or p.remote.name != remoteName:
|
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 peg_rev:
|
||||||
if self.IsMirror:
|
if self.IsMirror:
|
||||||
value = p.bare_git.rev_parse(p.revisionExpr + '^0')
|
value = p.bare_git.rev_parse(p.revisionExpr + '^0')
|
||||||
else:
|
else:
|
||||||
value = p.work_git.rev_parse(HEAD + '^0')
|
value = p.work_git.rev_parse(HEAD + '^0')
|
||||||
e.setAttribute('revision', value)
|
e.setAttribute('revision', value)
|
||||||
if peg_rev_upstream and value != p.revisionExpr:
|
if peg_rev_upstream:
|
||||||
# Only save the origin if the origin is not a sha1, and the default
|
if p.upstream:
|
||||||
# isn't our value, and the if the default doesn't already have that
|
e.setAttribute('upstream', p.upstream)
|
||||||
# covered.
|
elif value != p.revisionExpr:
|
||||||
e.setAttribute('upstream', p.revisionExpr)
|
# Only save the origin if the origin is not a sha1, and the default
|
||||||
elif not d.revisionExpr or p.revisionExpr != d.revisionExpr:
|
# isn't our value
|
||||||
e.setAttribute('revision', p.revisionExpr)
|
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)
|
||||||
|
|
||||||
for c in p.copyfiles:
|
for c in p.copyfiles:
|
||||||
ce = doc.createElement('copyfile')
|
ce = doc.createElement('copyfile')
|
||||||
@ -259,6 +273,12 @@ class XmlManifest(object):
|
|||||||
ce.setAttribute('dest', c.dest)
|
ce.setAttribute('dest', c.dest)
|
||||||
e.appendChild(ce)
|
e.appendChild(ce)
|
||||||
|
|
||||||
|
for l in p.linkfiles:
|
||||||
|
le = doc.createElement('linkfile')
|
||||||
|
le.setAttribute('src', l.src)
|
||||||
|
le.setAttribute('dest', l.dest)
|
||||||
|
e.appendChild(le)
|
||||||
|
|
||||||
default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath]
|
default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath]
|
||||||
egroups = [g for g in p.groups if g not in default_groups]
|
egroups = [g for g in p.groups if g not in default_groups]
|
||||||
if egroups:
|
if egroups:
|
||||||
@ -302,7 +322,7 @@ class XmlManifest(object):
|
|||||||
@property
|
@property
|
||||||
def projects(self):
|
def projects(self):
|
||||||
self._Load()
|
self._Load()
|
||||||
return self._paths.values()
|
return list(self._paths.values())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def remotes(self):
|
def remotes(self):
|
||||||
@ -490,6 +510,23 @@ class XmlManifest(object):
|
|||||||
if node.nodeName == 'project':
|
if node.nodeName == 'project':
|
||||||
project = self._ParseProject(node)
|
project = self._ParseProject(node)
|
||||||
recursively_add_projects(project)
|
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':
|
if node.nodeName == 'repo-hooks':
|
||||||
# Get the name of the project and the (space-separated) list of enabled.
|
# Get the name of the project and the (space-separated) list of enabled.
|
||||||
repo_hooks_project = self._reqatt(node, 'in-project')
|
repo_hooks_project = self._reqatt(node, 'in-project')
|
||||||
@ -566,10 +603,11 @@ class XmlManifest(object):
|
|||||||
gitdir = gitdir,
|
gitdir = gitdir,
|
||||||
objdir = gitdir,
|
objdir = gitdir,
|
||||||
worktree = None,
|
worktree = None,
|
||||||
relpath = None,
|
relpath = name or None,
|
||||||
revisionExpr = m.revisionExpr,
|
revisionExpr = m.revisionExpr,
|
||||||
revisionId = None)
|
revisionId = None)
|
||||||
self._projects[project.name] = [project]
|
self._projects[project.name] = [project]
|
||||||
|
self._paths[project.relpath] = project
|
||||||
|
|
||||||
def _ParseRemote(self, node):
|
def _ParseRemote(self, node):
|
||||||
"""
|
"""
|
||||||
@ -583,8 +621,11 @@ class XmlManifest(object):
|
|||||||
review = node.getAttribute('review')
|
review = node.getAttribute('review')
|
||||||
if review == '':
|
if review == '':
|
||||||
review = None
|
review = None
|
||||||
|
revision = node.getAttribute('revision')
|
||||||
|
if revision == '':
|
||||||
|
revision = None
|
||||||
manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
|
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):
|
def _ParseDefault(self, node):
|
||||||
"""
|
"""
|
||||||
@ -677,7 +718,7 @@ class XmlManifest(object):
|
|||||||
raise ManifestParseError("no remote for project %s within %s" %
|
raise ManifestParseError("no remote for project %s within %s" %
|
||||||
(name, self.manifestFile))
|
(name, self.manifestFile))
|
||||||
|
|
||||||
revisionExpr = node.getAttribute('revision')
|
revisionExpr = node.getAttribute('revision') or remote.revision
|
||||||
if not revisionExpr:
|
if not revisionExpr:
|
||||||
revisionExpr = self._default.revisionExpr
|
revisionExpr = self._default.revisionExpr
|
||||||
if not revisionExpr:
|
if not revisionExpr:
|
||||||
@ -726,7 +767,7 @@ class XmlManifest(object):
|
|||||||
groups = ''
|
groups = ''
|
||||||
if node.hasAttribute('groups'):
|
if node.hasAttribute('groups'):
|
||||||
groups = node.getAttribute('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:
|
if parent is None:
|
||||||
relpath, worktree, gitdir, objdir = self.GetProjectPaths(name, path)
|
relpath, worktree, gitdir, objdir = self.GetProjectPaths(name, path)
|
||||||
@ -762,6 +803,8 @@ class XmlManifest(object):
|
|||||||
for n in node.childNodes:
|
for n in node.childNodes:
|
||||||
if n.nodeName == 'copyfile':
|
if n.nodeName == 'copyfile':
|
||||||
self._ParseCopyFile(project, n)
|
self._ParseCopyFile(project, n)
|
||||||
|
if n.nodeName == 'linkfile':
|
||||||
|
self._ParseLinkFile(project, n)
|
||||||
if n.nodeName == 'annotation':
|
if n.nodeName == 'annotation':
|
||||||
self._ParseAnnotation(project, n)
|
self._ParseAnnotation(project, n)
|
||||||
if n.nodeName == 'project':
|
if n.nodeName == 'project':
|
||||||
@ -811,6 +854,14 @@ class XmlManifest(object):
|
|||||||
# dest is relative to the top of the tree
|
# dest is relative to the top of the tree
|
||||||
project.AddCopyFile(src, dest, os.path.join(self.topdir, dest))
|
project.AddCopyFile(src, dest, os.path.join(self.topdir, dest))
|
||||||
|
|
||||||
|
def _ParseLinkFile(self, project, node):
|
||||||
|
src = self._reqatt(node, 'src')
|
||||||
|
dest = self._reqatt(node, 'dest')
|
||||||
|
if not self.IsMirror:
|
||||||
|
# src is project relative;
|
||||||
|
# dest is relative to the top of the tree
|
||||||
|
project.AddLinkFile(src, dest, os.path.join(self.topdir, dest))
|
||||||
|
|
||||||
def _ParseAnnotation(self, project, node):
|
def _ParseAnnotation(self, project, node):
|
||||||
name = self._reqatt(node, 'name')
|
name = self._reqatt(node, 'name')
|
||||||
value = self._reqatt(node, 'value')
|
value = self._reqatt(node, 'value')
|
||||||
@ -843,3 +894,38 @@ class XmlManifest(object):
|
|||||||
raise ManifestParseError("no %s in <%s> within %s" %
|
raise ManifestParseError("no %s in <%s> within %s" %
|
||||||
(attname, node.nodeName, self.manifestFile))
|
(attname, node.nodeName, self.manifestFile))
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
def projectsDiff(self, manifest):
|
||||||
|
"""return the projects differences between two manifests.
|
||||||
|
|
||||||
|
The diff will be from self to given manifest.
|
||||||
|
|
||||||
|
"""
|
||||||
|
fromProjects = self.paths
|
||||||
|
toProjects = manifest.paths
|
||||||
|
|
||||||
|
fromKeys = sorted(fromProjects.keys())
|
||||||
|
toKeys = sorted(toProjects.keys())
|
||||||
|
|
||||||
|
diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []}
|
||||||
|
|
||||||
|
for proj in fromKeys:
|
||||||
|
if not proj in toKeys:
|
||||||
|
diff['removed'].append(fromProjects[proj])
|
||||||
|
else:
|
||||||
|
fromProj = fromProjects[proj]
|
||||||
|
toProj = toProjects[proj]
|
||||||
|
try:
|
||||||
|
fromRevId = fromProj.GetCommitRevisionId()
|
||||||
|
toRevId = toProj.GetCommitRevisionId()
|
||||||
|
except ManifestInvalidRevisionError:
|
||||||
|
diff['unreachable'].append((fromProj, toProj))
|
||||||
|
else:
|
||||||
|
if fromRevId != toRevId:
|
||||||
|
diff['changed'].append((fromProj, toProj))
|
||||||
|
toKeys.remove(proj)
|
||||||
|
|
||||||
|
for proj in toKeys:
|
||||||
|
diff['added'].append(toProjects[proj])
|
||||||
|
|
||||||
|
return diff
|
||||||
|
658
project.py
658
project.py
File diff suppressed because it is too large
Load Diff
18
repo
18
repo
@ -114,6 +114,7 @@ import errno
|
|||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -138,10 +139,6 @@ def _print(*objects, **kwargs):
|
|||||||
|
|
||||||
# Python version check
|
# Python version check
|
||||||
ver = sys.version_info
|
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:
|
if (ver[0], ver[1]) < MIN_PYTHON_VERSION:
|
||||||
_print('error: Python version %s unsupported.\n'
|
_print('error: Python version %s unsupported.\n'
|
||||||
'Please use Python 2.6 - 2.7 instead.'
|
'Please use Python 2.6 - 2.7 instead.'
|
||||||
@ -465,7 +462,7 @@ def _DownloadBundle(url, local, quiet):
|
|||||||
try:
|
try:
|
||||||
r = urllib.request.urlopen(url)
|
r = urllib.request.urlopen(url)
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
if e.code in [403, 404]:
|
if e.code in [401, 403, 404]:
|
||||||
return False
|
return False
|
||||||
_print('fatal: Cannot get %s' % url, file=sys.stderr)
|
_print('fatal: Cannot get %s' % url, file=sys.stderr)
|
||||||
_print('fatal: HTTP error %s' % e.code, file=sys.stderr)
|
_print('fatal: HTTP error %s' % e.code, file=sys.stderr)
|
||||||
@ -741,12 +738,7 @@ def main(orig_args):
|
|||||||
try:
|
try:
|
||||||
_Init(args)
|
_Init(args)
|
||||||
except CloneFailure:
|
except CloneFailure:
|
||||||
for root, dirs, files in os.walk(repodir, topdown=False):
|
shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True)
|
||||||
for name in files:
|
|
||||||
os.remove(os.path.join(root, name))
|
|
||||||
for name in dirs:
|
|
||||||
os.rmdir(os.path.join(root, name))
|
|
||||||
os.rmdir(repodir)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
repo_main, rel_repo_dir = _FindRepo()
|
repo_main, rel_repo_dir = _FindRepo()
|
||||||
else:
|
else:
|
||||||
@ -772,4 +764,8 @@ def main(orig_args):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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:])
|
main(sys.argv[1:])
|
||||||
|
@ -46,6 +46,10 @@ class BranchInfo(object):
|
|||||||
def IsCurrent(self):
|
def IsCurrent(self):
|
||||||
return self.current > 0
|
return self.current > 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def IsSplitCurrent(self):
|
||||||
|
return self.current != 0 and self.current != len(self.projects)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def IsPublished(self):
|
def IsPublished(self):
|
||||||
return self.published > 0
|
return self.published > 0
|
||||||
@ -139,10 +143,14 @@ is shown, then the branch appears in all projects.
|
|||||||
if in_cnt < project_cnt:
|
if in_cnt < project_cnt:
|
||||||
fmt = out.write
|
fmt = out.write
|
||||||
paths = []
|
paths = []
|
||||||
if in_cnt < project_cnt - in_cnt:
|
non_cur_paths = []
|
||||||
|
if i.IsSplitCurrent or (in_cnt < project_cnt - in_cnt):
|
||||||
in_type = 'in'
|
in_type = 'in'
|
||||||
for b in i.projects:
|
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:
|
else:
|
||||||
fmt = out.notinproject
|
fmt = out.notinproject
|
||||||
in_type = 'not in'
|
in_type = 'not in'
|
||||||
@ -154,13 +162,19 @@ is shown, then the branch appears in all projects.
|
|||||||
paths.append(p.relpath)
|
paths.append(p.relpath)
|
||||||
|
|
||||||
s = ' %s %s' % (in_type, ', '.join(paths))
|
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)
|
fmt(s)
|
||||||
else:
|
else:
|
||||||
fmt(' %s:' % in_type)
|
fmt(' %s:' % in_type)
|
||||||
|
fmt = out.current if i.IsCurrent else out.write
|
||||||
for p in paths:
|
for p in paths:
|
||||||
out.nl()
|
out.nl()
|
||||||
fmt(width*' ' + ' %s' % p)
|
fmt(width*' ' + ' %s' % p)
|
||||||
|
fmt = out.write
|
||||||
|
for p in non_cur_paths:
|
||||||
|
out.nl()
|
||||||
|
fmt(width*' ' + ' %s' % p)
|
||||||
else:
|
else:
|
||||||
out.write(' in all projects')
|
out.write(' in all projects')
|
||||||
out.nl()
|
out.nl()
|
||||||
|
@ -76,6 +76,7 @@ change id will be added.
|
|||||||
capture_stdout = True,
|
capture_stdout = True,
|
||||||
capture_stderr = True)
|
capture_stderr = True)
|
||||||
p.stdin.write(new_msg)
|
p.stdin.write(new_msg)
|
||||||
|
p.stdin.close()
|
||||||
if p.Wait() != 0:
|
if p.Wait() != 0:
|
||||||
print("error: Failed to update commit message", file=sys.stderr)
|
print("error: Failed to update commit message", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
195
subcmds/diffmanifests.py
Normal file
195
subcmds/diffmanifests.py
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2014 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 color import Coloring
|
||||||
|
from command import PagedCommand
|
||||||
|
from manifest_xml import XmlManifest
|
||||||
|
|
||||||
|
class _Coloring(Coloring):
|
||||||
|
def __init__(self, config):
|
||||||
|
Coloring.__init__(self, config, "status")
|
||||||
|
|
||||||
|
class Diffmanifests(PagedCommand):
|
||||||
|
""" A command to see logs in projects represented by manifests
|
||||||
|
|
||||||
|
This is used to see deeper differences between manifests. Where a simple
|
||||||
|
diff would only show a diff of sha1s for example, this command will display
|
||||||
|
the logs of the project between both sha1s, allowing user to see diff at a
|
||||||
|
deeper level.
|
||||||
|
"""
|
||||||
|
|
||||||
|
common = True
|
||||||
|
helpSummary = "Manifest diff utility"
|
||||||
|
helpUsage = """%prog manifest1.xml [manifest2.xml] [options]"""
|
||||||
|
|
||||||
|
helpDescription = """
|
||||||
|
The %prog command shows differences between project revisions of manifest1 and
|
||||||
|
manifest2. if manifest2 is not specified, current manifest.xml will be used
|
||||||
|
instead. Both absolute and relative paths may be used for manifests. Relative
|
||||||
|
paths start from project's ".repo/manifests" folder.
|
||||||
|
|
||||||
|
The --raw option Displays the diff in a way that facilitates parsing, the
|
||||||
|
project pattern will be <status> <path> <revision from> [<revision to>] and the
|
||||||
|
commit pattern will be <status> <onelined log> with status values respectively :
|
||||||
|
|
||||||
|
A = Added project
|
||||||
|
R = Removed project
|
||||||
|
C = Changed project
|
||||||
|
U = Project with unreachable revision(s) (revision(s) not found)
|
||||||
|
|
||||||
|
for project, and
|
||||||
|
|
||||||
|
A = Added commit
|
||||||
|
R = Removed commit
|
||||||
|
|
||||||
|
for a commit.
|
||||||
|
|
||||||
|
Only changed projects may contain commits, and commit status always starts with
|
||||||
|
a space, and are part of last printed project.
|
||||||
|
Unreachable revisions may occur if project is not up to date or if repo has not
|
||||||
|
been initialized with all the groups, in which case some projects won't be
|
||||||
|
synced and their revisions won't be found.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _Options(self, p):
|
||||||
|
p.add_option('--raw',
|
||||||
|
dest='raw', action='store_true',
|
||||||
|
help='Display raw diff.')
|
||||||
|
p.add_option('--no-color',
|
||||||
|
dest='color', action='store_false', default=True,
|
||||||
|
help='does not display the diff in color.')
|
||||||
|
|
||||||
|
def _printRawDiff(self, diff):
|
||||||
|
for project in diff['added']:
|
||||||
|
self.printText("A %s %s" % (project.relpath, project.revisionExpr))
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
for project in diff['removed']:
|
||||||
|
self.printText("R %s %s" % (project.relpath, project.revisionExpr))
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
for project, otherProject in diff['changed']:
|
||||||
|
self.printText("C %s %s %s" % (project.relpath, project.revisionExpr,
|
||||||
|
otherProject.revisionExpr))
|
||||||
|
self.out.nl()
|
||||||
|
self._printLogs(project, otherProject, raw=True, color=False)
|
||||||
|
|
||||||
|
for project, otherProject in diff['unreachable']:
|
||||||
|
self.printText("U %s %s %s" % (project.relpath, project.revisionExpr,
|
||||||
|
otherProject.revisionExpr))
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
def _printDiff(self, diff, color=True):
|
||||||
|
if diff['added']:
|
||||||
|
self.out.nl()
|
||||||
|
self.printText('added projects : \n')
|
||||||
|
self.out.nl()
|
||||||
|
for project in diff['added']:
|
||||||
|
self.printProject('\t%s' % (project.relpath))
|
||||||
|
self.printText(' at revision ')
|
||||||
|
self.printRevision(project.revisionExpr)
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
if diff['removed']:
|
||||||
|
self.out.nl()
|
||||||
|
self.printText('removed projects : \n')
|
||||||
|
self.out.nl()
|
||||||
|
for project in diff['removed']:
|
||||||
|
self.printProject('\t%s' % (project.relpath))
|
||||||
|
self.printText(' at revision ')
|
||||||
|
self.printRevision(project.revisionExpr)
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
if diff['changed']:
|
||||||
|
self.out.nl()
|
||||||
|
self.printText('changed projects : \n')
|
||||||
|
self.out.nl()
|
||||||
|
for project, otherProject in diff['changed']:
|
||||||
|
self.printProject('\t%s' % (project.relpath))
|
||||||
|
self.printText(' changed from ')
|
||||||
|
self.printRevision(project.revisionExpr)
|
||||||
|
self.printText(' to ')
|
||||||
|
self.printRevision(otherProject.revisionExpr)
|
||||||
|
self.out.nl()
|
||||||
|
self._printLogs(project, otherProject, raw=False, color=color)
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
if diff['unreachable']:
|
||||||
|
self.out.nl()
|
||||||
|
self.printText('projects with unreachable revisions : \n')
|
||||||
|
self.out.nl()
|
||||||
|
for project, otherProject in diff['unreachable']:
|
||||||
|
self.printProject('\t%s ' % (project.relpath))
|
||||||
|
self.printRevision(project.revisionExpr)
|
||||||
|
self.printText(' or ')
|
||||||
|
self.printRevision(otherProject.revisionExpr)
|
||||||
|
self.printText(' not found')
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
def _printLogs(self, project, otherProject, raw=False, color=True):
|
||||||
|
logs = project.getAddedAndRemovedLogs(otherProject, oneline=True,
|
||||||
|
color=color)
|
||||||
|
if logs['removed']:
|
||||||
|
removedLogs = logs['removed'].split('\n')
|
||||||
|
for log in removedLogs:
|
||||||
|
if log.strip():
|
||||||
|
if raw:
|
||||||
|
self.printText(' R ' + log)
|
||||||
|
self.out.nl()
|
||||||
|
else:
|
||||||
|
self.printRemoved('\t\t[-] ')
|
||||||
|
self.printText(log)
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
if logs['added']:
|
||||||
|
addedLogs = logs['added'].split('\n')
|
||||||
|
for log in addedLogs:
|
||||||
|
if log.strip():
|
||||||
|
if raw:
|
||||||
|
self.printText(' A ' + log)
|
||||||
|
self.out.nl()
|
||||||
|
else:
|
||||||
|
self.printAdded('\t\t[+] ')
|
||||||
|
self.printText(log)
|
||||||
|
self.out.nl()
|
||||||
|
|
||||||
|
def Execute(self, opt, args):
|
||||||
|
if not args or len(args) > 2:
|
||||||
|
self.Usage()
|
||||||
|
|
||||||
|
self.out = _Coloring(self.manifest.globalConfig)
|
||||||
|
self.printText = self.out.nofmt_printer('text')
|
||||||
|
if opt.color:
|
||||||
|
self.printProject = self.out.nofmt_printer('project', attr = 'bold')
|
||||||
|
self.printAdded = self.out.nofmt_printer('green', fg = 'green', attr = 'bold')
|
||||||
|
self.printRemoved = self.out.nofmt_printer('red', fg = 'red', attr = 'bold')
|
||||||
|
self.printRevision = self.out.nofmt_printer('revision', fg = 'yellow')
|
||||||
|
else:
|
||||||
|
self.printProject = self.printAdded = self.printRemoved = self.printRevision = self.printText
|
||||||
|
|
||||||
|
manifest1 = XmlManifest(self.manifest.repodir)
|
||||||
|
manifest1.Override(args[0])
|
||||||
|
if len(args) == 1:
|
||||||
|
manifest2 = self.manifest
|
||||||
|
else:
|
||||||
|
manifest2 = XmlManifest(self.manifest.repodir)
|
||||||
|
manifest2.Override(args[1])
|
||||||
|
|
||||||
|
diff = manifest1.projectsDiff(manifest2)
|
||||||
|
if opt.raw:
|
||||||
|
self._printRawDiff(diff)
|
||||||
|
else:
|
||||||
|
self._printDiff(diff, color=opt.color)
|
@ -18,6 +18,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from command import Command
|
from command import Command
|
||||||
|
from error import GitError
|
||||||
|
|
||||||
CHANGE_RE = re.compile(r'^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$')
|
CHANGE_RE = re.compile(r'^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$')
|
||||||
|
|
||||||
@ -87,7 +88,13 @@ makes it available in your project's local working directory.
|
|||||||
for c in dl.commits:
|
for c in dl.commits:
|
||||||
print(' %s' % (c), file=sys.stderr)
|
print(' %s' % (c), file=sys.stderr)
|
||||||
if opt.cherrypick:
|
if opt.cherrypick:
|
||||||
project._CherryPick(dl.commit)
|
try:
|
||||||
|
project._CherryPick(dl.commit)
|
||||||
|
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:
|
elif opt.revert:
|
||||||
project._Revert(dl.commit)
|
project._Revert(dl.commit)
|
||||||
elif opt.ffonly:
|
elif opt.ffonly:
|
||||||
|
@ -14,10 +14,13 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import errno
|
||||||
import fcntl
|
import fcntl
|
||||||
|
import multiprocessing
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import select
|
import select
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -31,6 +34,7 @@ _CAN_COLOR = [
|
|||||||
'log',
|
'log',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ForallColoring(Coloring):
|
class ForallColoring(Coloring):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
Coloring.__init__(self, config, 'forall')
|
Coloring.__init__(self, config, 'forall')
|
||||||
@ -87,6 +91,12 @@ revision to a locally executed git command, use REPO_LREV.
|
|||||||
REPO_RREV is the name of the revision from the manifest, exactly
|
REPO_RREV is the name of the revision from the manifest, exactly
|
||||||
as written in the manifest.
|
as written in the manifest.
|
||||||
|
|
||||||
|
REPO_COUNT is the total number of projects being iterated.
|
||||||
|
|
||||||
|
REPO_I is the current (1-based) iteration count. Can be used in
|
||||||
|
conjunction with REPO_COUNT to add a simple progress indicator to your
|
||||||
|
command.
|
||||||
|
|
||||||
REPO__* are any extra environment variables, specified by the
|
REPO__* are any extra environment variables, specified by the
|
||||||
"annotation" element under any project element. This can be useful
|
"annotation" element under any project element. This can be useful
|
||||||
for differentiating trees based on user-specific criteria, or simply
|
for differentiating trees based on user-specific criteria, or simply
|
||||||
@ -126,9 +136,35 @@ without iterating through the remaining projects.
|
|||||||
g.add_option('-v', '--verbose',
|
g.add_option('-v', '--verbose',
|
||||||
dest='verbose', action='store_true',
|
dest='verbose', action='store_true',
|
||||||
help='Show command error messages')
|
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):
|
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):
|
def Execute(self, opt, args):
|
||||||
if not opt.command:
|
if not opt.command:
|
||||||
@ -167,123 +203,188 @@ without iterating through the remaining projects.
|
|||||||
# pylint: enable=W0631
|
# pylint: enable=W0631
|
||||||
|
|
||||||
mirror = self.manifest.IsMirror
|
mirror = self.manifest.IsMirror
|
||||||
out = ForallColoring(self.manifest.manifestProject.config)
|
|
||||||
out.redirect(sys.stdout)
|
|
||||||
|
|
||||||
rc = 0
|
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:
|
if not opt.regex:
|
||||||
projects = self.GetProjects(args)
|
projects = self.GetProjects(args)
|
||||||
else:
|
else:
|
||||||
projects = self.FindProjects(args)
|
projects = self.FindProjects(args)
|
||||||
|
|
||||||
for project in projects:
|
os.environ['REPO_COUNT'] = str(len(projects))
|
||||||
env = os.environ.copy()
|
|
||||||
def setenv(name, val):
|
|
||||||
if val is None:
|
|
||||||
val = ''
|
|
||||||
env[name] = val.encode()
|
|
||||||
|
|
||||||
setenv('REPO_PROJECT', project.name)
|
pool = multiprocessing.Pool(opt.jobs, InitWorker)
|
||||||
setenv('REPO_PATH', project.relpath)
|
try:
|
||||||
setenv('REPO_REMOTE', project.remote.name)
|
config = self.manifest.manifestProject.config
|
||||||
setenv('REPO_LREV', project.GetRevisionId())
|
results_it = pool.imap(
|
||||||
setenv('REPO_RREV', project.revisionExpr)
|
DoWorkWrapper,
|
||||||
for a in project.annotations:
|
self.ProjectArgs(projects, mirror, opt, cmd, shell, config))
|
||||||
setenv("REPO__%s" % (a.name), a.value)
|
pool.close()
|
||||||
|
for r in results_it:
|
||||||
if mirror:
|
rc = rc or r
|
||||||
setenv('GIT_DIR', project.gitdir)
|
if r != 0 and opt.abort_on_errors:
|
||||||
cwd = project.gitdir
|
raise Exception('Aborting due to previous error')
|
||||||
else:
|
except (KeyboardInterrupt, WorkerKeyboardInterrupt):
|
||||||
cwd = project.worktree
|
# Catch KeyboardInterrupt raised inside and outside of workers
|
||||||
|
print('Interrupted - terminating the pool')
|
||||||
if not os.path.exists(cwd):
|
pool.terminate()
|
||||||
if (opt.project_header and opt.verbose) \
|
rc = rc or errno.EINTR
|
||||||
or not opt.project_header:
|
except Exception as e:
|
||||||
print('skipping %s/' % project.relpath, file=sys.stderr)
|
# Catch any other exceptions raised
|
||||||
continue
|
print('Got an error, terminating the pool: %r' % e,
|
||||||
|
file=sys.stderr)
|
||||||
if opt.project_header:
|
pool.terminate()
|
||||||
stdin = subprocess.PIPE
|
rc = rc or getattr(e, 'errno', 1)
|
||||||
stdout = subprocess.PIPE
|
finally:
|
||||||
stderr = subprocess.PIPE
|
pool.join()
|
||||||
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)
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
sys.exit(rc)
|
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
|
||||||
|
@ -27,7 +27,7 @@ else:
|
|||||||
import imp
|
import imp
|
||||||
import urlparse
|
import urlparse
|
||||||
urllib = imp.new_module('urllib')
|
urllib = imp.new_module('urllib')
|
||||||
urllib.parse = urlparse.urlparse
|
urllib.parse = urlparse
|
||||||
|
|
||||||
from color import Coloring
|
from color import Coloring
|
||||||
from command import InteractiveCommand, MirrorSafeCommand
|
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.
|
# server where this git is located, so let's save that here.
|
||||||
mirrored_manifest_git = None
|
mirrored_manifest_git = None
|
||||||
if opt.reference:
|
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)
|
mirrored_manifest_git = os.path.join(opt.reference, manifest_git_path)
|
||||||
if not mirrored_manifest_git.endswith(".git"):
|
if not mirrored_manifest_git.endswith(".git"):
|
||||||
mirrored_manifest_git += ".git"
|
mirrored_manifest_git += ".git"
|
||||||
@ -233,7 +233,7 @@ to update the working directory files.
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if opt.manifest_branch:
|
if opt.manifest_branch:
|
||||||
m.MetaBranchSwitch(opt.manifest_branch)
|
m.MetaBranchSwitch()
|
||||||
|
|
||||||
syncbuf = SyncBuffer(m.config)
|
syncbuf = SyncBuffer(m.config)
|
||||||
m.Sync_LocalHalf(syncbuf)
|
m.Sync_LocalHalf(syncbuf)
|
||||||
|
@ -59,9 +59,13 @@ revision specified in the manifest.
|
|||||||
for project in all_projects:
|
for project in all_projects:
|
||||||
pm.update()
|
pm.update()
|
||||||
# If the current revision is a specific SHA1 then we can't push back
|
# If the current revision is a specific SHA1 then we can't push back
|
||||||
# to it so substitute the manifest default revision instead.
|
# to it; so substitute with dest_branch if defined, or with manifest
|
||||||
|
# default revision instead.
|
||||||
if IsId(project.revisionExpr):
|
if IsId(project.revisionExpr):
|
||||||
project.revisionExpr = self.manifest.default.revisionExpr
|
if project.dest_branch:
|
||||||
|
project.revisionExpr = project.dest_branch
|
||||||
|
else:
|
||||||
|
project.revisionExpr = self.manifest.default.revisionExpr
|
||||||
if not project.StartBranch(nb):
|
if not project.StartBranch(nb):
|
||||||
err.append(project)
|
err.append(project)
|
||||||
pm.end()
|
pm.end()
|
||||||
|
@ -22,15 +22,8 @@ except ImportError:
|
|||||||
|
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
from pyversion import is_python3
|
|
||||||
if is_python3():
|
|
||||||
import io
|
|
||||||
else:
|
|
||||||
import StringIO as io
|
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
from color import Coloring
|
from color import Coloring
|
||||||
|
|
||||||
@ -97,7 +90,7 @@ the following meanings:
|
|||||||
dest='orphans', action='store_true',
|
dest='orphans', action='store_true',
|
||||||
help="include objects in working directory outside of repo projects")
|
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 specific project.
|
||||||
|
|
||||||
Obtains the status for a project, redirecting the output to
|
Obtains the status for a project, redirecting the output to
|
||||||
@ -111,9 +104,9 @@ the following meanings:
|
|||||||
output: Where to output the status.
|
output: Where to output the status.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
state = project.PrintWorkTreeStatus(output)
|
state = project.PrintWorkTreeStatus()
|
||||||
if state == 'CLEAN':
|
if state == 'CLEAN':
|
||||||
clean_counter.next()
|
next(clean_counter)
|
||||||
finally:
|
finally:
|
||||||
sem.release()
|
sem.release()
|
||||||
|
|
||||||
@ -122,16 +115,16 @@ the following meanings:
|
|||||||
status_header = ' --\t'
|
status_header = ' --\t'
|
||||||
for item in dirs:
|
for item in dirs:
|
||||||
if not os.path.isdir(item):
|
if not os.path.isdir(item):
|
||||||
outstring.write(''.join([status_header, item]))
|
outstring.append(''.join([status_header, item]))
|
||||||
continue
|
continue
|
||||||
if item in proj_dirs:
|
if item in proj_dirs:
|
||||||
continue
|
continue
|
||||||
if item in proj_dirs_parents:
|
if item in proj_dirs_parents:
|
||||||
self._FindOrphans(glob.glob('%s/.*' % item) + \
|
self._FindOrphans(glob.glob('%s/.*' % item) +
|
||||||
glob.glob('%s/*' % item), \
|
glob.glob('%s/*' % item),
|
||||||
proj_dirs, proj_dirs_parents, outstring)
|
proj_dirs, proj_dirs_parents, outstring)
|
||||||
continue
|
continue
|
||||||
outstring.write(''.join([status_header, item, '/']))
|
outstring.append(''.join([status_header, item, '/']))
|
||||||
|
|
||||||
def Execute(self, opt, args):
|
def Execute(self, opt, args):
|
||||||
all_projects = self.GetProjects(args)
|
all_projects = self.GetProjects(args)
|
||||||
@ -141,30 +134,21 @@ the following meanings:
|
|||||||
for project in all_projects:
|
for project in all_projects:
|
||||||
state = project.PrintWorkTreeStatus()
|
state = project.PrintWorkTreeStatus()
|
||||||
if state == 'CLEAN':
|
if state == 'CLEAN':
|
||||||
counter.next()
|
next(counter)
|
||||||
else:
|
else:
|
||||||
sem = _threading.Semaphore(opt.jobs)
|
sem = _threading.Semaphore(opt.jobs)
|
||||||
threads_and_output = []
|
threads = []
|
||||||
for project in all_projects:
|
for project in all_projects:
|
||||||
sem.acquire()
|
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,
|
t = _threading.Thread(target=self._StatusHelper,
|
||||||
args=(project, counter, sem, output))
|
args=(project, counter, sem))
|
||||||
threads_and_output.append((t, output))
|
threads.append(t)
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
for (t, output) in threads_and_output:
|
for t in threads:
|
||||||
t.join()
|
t.join()
|
||||||
output.dump(sys.stdout)
|
if len(all_projects) == next(counter):
|
||||||
output.close()
|
|
||||||
if len(all_projects) == counter.next():
|
|
||||||
print('nothing to commit (working directory clean)')
|
print('nothing to commit (working directory clean)')
|
||||||
|
|
||||||
if opt.orphans:
|
if opt.orphans:
|
||||||
@ -188,23 +172,21 @@ the following meanings:
|
|||||||
try:
|
try:
|
||||||
os.chdir(self.manifest.topdir)
|
os.chdir(self.manifest.topdir)
|
||||||
|
|
||||||
outstring = io.StringIO()
|
outstring = []
|
||||||
self._FindOrphans(glob.glob('.*') + \
|
self._FindOrphans(glob.glob('.*') +
|
||||||
glob.glob('*'), \
|
glob.glob('*'),
|
||||||
proj_dirs, proj_dirs_parents, outstring)
|
proj_dirs, proj_dirs_parents, outstring)
|
||||||
|
|
||||||
if outstring.buflist:
|
if outstring:
|
||||||
output = StatusColoring(self.manifest.globalConfig)
|
output = StatusColoring(self.manifest.globalConfig)
|
||||||
output.project('Objects not within a project (orphans)')
|
output.project('Objects not within a project (orphans)')
|
||||||
output.nl()
|
output.nl()
|
||||||
for entry in outstring.buflist:
|
for entry in outstring:
|
||||||
output.untracked(entry)
|
output.untracked(entry)
|
||||||
output.nl()
|
output.nl()
|
||||||
else:
|
else:
|
||||||
print('No orphan files or directories')
|
print('No orphan files or directories')
|
||||||
|
|
||||||
outstring.close()
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Restore CWD.
|
# Restore CWD.
|
||||||
os.chdir(orig_path)
|
os.chdir(orig_path)
|
||||||
|
170
subcmds/sync.py
170
subcmds/sync.py
@ -14,10 +14,10 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import json
|
||||||
import netrc
|
import netrc
|
||||||
from optparse import SUPPRESS_HELP
|
from optparse import SUPPRESS_HELP
|
||||||
import os
|
import os
|
||||||
import pickle
|
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
@ -128,6 +128,13 @@ HTTP client or proxy configuration, but the Git binary works.
|
|||||||
The --fetch-submodules option enables fetching Git submodules
|
The --fetch-submodules option enables fetching Git submodules
|
||||||
of a project from server.
|
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
|
SSH Connections
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
@ -203,6 +210,9 @@ later is required to fix a server side protocol bug.
|
|||||||
p.add_option('--no-tags',
|
p.add_option('--no-tags',
|
||||||
dest='no_tags', action='store_true',
|
dest='no_tags', action='store_true',
|
||||||
help="don't fetch tags")
|
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:
|
if show_smart:
|
||||||
p.add_option('-s', '--smart-sync',
|
p.add_option('-s', '--smart-sync',
|
||||||
dest='smart_sync', action='store_true',
|
dest='smart_sync', action='store_true',
|
||||||
@ -219,7 +229,7 @@ later is required to fix a server side protocol bug.
|
|||||||
dest='repo_upgraded', action='store_true',
|
dest='repo_upgraded', action='store_true',
|
||||||
help=SUPPRESS_HELP)
|
help=SUPPRESS_HELP)
|
||||||
|
|
||||||
def _FetchProjectList(self, opt, projects, *args):
|
def _FetchProjectList(self, opt, projects, *args, **kwargs):
|
||||||
"""Main function of the fetch threads when jobs are > 1.
|
"""Main function of the fetch threads when jobs are > 1.
|
||||||
|
|
||||||
Delegates most of the work to _FetchHelper.
|
Delegates most of the work to _FetchHelper.
|
||||||
@ -227,11 +237,11 @@ later is required to fix a server side protocol bug.
|
|||||||
Args:
|
Args:
|
||||||
opt: Program options returned from optparse. See _Options().
|
opt: Program options returned from optparse. See _Options().
|
||||||
projects: Projects to fetch.
|
projects: Projects to fetch.
|
||||||
*args: Remaining arguments to pass to _FetchHelper. See the
|
*args, **kwargs: Remaining arguments to pass to _FetchHelper. See the
|
||||||
_FetchHelper docstring for details.
|
_FetchHelper docstring for details.
|
||||||
"""
|
"""
|
||||||
for project in projects:
|
for project in projects:
|
||||||
success = self._FetchHelper(opt, project, *args)
|
success = self._FetchHelper(opt, project, *args, **kwargs)
|
||||||
if not success and not opt.force_broken:
|
if not success and not opt.force_broken:
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -272,7 +282,8 @@ later is required to fix a server side protocol bug.
|
|||||||
quiet=opt.quiet,
|
quiet=opt.quiet,
|
||||||
current_branch_only=opt.current_branch_only,
|
current_branch_only=opt.current_branch_only,
|
||||||
clone_bundle=not opt.no_clone_bundle,
|
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)
|
self._fetch_times.Set(project, time.time() - start)
|
||||||
|
|
||||||
# Lock around all the rest of the code, since printing, updating a set
|
# Lock around all the rest of the code, since printing, updating a set
|
||||||
@ -304,62 +315,47 @@ later is required to fix a server side protocol bug.
|
|||||||
|
|
||||||
def _Fetch(self, projects, opt):
|
def _Fetch(self, projects, opt):
|
||||||
fetched = set()
|
fetched = set()
|
||||||
|
lock = _threading.Lock()
|
||||||
pm = Progress('Fetching projects', len(projects))
|
pm = Progress('Fetching projects', len(projects))
|
||||||
|
|
||||||
if self.jobs == 1:
|
objdir_project_map = dict()
|
||||||
for project in projects:
|
for project in projects:
|
||||||
pm.update()
|
objdir_project_map.setdefault(project.objdir, []).append(project)
|
||||||
if not opt.quiet:
|
|
||||||
print('Fetching project %s' % project.name)
|
|
||||||
if project.Sync_NetworkHalf(
|
|
||||||
quiet=opt.quiet,
|
|
||||||
current_branch_only=opt.current_branch_only,
|
|
||||||
clone_bundle=not opt.no_clone_bundle,
|
|
||||||
no_tags=opt.no_tags,
|
|
||||||
archive=self.manifest.IsArchive):
|
|
||||||
fetched.add(project.gitdir)
|
|
||||||
else:
|
|
||||||
print('error: Cannot fetch %s' % project.name, file=sys.stderr)
|
|
||||||
if opt.force_broken:
|
|
||||||
print('warn: --force-broken, continuing to sync', file=sys.stderr)
|
|
||||||
else:
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
objdir_project_map = dict()
|
|
||||||
for project in projects:
|
|
||||||
objdir_project_map.setdefault(project.objdir, []).append(project)
|
|
||||||
|
|
||||||
threads = set()
|
threads = set()
|
||||||
lock = _threading.Lock()
|
sem = _threading.Semaphore(self.jobs)
|
||||||
sem = _threading.Semaphore(self.jobs)
|
err_event = _threading.Event()
|
||||||
err_event = _threading.Event()
|
for project_list in objdir_project_map.values():
|
||||||
for project_list in objdir_project_map.values():
|
# Check for any errors before running any more tasks.
|
||||||
# Check for any errors before starting any new threads.
|
# ...we'll let existing threads finish, though.
|
||||||
# ...we'll let existing threads finish, though.
|
if err_event.isSet() and not opt.force_broken:
|
||||||
if err_event.isSet():
|
break
|
||||||
break
|
|
||||||
|
|
||||||
sem.acquire()
|
sem.acquire()
|
||||||
|
kwargs = dict(opt=opt,
|
||||||
|
projects=project_list,
|
||||||
|
lock=lock,
|
||||||
|
fetched=fetched,
|
||||||
|
pm=pm,
|
||||||
|
sem=sem,
|
||||||
|
err_event=err_event)
|
||||||
|
if self.jobs > 1:
|
||||||
t = _threading.Thread(target = self._FetchProjectList,
|
t = _threading.Thread(target = self._FetchProjectList,
|
||||||
args = (opt,
|
kwargs = kwargs)
|
||||||
project_list,
|
|
||||||
lock,
|
|
||||||
fetched,
|
|
||||||
pm,
|
|
||||||
sem,
|
|
||||||
err_event))
|
|
||||||
# Ensure that Ctrl-C will not freeze the repo process.
|
# Ensure that Ctrl-C will not freeze the repo process.
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
threads.add(t)
|
threads.add(t)
|
||||||
t.start()
|
t.start()
|
||||||
|
else:
|
||||||
|
self._FetchProjectList(**kwargs)
|
||||||
|
|
||||||
for t in threads:
|
for t in threads:
|
||||||
t.join()
|
t.join()
|
||||||
|
|
||||||
# If we saw an error, exit with code 1 so that other scripts can check.
|
# If we saw an error, exit with code 1 so that other scripts can check.
|
||||||
if err_event.isSet():
|
if err_event.isSet():
|
||||||
print('\nerror: Exited sync due to fetch errors', file=sys.stderr)
|
print('\nerror: Exited sync due to fetch errors', file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
pm.end()
|
pm.end()
|
||||||
self._fetch_times.Save()
|
self._fetch_times.Save()
|
||||||
@ -521,6 +517,9 @@ later is required to fix a server side protocol bug.
|
|||||||
self.manifest.Override(opt.manifest_name)
|
self.manifest.Override(opt.manifest_name)
|
||||||
|
|
||||||
manifest_name = 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 opt.smart_sync or opt.smart_tag:
|
||||||
if not self.manifest.manifest_server:
|
if not self.manifest.manifest_server:
|
||||||
@ -573,7 +572,10 @@ later is required to fix a server side protocol bug.
|
|||||||
branch = branch[len(R_HEADS):]
|
branch = branch[len(R_HEADS):]
|
||||||
|
|
||||||
env = os.environ.copy()
|
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'],
|
target = '%s-%s' % (env['TARGET_PRODUCT'],
|
||||||
env['TARGET_BUILD_VARIANT'])
|
env['TARGET_BUILD_VARIANT'])
|
||||||
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
[success, manifest_str] = server.GetApprovedManifest(branch, target)
|
||||||
@ -584,17 +586,16 @@ later is required to fix a server side protocol bug.
|
|||||||
[success, manifest_str] = server.GetManifest(opt.smart_tag)
|
[success, manifest_str] = server.GetManifest(opt.smart_tag)
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
manifest_name = "smart_sync_override.xml"
|
manifest_name = smart_sync_manifest_name
|
||||||
manifest_path = os.path.join(self.manifest.manifestProject.worktree,
|
|
||||||
manifest_name)
|
|
||||||
try:
|
try:
|
||||||
f = open(manifest_path, 'w')
|
f = open(smart_sync_manifest_path, 'w')
|
||||||
try:
|
try:
|
||||||
f.write(manifest_str)
|
f.write(manifest_str)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except IOError:
|
except IOError as e:
|
||||||
print('error: cannot write manifest to %s' % manifest_path,
|
print('error: cannot write manifest to %s:\n%s'
|
||||||
|
% (smart_sync_manifest_path, e),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
self._ReloadManifest(manifest_name)
|
self._ReloadManifest(manifest_name)
|
||||||
@ -611,6 +612,13 @@ later is required to fix a server side protocol bug.
|
|||||||
% (self.manifest.manifest_server, e.errcode, e.errmsg),
|
% (self.manifest.manifest_server, e.errcode, e.errmsg),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
sys.exit(1)
|
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 = self.manifest.repoProject
|
||||||
rp.PreSync()
|
rp.PreSync()
|
||||||
@ -624,7 +632,8 @@ later is required to fix a server side protocol bug.
|
|||||||
if not opt.local_only:
|
if not opt.local_only:
|
||||||
mp.Sync_NetworkHalf(quiet=opt.quiet,
|
mp.Sync_NetworkHalf(quiet=opt.quiet,
|
||||||
current_branch_only=opt.current_branch_only,
|
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:
|
if mp.HasChanges:
|
||||||
syncbuf = SyncBuffer(mp.config)
|
syncbuf = SyncBuffer(mp.config)
|
||||||
@ -775,7 +784,7 @@ class _FetchTimes(object):
|
|||||||
_ALPHA = 0.5
|
_ALPHA = 0.5
|
||||||
|
|
||||||
def __init__(self, manifest):
|
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._times = None
|
||||||
self._seen = set()
|
self._seen = set()
|
||||||
|
|
||||||
@ -794,22 +803,17 @@ class _FetchTimes(object):
|
|||||||
def _Load(self):
|
def _Load(self):
|
||||||
if self._times is None:
|
if self._times is None:
|
||||||
try:
|
try:
|
||||||
f = open(self._path, 'rb')
|
f = open(self._path)
|
||||||
except IOError:
|
|
||||||
self._times = {}
|
|
||||||
return self._times
|
|
||||||
try:
|
|
||||||
try:
|
try:
|
||||||
self._times = pickle.load(f)
|
self._times = json.load(f)
|
||||||
except IOError:
|
finally:
|
||||||
try:
|
f.close()
|
||||||
os.remove(self._path)
|
except (IOError, ValueError):
|
||||||
except OSError:
|
try:
|
||||||
pass
|
os.remove(self._path)
|
||||||
self._times = {}
|
except OSError:
|
||||||
finally:
|
pass
|
||||||
f.close()
|
self._times = {}
|
||||||
return self._times
|
|
||||||
|
|
||||||
def Save(self):
|
def Save(self):
|
||||||
if self._times is None:
|
if self._times is None:
|
||||||
@ -823,13 +827,13 @@ class _FetchTimes(object):
|
|||||||
del self._times[name]
|
del self._times[name]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open(self._path, 'wb')
|
f = open(self._path, 'w')
|
||||||
try:
|
try:
|
||||||
pickle.dump(self._times, f)
|
json.dump(self._times, f, indent=2)
|
||||||
except (IOError, OSError, pickle.PickleError):
|
finally:
|
||||||
try:
|
f.close()
|
||||||
os.remove(self._path)
|
except (IOError, TypeError):
|
||||||
except OSError:
|
try:
|
||||||
pass
|
os.remove(self._path)
|
||||||
finally:
|
except OSError:
|
||||||
f.close()
|
pass
|
||||||
|
@ -25,10 +25,12 @@ from git_command import GitCommand
|
|||||||
from project import RepoHook
|
from project import RepoHook
|
||||||
|
|
||||||
from pyversion import is_python3
|
from pyversion import is_python3
|
||||||
|
# pylint:disable=W0622
|
||||||
if not is_python3():
|
if not is_python3():
|
||||||
# pylint:disable=W0622
|
|
||||||
input = raw_input
|
input = raw_input
|
||||||
# pylint:enable=W0622
|
else:
|
||||||
|
unicode = str
|
||||||
|
# pylint:enable=W0622
|
||||||
|
|
||||||
UNUSUAL_COMMIT_THRESHOLD = 5
|
UNUSUAL_COMMIT_THRESHOLD = 5
|
||||||
|
|
||||||
@ -89,6 +91,11 @@ to "true" then repo will assume you always answer "y" at the prompt,
|
|||||||
and will not prompt you further. If it is set to "false" then repo
|
and will not prompt you further. If it is set to "false" then repo
|
||||||
will assume you always answer "n", and will abort.
|
will assume you always answer "n", and will abort.
|
||||||
|
|
||||||
|
review.URL.autoreviewer:
|
||||||
|
|
||||||
|
To automatically append a user or mailing list to reviews, you can set
|
||||||
|
a per-project or global Git option to do so.
|
||||||
|
|
||||||
review.URL.autocopy:
|
review.URL.autocopy:
|
||||||
|
|
||||||
To automatically copy a user or mailing list to all uploaded reviews,
|
To automatically copy a user or mailing list to all uploaded reviews,
|
||||||
@ -293,14 +300,20 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
|
|
||||||
self._UploadAndReport(opt, todo, people)
|
self._UploadAndReport(opt, todo, people)
|
||||||
|
|
||||||
def _AppendAutoCcList(self, branch, people):
|
def _AppendAutoList(self, branch, people):
|
||||||
"""
|
"""
|
||||||
|
Appends the list of reviewers in the git project's config.
|
||||||
Appends the list of users in the CC list in the git project's config if a
|
Appends the list of users in the CC list in the git project's config if a
|
||||||
non-empty reviewer list was found.
|
non-empty reviewer list was found.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = branch.name
|
name = branch.name
|
||||||
project = branch.project
|
project = branch.project
|
||||||
|
|
||||||
|
key = 'review.%s.autoreviewer' % project.GetBranch(name).remote.review
|
||||||
|
raw_list = project.config.GetString(key)
|
||||||
|
if not raw_list is None:
|
||||||
|
people[0].extend([entry.strip() for entry in raw_list.split(',')])
|
||||||
|
|
||||||
key = 'review.%s.autocopy' % project.GetBranch(name).remote.review
|
key = 'review.%s.autocopy' % project.GetBranch(name).remote.review
|
||||||
raw_list = project.config.GetString(key)
|
raw_list = project.config.GetString(key)
|
||||||
if not raw_list is None and len(people[0]) > 0:
|
if not raw_list is None and len(people[0]) > 0:
|
||||||
@ -323,16 +336,20 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
for branch in todo:
|
for branch in todo:
|
||||||
try:
|
try:
|
||||||
people = copy.deepcopy(original_people)
|
people = copy.deepcopy(original_people)
|
||||||
self._AppendAutoCcList(branch, people)
|
self._AppendAutoList(branch, people)
|
||||||
|
|
||||||
# Check if there are local changes that may have been forgotten
|
# 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
|
key = 'review.%s.autoupload' % branch.project.remote.review
|
||||||
answer = branch.project.config.GetBoolean(key)
|
answer = branch.project.config.GetBoolean(key)
|
||||||
|
|
||||||
# if they want to auto upload, let's not ask because it could be automated
|
# if they want to auto upload, let's not ask because it could be automated
|
||||||
if answer is None:
|
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()
|
a = sys.stdin.readline().strip().lower()
|
||||||
if a not in ('y', 'yes', 't', 'true', 'on'):
|
if a not in ('y', 'yes', 't', 'true', 'on'):
|
||||||
print("skipping upload", file=sys.stderr)
|
print("skipping upload", file=sys.stderr)
|
||||||
|
Reference in New Issue
Block a user