mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-28 20:17:26 +00:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b8db3ce3e | |||
5df6de075e | |||
a0de6e8eab | |||
16614f86b3 | |||
88443387b1 | |||
99482ae58a | |||
ec1df9b7f6 | |||
06d029c1c8 | |||
b715b14807 | |||
60829ba72f |
@ -20,12 +20,15 @@ A manifest XML file (e.g. 'default.xml') roughly conforms to the
|
|||||||
following DTD:
|
following DTD:
|
||||||
|
|
||||||
<!DOCTYPE manifest [
|
<!DOCTYPE manifest [
|
||||||
<!ELEMENT manifest (remote*,
|
<!ELEMENT manifest (notice?,
|
||||||
|
remote*,
|
||||||
default?,
|
default?,
|
||||||
manifest-server?,
|
manifest-server?,
|
||||||
remove-project*,
|
remove-project*,
|
||||||
project*)>
|
project*)>
|
||||||
|
|
||||||
|
<!ELEMENT notice (#PCDATA)>
|
||||||
|
|
||||||
<!ELEMENT remote (EMPTY)>
|
<!ELEMENT remote (EMPTY)>
|
||||||
<!ATTLIST remote name ID #REQUIRED>
|
<!ATTLIST remote name ID #REQUIRED>
|
||||||
<!ATTLIST remote fetch CDATA #REQUIRED>
|
<!ATTLIST remote fetch CDATA #REQUIRED>
|
||||||
|
@ -82,7 +82,7 @@ least one of these before using this command."""
|
|||||||
fd = None
|
fd = None
|
||||||
|
|
||||||
if re.compile("^.*[$ \t'].*$").match(editor):
|
if re.compile("^.*[$ \t'].*$").match(editor):
|
||||||
args = [editor + ' "$@"']
|
args = [editor + ' "$@"', 'sh']
|
||||||
shell = True
|
shell = True
|
||||||
else:
|
else:
|
||||||
args = [editor]
|
args = [editor]
|
||||||
|
@ -257,9 +257,11 @@ class GitConfig(object):
|
|||||||
finally:
|
finally:
|
||||||
fd.close()
|
fd.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
os.remove(self._pickle)
|
if os.path.exists(self._pickle):
|
||||||
|
os.remove(self._pickle)
|
||||||
except cPickle.PickleError:
|
except cPickle.PickleError:
|
||||||
os.remove(self._pickle)
|
if os.path.exists(self._pickle):
|
||||||
|
os.remove(self._pickle)
|
||||||
|
|
||||||
def _ReadGit(self):
|
def _ReadGit(self):
|
||||||
"""
|
"""
|
||||||
@ -356,18 +358,21 @@ class RefSpec(object):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
_ssh_cache = {}
|
_master_processes = []
|
||||||
|
_master_keys = set()
|
||||||
_ssh_master = True
|
_ssh_master = True
|
||||||
|
|
||||||
def _open_ssh(host, port=None):
|
def _open_ssh(host, port=None):
|
||||||
global _ssh_master
|
global _ssh_master
|
||||||
|
|
||||||
|
# Check to see whether we already think that the master is running; if we
|
||||||
|
# think it's already running, return right away.
|
||||||
if port is not None:
|
if port is not None:
|
||||||
key = '%s:%s' % (host, port)
|
key = '%s:%s' % (host, port)
|
||||||
else:
|
else:
|
||||||
key = host
|
key = host
|
||||||
|
|
||||||
if key in _ssh_cache:
|
if key in _master_keys:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not _ssh_master \
|
if not _ssh_master \
|
||||||
@ -377,15 +382,39 @@ def _open_ssh(host, port=None):
|
|||||||
#
|
#
|
||||||
return False
|
return False
|
||||||
|
|
||||||
command = ['ssh',
|
# We will make two calls to ssh; this is the common part of both calls.
|
||||||
'-o','ControlPath %s' % ssh_sock(),
|
command_base = ['ssh',
|
||||||
'-M',
|
'-o','ControlPath %s' % ssh_sock(),
|
||||||
'-N',
|
host]
|
||||||
host]
|
|
||||||
|
|
||||||
if port is not None:
|
if port is not None:
|
||||||
command[3:3] = ['-p',str(port)]
|
command_base[1:1] = ['-p',str(port)]
|
||||||
|
|
||||||
|
# Since the key wasn't in _master_keys, we think that master isn't running.
|
||||||
|
# ...but before actually starting a master, we'll double-check. This can
|
||||||
|
# be important because we can't tell that that 'git@myhost.com' is the same
|
||||||
|
# as 'myhost.com' where "User git" is setup in the user's ~/.ssh/config file.
|
||||||
|
check_command = command_base + ['-O','check']
|
||||||
|
try:
|
||||||
|
Trace(': %s', ' '.join(check_command))
|
||||||
|
check_process = subprocess.Popen(check_command,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
|
check_process.communicate() # read output, but ignore it...
|
||||||
|
isnt_running = check_process.wait()
|
||||||
|
|
||||||
|
if not isnt_running:
|
||||||
|
# Our double-check found that the master _was_ infact running. Add to
|
||||||
|
# the list of keys.
|
||||||
|
_master_keys.add(key)
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
# Ignore excpetions. We we will fall back to the normal command and print
|
||||||
|
# to the log there.
|
||||||
|
pass
|
||||||
|
|
||||||
|
command = command_base[:1] + \
|
||||||
|
['-M', '-N'] + \
|
||||||
|
command_base[1:]
|
||||||
try:
|
try:
|
||||||
Trace(': %s', ' '.join(command))
|
Trace(': %s', ' '.join(command))
|
||||||
p = subprocess.Popen(command)
|
p = subprocess.Popen(command)
|
||||||
@ -396,20 +425,22 @@ def _open_ssh(host, port=None):
|
|||||||
% (host,port, str(e))
|
% (host,port, str(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
_ssh_cache[key] = p
|
_master_processes.append(p)
|
||||||
|
_master_keys.add(key)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def close_ssh():
|
def close_ssh():
|
||||||
terminate_ssh_clients()
|
terminate_ssh_clients()
|
||||||
|
|
||||||
for key,p in _ssh_cache.iteritems():
|
for p in _master_processes:
|
||||||
try:
|
try:
|
||||||
os.kill(p.pid, SIGTERM)
|
os.kill(p.pid, SIGTERM)
|
||||||
p.wait()
|
p.wait()
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
_ssh_cache.clear()
|
del _master_processes[:]
|
||||||
|
_master_keys.clear()
|
||||||
|
|
||||||
d = ssh_sock(create=False)
|
d = ssh_sock(create=False)
|
||||||
if d:
|
if d:
|
||||||
|
2
git_ssh
2
git_ssh
@ -1,2 +1,2 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
exec ssh -o "ControlPath $REPO_SSH_SOCK" "$@"
|
exec ssh -o "ControlMaster no" -o "ControlPath $REPO_SSH_SOCK" "$@"
|
||||||
|
@ -107,6 +107,15 @@ class XmlManifest(object):
|
|||||||
root = doc.createElement('manifest')
|
root = doc.createElement('manifest')
|
||||||
doc.appendChild(root)
|
doc.appendChild(root)
|
||||||
|
|
||||||
|
# Save out the notice. There's a little bit of work here to give it the
|
||||||
|
# right whitespace, which assumes that the notice is automatically indented
|
||||||
|
# by 4 by minidom.
|
||||||
|
if self.notice:
|
||||||
|
notice_element = root.appendChild(doc.createElement('notice'))
|
||||||
|
notice_lines = self.notice.splitlines()
|
||||||
|
indented_notice = ('\n'.join(" "*4 + line for line in notice_lines))[4:]
|
||||||
|
notice_element.appendChild(doc.createTextNode(indented_notice))
|
||||||
|
|
||||||
d = self.default
|
d = self.default
|
||||||
sort_remotes = list(self.remotes.keys())
|
sort_remotes = list(self.remotes.keys())
|
||||||
sort_remotes.sort()
|
sort_remotes.sort()
|
||||||
@ -179,6 +188,11 @@ class XmlManifest(object):
|
|||||||
self._Load()
|
self._Load()
|
||||||
return self._default
|
return self._default
|
||||||
|
|
||||||
|
@property
|
||||||
|
def notice(self):
|
||||||
|
self._Load()
|
||||||
|
return self._notice
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def manifest_server(self):
|
def manifest_server(self):
|
||||||
self._Load()
|
self._Load()
|
||||||
@ -193,6 +207,7 @@ class XmlManifest(object):
|
|||||||
self._projects = {}
|
self._projects = {}
|
||||||
self._remotes = {}
|
self._remotes = {}
|
||||||
self._default = None
|
self._default = None
|
||||||
|
self._notice = None
|
||||||
self.branch = None
|
self.branch = None
|
||||||
self._manifest_server = None
|
self._manifest_server = None
|
||||||
|
|
||||||
@ -263,6 +278,14 @@ class XmlManifest(object):
|
|||||||
if self._default is None:
|
if self._default is None:
|
||||||
self._default = _Default()
|
self._default = _Default()
|
||||||
|
|
||||||
|
for node in config.childNodes:
|
||||||
|
if node.nodeName == 'notice':
|
||||||
|
if self._notice is not None:
|
||||||
|
raise ManifestParseError, \
|
||||||
|
'duplicate notice in %s' % \
|
||||||
|
(self.manifestFile)
|
||||||
|
self._notice = self._ParseNotice(node)
|
||||||
|
|
||||||
for node in config.childNodes:
|
for node in config.childNodes:
|
||||||
if node.nodeName == 'manifest-server':
|
if node.nodeName == 'manifest-server':
|
||||||
url = self._reqatt(node, 'url')
|
url = self._reqatt(node, 'url')
|
||||||
@ -338,6 +361,45 @@ class XmlManifest(object):
|
|||||||
d.revisionExpr = None
|
d.revisionExpr = None
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def _ParseNotice(self, node):
|
||||||
|
"""
|
||||||
|
reads a <notice> element from the manifest file
|
||||||
|
|
||||||
|
The <notice> element is distinct from other tags in the XML in that the
|
||||||
|
data is conveyed between the start and end tag (it's not an empty-element
|
||||||
|
tag).
|
||||||
|
|
||||||
|
The white space (carriage returns, indentation) for the notice element is
|
||||||
|
relevant and is parsed in a way that is based on how python docstrings work.
|
||||||
|
In fact, the code is remarkably similar to here:
|
||||||
|
http://www.python.org/dev/peps/pep-0257/
|
||||||
|
"""
|
||||||
|
# Get the data out of the node...
|
||||||
|
notice = node.childNodes[0].data
|
||||||
|
|
||||||
|
# Figure out minimum indentation, skipping the first line (the same line
|
||||||
|
# as the <notice> tag)...
|
||||||
|
minIndent = sys.maxint
|
||||||
|
lines = notice.splitlines()
|
||||||
|
for line in lines[1:]:
|
||||||
|
lstrippedLine = line.lstrip()
|
||||||
|
if lstrippedLine:
|
||||||
|
indent = len(line) - len(lstrippedLine)
|
||||||
|
minIndent = min(indent, minIndent)
|
||||||
|
|
||||||
|
# Strip leading / trailing blank lines and also indentation.
|
||||||
|
cleanLines = [lines[0].strip()]
|
||||||
|
for line in lines[1:]:
|
||||||
|
cleanLines.append(line[minIndent:].rstrip())
|
||||||
|
|
||||||
|
# Clear completely blank lines from front and back...
|
||||||
|
while cleanLines and not cleanLines[0]:
|
||||||
|
del cleanLines[0]
|
||||||
|
while cleanLines and not cleanLines[-1]:
|
||||||
|
del cleanLines[-1]
|
||||||
|
|
||||||
|
return '\n'.join(cleanLines)
|
||||||
|
|
||||||
def _ParseProject(self, node):
|
def _ParseProject(self, node):
|
||||||
"""
|
"""
|
||||||
reads a <project> element from the manifest file
|
reads a <project> element from the manifest file
|
||||||
|
120
project.py
120
project.py
@ -111,7 +111,6 @@ class ReviewableBranch(object):
|
|||||||
self.project = project
|
self.project = project
|
||||||
self.branch = branch
|
self.branch = branch
|
||||||
self.base = base
|
self.base = base
|
||||||
self.replace_changes = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -151,7 +150,6 @@ class ReviewableBranch(object):
|
|||||||
|
|
||||||
def UploadForReview(self, people, auto_topic=False):
|
def UploadForReview(self, people, auto_topic=False):
|
||||||
self.project.UploadForReview(self.name,
|
self.project.UploadForReview(self.name,
|
||||||
self.replace_changes,
|
|
||||||
people,
|
people,
|
||||||
auto_topic=auto_topic)
|
auto_topic=auto_topic)
|
||||||
|
|
||||||
@ -557,7 +555,6 @@ class Project(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def UploadForReview(self, branch=None,
|
def UploadForReview(self, branch=None,
|
||||||
replace_changes=None,
|
|
||||||
people=([],[]),
|
people=([],[]),
|
||||||
auto_topic=False):
|
auto_topic=False):
|
||||||
"""Uploads the named branch for code review.
|
"""Uploads the named branch for code review.
|
||||||
@ -600,9 +597,6 @@ class Project(object):
|
|||||||
cmd.append(branch.remote.SshReviewUrl(self.UserEmail))
|
cmd.append(branch.remote.SshReviewUrl(self.UserEmail))
|
||||||
cmd.append(ref_spec)
|
cmd.append(ref_spec)
|
||||||
|
|
||||||
if replace_changes:
|
|
||||||
for change_id,commit_id in replace_changes.iteritems():
|
|
||||||
cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id))
|
|
||||||
if GitCommand(self, cmd, bare = True).Wait() != 0:
|
if GitCommand(self, cmd, bare = True).Wait() != 0:
|
||||||
raise UploadError('Upload failed')
|
raise UploadError('Upload failed')
|
||||||
|
|
||||||
@ -618,17 +612,19 @@ class Project(object):
|
|||||||
|
|
||||||
## Sync ##
|
## Sync ##
|
||||||
|
|
||||||
def Sync_NetworkHalf(self):
|
def Sync_NetworkHalf(self, quiet=False):
|
||||||
"""Perform only the network IO portion of the sync process.
|
"""Perform only the network IO portion of the sync process.
|
||||||
Local working directory/branch state is not affected.
|
Local working directory/branch state is not affected.
|
||||||
"""
|
"""
|
||||||
if not self.Exists:
|
is_new = not self.Exists
|
||||||
print >>sys.stderr
|
if is_new:
|
||||||
print >>sys.stderr, 'Initializing project %s ...' % self.name
|
if not quiet:
|
||||||
|
print >>sys.stderr
|
||||||
|
print >>sys.stderr, 'Initializing project %s ...' % self.name
|
||||||
self._InitGitDir()
|
self._InitGitDir()
|
||||||
|
|
||||||
self._InitRemote()
|
self._InitRemote()
|
||||||
if not self._RemoteFetch():
|
if not self._RemoteFetch(initial=is_new, quiet=quiet):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
#Check that the requested ref was found after fetch
|
#Check that the requested ref was found after fetch
|
||||||
@ -641,7 +637,7 @@ class Project(object):
|
|||||||
#
|
#
|
||||||
rev = self.revisionExpr
|
rev = self.revisionExpr
|
||||||
if rev.startswith(R_TAGS):
|
if rev.startswith(R_TAGS):
|
||||||
self._RemoteFetch(None, rev[len(R_TAGS):])
|
self._RemoteFetch(None, rev[len(R_TAGS):], quiet=quiet)
|
||||||
|
|
||||||
if self.worktree:
|
if self.worktree:
|
||||||
self._InitMRef()
|
self._InitMRef()
|
||||||
@ -1024,7 +1020,9 @@ class Project(object):
|
|||||||
|
|
||||||
## Direct Git Commands ##
|
## Direct Git Commands ##
|
||||||
|
|
||||||
def _RemoteFetch(self, name=None, tag=None):
|
def _RemoteFetch(self, name=None, tag=None,
|
||||||
|
initial=False,
|
||||||
|
quiet=False):
|
||||||
if not name:
|
if not name:
|
||||||
name = self.remote.name
|
name = self.remote.name
|
||||||
|
|
||||||
@ -1032,17 +1030,84 @@ class Project(object):
|
|||||||
if self.GetRemote(name).PreConnectFetch():
|
if self.GetRemote(name).PreConnectFetch():
|
||||||
ssh_proxy = True
|
ssh_proxy = True
|
||||||
|
|
||||||
|
if initial:
|
||||||
|
alt = os.path.join(self.gitdir, 'objects/info/alternates')
|
||||||
|
try:
|
||||||
|
fd = open(alt, 'rb')
|
||||||
|
try:
|
||||||
|
ref_dir = fd.readline()
|
||||||
|
if ref_dir and ref_dir.endswith('\n'):
|
||||||
|
ref_dir = ref_dir[:-1]
|
||||||
|
finally:
|
||||||
|
fd.close()
|
||||||
|
except IOError, e:
|
||||||
|
ref_dir = None
|
||||||
|
|
||||||
|
if ref_dir and 'objects' == os.path.basename(ref_dir):
|
||||||
|
ref_dir = os.path.dirname(ref_dir)
|
||||||
|
packed_refs = os.path.join(self.gitdir, 'packed-refs')
|
||||||
|
remote = self.GetRemote(name)
|
||||||
|
|
||||||
|
all = self.bare_ref.all
|
||||||
|
ids = set(all.values())
|
||||||
|
tmp = set()
|
||||||
|
|
||||||
|
for r, id in GitRefs(ref_dir).all.iteritems():
|
||||||
|
if r not in all:
|
||||||
|
if r.startswith(R_TAGS) or remote.WritesTo(r):
|
||||||
|
all[r] = id
|
||||||
|
ids.add(id)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if id in ids:
|
||||||
|
continue
|
||||||
|
|
||||||
|
r = 'refs/_alt/%s' % id
|
||||||
|
all[r] = id
|
||||||
|
ids.add(id)
|
||||||
|
tmp.add(r)
|
||||||
|
|
||||||
|
ref_names = list(all.keys())
|
||||||
|
ref_names.sort()
|
||||||
|
|
||||||
|
tmp_packed = ''
|
||||||
|
old_packed = ''
|
||||||
|
|
||||||
|
for r in ref_names:
|
||||||
|
line = '%s %s\n' % (all[r], r)
|
||||||
|
tmp_packed += line
|
||||||
|
if r not in tmp:
|
||||||
|
old_packed += line
|
||||||
|
|
||||||
|
_lwrite(packed_refs, tmp_packed)
|
||||||
|
|
||||||
|
else:
|
||||||
|
ref_dir = None
|
||||||
|
|
||||||
cmd = ['fetch']
|
cmd = ['fetch']
|
||||||
|
if quiet:
|
||||||
|
cmd.append('--quiet')
|
||||||
if not self.worktree:
|
if not self.worktree:
|
||||||
cmd.append('--update-head-ok')
|
cmd.append('--update-head-ok')
|
||||||
cmd.append(name)
|
cmd.append(name)
|
||||||
if tag is not None:
|
if tag is not None:
|
||||||
cmd.append('tag')
|
cmd.append('tag')
|
||||||
cmd.append(tag)
|
cmd.append(tag)
|
||||||
return GitCommand(self,
|
|
||||||
cmd,
|
ok = GitCommand(self,
|
||||||
bare = True,
|
cmd,
|
||||||
ssh_proxy = ssh_proxy).Wait() == 0
|
bare = True,
|
||||||
|
ssh_proxy = ssh_proxy).Wait() == 0
|
||||||
|
|
||||||
|
if initial:
|
||||||
|
if ref_dir:
|
||||||
|
if old_packed != '':
|
||||||
|
_lwrite(packed_refs, old_packed)
|
||||||
|
else:
|
||||||
|
os.remove(packed_refs)
|
||||||
|
self.bare_git.pack_refs('--all', '--prune')
|
||||||
|
|
||||||
|
return ok
|
||||||
|
|
||||||
def _Checkout(self, rev, quiet=False):
|
def _Checkout(self, rev, quiet=False):
|
||||||
cmd = ['checkout']
|
cmd = ['checkout']
|
||||||
@ -1080,6 +1145,27 @@ class Project(object):
|
|||||||
os.makedirs(self.gitdir)
|
os.makedirs(self.gitdir)
|
||||||
self.bare_git.init()
|
self.bare_git.init()
|
||||||
|
|
||||||
|
mp = self.manifest.manifestProject
|
||||||
|
ref_dir = mp.config.GetString('repo.reference')
|
||||||
|
|
||||||
|
if ref_dir:
|
||||||
|
mirror_git = os.path.join(ref_dir, self.name + '.git')
|
||||||
|
repo_git = os.path.join(ref_dir, '.repo', 'projects',
|
||||||
|
self.relpath + '.git')
|
||||||
|
|
||||||
|
if os.path.exists(mirror_git):
|
||||||
|
ref_dir = mirror_git
|
||||||
|
|
||||||
|
elif os.path.exists(repo_git):
|
||||||
|
ref_dir = repo_git
|
||||||
|
|
||||||
|
else:
|
||||||
|
ref_dir = None
|
||||||
|
|
||||||
|
if ref_dir:
|
||||||
|
_lwrite(os.path.join(self.gitdir, 'objects/info/alternates'),
|
||||||
|
os.path.join(ref_dir, 'objects') + '\n')
|
||||||
|
|
||||||
if self.manifest.IsMirror:
|
if self.manifest.IsMirror:
|
||||||
self.config.SetString('core.bare', 'true')
|
self.config.SetString('core.bare', 'true')
|
||||||
else:
|
else:
|
||||||
|
5
repo
5
repo
@ -28,7 +28,7 @@ if __name__ == '__main__':
|
|||||||
del magic
|
del magic
|
||||||
|
|
||||||
# increment this whenever we make important changes to this script
|
# increment this whenever we make important changes to this script
|
||||||
VERSION = (1, 8)
|
VERSION = (1, 9)
|
||||||
|
|
||||||
# increment this if the MAINTAINER_KEYS block is modified
|
# increment this if the MAINTAINER_KEYS block is modified
|
||||||
KEYRING_VERSION = (1,0)
|
KEYRING_VERSION = (1,0)
|
||||||
@ -118,6 +118,9 @@ group.add_option('-m', '--manifest-name',
|
|||||||
group.add_option('--mirror',
|
group.add_option('--mirror',
|
||||||
dest='mirror', action='store_true',
|
dest='mirror', action='store_true',
|
||||||
help='mirror the forrest')
|
help='mirror the forrest')
|
||||||
|
group.add_option('--reference',
|
||||||
|
dest='reference',
|
||||||
|
help='location of mirror directory', metavar='DIR')
|
||||||
|
|
||||||
# Tool
|
# Tool
|
||||||
group = init_optparse.add_option_group('repo Version options')
|
group = init_optparse.add_option_group('repo Version options')
|
||||||
|
@ -41,6 +41,13 @@ The optional -m argument can be used to specify an alternate manifest
|
|||||||
to be used. If no manifest is specified, the manifest default.xml
|
to be used. If no manifest is specified, the manifest default.xml
|
||||||
will be used.
|
will be used.
|
||||||
|
|
||||||
|
The --reference option can be used to point to a directory that
|
||||||
|
has the content of a --mirror sync. This will make the working
|
||||||
|
directory use as much data as possible from the local reference
|
||||||
|
directory when fetching from the server. This will make the sync
|
||||||
|
go a lot faster by reducing data traffic on the network.
|
||||||
|
|
||||||
|
|
||||||
Switching Manifest Branches
|
Switching Manifest Branches
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
@ -71,7 +78,9 @@ to update the working directory files.
|
|||||||
g.add_option('--mirror',
|
g.add_option('--mirror',
|
||||||
dest='mirror', action='store_true',
|
dest='mirror', action='store_true',
|
||||||
help='mirror the forrest')
|
help='mirror the forrest')
|
||||||
|
g.add_option('--reference',
|
||||||
|
dest='reference',
|
||||||
|
help='location of mirror directory', metavar='DIR')
|
||||||
|
|
||||||
# Tool
|
# Tool
|
||||||
g = p.add_option_group('repo Version options')
|
g = p.add_option_group('repo Version options')
|
||||||
@ -115,6 +124,9 @@ to update the working directory files.
|
|||||||
r.ResetFetch()
|
r.ResetFetch()
|
||||||
r.Save()
|
r.Save()
|
||||||
|
|
||||||
|
if opt.reference:
|
||||||
|
m.config.SetString('repo.reference', opt.reference)
|
||||||
|
|
||||||
if opt.mirror:
|
if opt.mirror:
|
||||||
if is_new:
|
if is_new:
|
||||||
m.config.SetString('repo.mirror', 'true')
|
m.config.SetString('repo.mirror', 'true')
|
||||||
|
@ -70,6 +70,9 @@ The -s/--smart-sync option can be used to sync to a known good
|
|||||||
build as specified by the manifest-server element in the current
|
build as specified by the manifest-server element in the current
|
||||||
manifest.
|
manifest.
|
||||||
|
|
||||||
|
The -f/--force-broken option can be used to proceed with syncing
|
||||||
|
other projects if a project sync fails.
|
||||||
|
|
||||||
SSH Connections
|
SSH Connections
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
@ -101,6 +104,9 @@ later is required to fix a server side protocol bug.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def _Options(self, p, show_smart=True):
|
def _Options(self, p, show_smart=True):
|
||||||
|
p.add_option('-f', '--force-broken',
|
||||||
|
dest='force_broken', action='store_true',
|
||||||
|
help="continue sync even if a project fails to sync")
|
||||||
p.add_option('-l','--local-only',
|
p.add_option('-l','--local-only',
|
||||||
dest='local_only', action='store_true',
|
dest='local_only', action='store_true',
|
||||||
help="only update working tree, don't fetch")
|
help="only update working tree, don't fetch")
|
||||||
@ -110,6 +116,9 @@ later is required to fix a server side protocol bug.
|
|||||||
p.add_option('-d','--detach',
|
p.add_option('-d','--detach',
|
||||||
dest='detach_head', action='store_true',
|
dest='detach_head', action='store_true',
|
||||||
help='detach projects back to manifest revision')
|
help='detach projects back to manifest revision')
|
||||||
|
p.add_option('-q','--quiet',
|
||||||
|
dest='quiet', action='store_true',
|
||||||
|
help='be more quiet')
|
||||||
p.add_option('-j','--jobs',
|
p.add_option('-j','--jobs',
|
||||||
dest='jobs', action='store', type='int',
|
dest='jobs', action='store', type='int',
|
||||||
help="number of projects to fetch simultaneously")
|
help="number of projects to fetch simultaneously")
|
||||||
@ -126,11 +135,14 @@ later is required to fix a server side protocol bug.
|
|||||||
dest='repo_upgraded', action='store_true',
|
dest='repo_upgraded', action='store_true',
|
||||||
help=SUPPRESS_HELP)
|
help=SUPPRESS_HELP)
|
||||||
|
|
||||||
def _FetchHelper(self, project, lock, fetched, pm, sem):
|
def _FetchHelper(self, opt, project, lock, fetched, pm, sem):
|
||||||
if not project.Sync_NetworkHalf():
|
if not project.Sync_NetworkHalf(quiet=opt.quiet):
|
||||||
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
||||||
sem.release()
|
if opt.force_broken:
|
||||||
sys.exit(1)
|
print >>sys.stderr, 'warn: --force-broken, continuing to sync'
|
||||||
|
else:
|
||||||
|
sem.release()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
fetched.add(project.gitdir)
|
fetched.add(project.gitdir)
|
||||||
@ -138,18 +150,21 @@ later is required to fix a server side protocol bug.
|
|||||||
lock.release()
|
lock.release()
|
||||||
sem.release()
|
sem.release()
|
||||||
|
|
||||||
def _Fetch(self, projects):
|
def _Fetch(self, projects, opt):
|
||||||
fetched = set()
|
fetched = set()
|
||||||
pm = Progress('Fetching projects', len(projects))
|
pm = Progress('Fetching projects', len(projects))
|
||||||
|
|
||||||
if self.jobs == 1:
|
if self.jobs == 1:
|
||||||
for project in projects:
|
for project in projects:
|
||||||
pm.update()
|
pm.update()
|
||||||
if project.Sync_NetworkHalf():
|
if project.Sync_NetworkHalf(quiet=opt.quiet):
|
||||||
fetched.add(project.gitdir)
|
fetched.add(project.gitdir)
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
|
||||||
sys.exit(1)
|
if opt.force_broken:
|
||||||
|
print >>sys.stderr, 'warn: --force-broken, continuing to sync'
|
||||||
|
else:
|
||||||
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
threads = set()
|
threads = set()
|
||||||
lock = _threading.Lock()
|
lock = _threading.Lock()
|
||||||
@ -157,7 +172,12 @@ later is required to fix a server side protocol bug.
|
|||||||
for project in projects:
|
for project in projects:
|
||||||
sem.acquire()
|
sem.acquire()
|
||||||
t = _threading.Thread(target = self._FetchHelper,
|
t = _threading.Thread(target = self._FetchHelper,
|
||||||
args = (project, lock, fetched, pm, sem))
|
args = (opt,
|
||||||
|
project,
|
||||||
|
lock,
|
||||||
|
fetched,
|
||||||
|
pm,
|
||||||
|
sem))
|
||||||
threads.add(t)
|
threads.add(t)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
@ -291,7 +311,7 @@ uncommitted changes are present' % project.relpath
|
|||||||
_PostRepoUpgrade(self.manifest)
|
_PostRepoUpgrade(self.manifest)
|
||||||
|
|
||||||
if not opt.local_only:
|
if not opt.local_only:
|
||||||
mp.Sync_NetworkHalf()
|
mp.Sync_NetworkHalf(quiet=opt.quiet)
|
||||||
|
|
||||||
if mp.HasChanges:
|
if mp.HasChanges:
|
||||||
syncbuf = SyncBuffer(mp.config)
|
syncbuf = SyncBuffer(mp.config)
|
||||||
@ -308,7 +328,7 @@ uncommitted changes are present' % project.relpath
|
|||||||
to_fetch.append(rp)
|
to_fetch.append(rp)
|
||||||
to_fetch.extend(all)
|
to_fetch.extend(all)
|
||||||
|
|
||||||
fetched = self._Fetch(to_fetch)
|
fetched = self._Fetch(to_fetch, opt)
|
||||||
_PostRepoFetch(rp, opt.no_repo_verify)
|
_PostRepoFetch(rp, opt.no_repo_verify)
|
||||||
if opt.network_only:
|
if opt.network_only:
|
||||||
# bail out now; the rest touches the working tree
|
# bail out now; the rest touches the working tree
|
||||||
@ -320,7 +340,7 @@ uncommitted changes are present' % project.relpath
|
|||||||
for project in all:
|
for project in all:
|
||||||
if project.gitdir not in fetched:
|
if project.gitdir not in fetched:
|
||||||
missing.append(project)
|
missing.append(project)
|
||||||
self._Fetch(missing)
|
self._Fetch(missing, opt)
|
||||||
|
|
||||||
if self.manifest.IsMirror:
|
if self.manifest.IsMirror:
|
||||||
# bail out now, we have no working tree
|
# bail out now, we have no working tree
|
||||||
@ -341,6 +361,11 @@ uncommitted changes are present' % project.relpath
|
|||||||
if not syncbuf.Finish():
|
if not syncbuf.Finish():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# If there's a notice that's supposed to print at the end of the sync, print
|
||||||
|
# it now...
|
||||||
|
if self.manifest.notice:
|
||||||
|
print self.manifest.notice
|
||||||
|
|
||||||
def _PostRepoUpgrade(manifest):
|
def _PostRepoUpgrade(manifest):
|
||||||
for project in manifest.projects.values():
|
for project in manifest.projects.values():
|
||||||
if project.Exists:
|
if project.Exists:
|
||||||
|
@ -47,7 +47,7 @@ class Upload(InteractiveCommand):
|
|||||||
common = True
|
common = True
|
||||||
helpSummary = "Upload changes for code review"
|
helpSummary = "Upload changes for code review"
|
||||||
helpUsage="""
|
helpUsage="""
|
||||||
%prog [--re --cc] {[<project>]... | --replace <project>}
|
%prog [--re --cc] [<project>]...
|
||||||
"""
|
"""
|
||||||
helpDescription = """
|
helpDescription = """
|
||||||
The '%prog' command is used to send changes to the Gerrit Code
|
The '%prog' command is used to send changes to the Gerrit Code
|
||||||
@ -67,12 +67,6 @@ added to the respective list of users, and emails are sent to any
|
|||||||
new users. Users passed as --reviewers must already be registered
|
new users. Users passed as --reviewers must already be registered
|
||||||
with the code review system, or the upload will fail.
|
with the code review system, or the upload will fail.
|
||||||
|
|
||||||
If the --replace option is passed the user can designate which
|
|
||||||
existing change(s) in Gerrit match up to the commits in the branch
|
|
||||||
being uploaded. For each matched pair of change,commit the commit
|
|
||||||
will be added as a new patch set, completely replacing the set of
|
|
||||||
files and description associated with the change in Gerrit.
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
@ -119,9 +113,6 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
p.add_option('-t',
|
p.add_option('-t',
|
||||||
dest='auto_topic', action='store_true',
|
dest='auto_topic', action='store_true',
|
||||||
help='Send local branch name to Gerrit Code Review')
|
help='Send local branch name to Gerrit Code Review')
|
||||||
p.add_option('--replace',
|
|
||||||
dest='replace', action='store_true',
|
|
||||||
help='Upload replacement patchesets from this branch')
|
|
||||||
p.add_option('--re', '--reviewers',
|
p.add_option('--re', '--reviewers',
|
||||||
type='string', action='append', dest='reviewers',
|
type='string', action='append', dest='reviewers',
|
||||||
help='Request reviews from these people.')
|
help='Request reviews from these people.')
|
||||||
@ -262,65 +253,6 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
except:
|
except:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _ReplaceBranch(self, project, people):
|
|
||||||
branch = project.CurrentBranch
|
|
||||||
if not branch:
|
|
||||||
print >>sys.stdout, "no branches ready for upload"
|
|
||||||
return
|
|
||||||
branch = project.GetUploadableBranch(branch)
|
|
||||||
if not branch:
|
|
||||||
print >>sys.stdout, "no branches ready for upload"
|
|
||||||
return
|
|
||||||
|
|
||||||
script = []
|
|
||||||
script.append('# Replacing from branch %s' % branch.name)
|
|
||||||
|
|
||||||
if len(branch.commits) == 1:
|
|
||||||
change = self._FindGerritChange(branch)
|
|
||||||
script.append('[%-6s] %s' % (change, branch.commits[0]))
|
|
||||||
else:
|
|
||||||
for commit in branch.commits:
|
|
||||||
script.append('[ ] %s' % commit)
|
|
||||||
|
|
||||||
script.append('')
|
|
||||||
script.append('# Insert change numbers in the brackets to add a new patch set.')
|
|
||||||
script.append('# To create a new change record, leave the brackets empty.')
|
|
||||||
|
|
||||||
script = Editor.EditString("\n".join(script)).split("\n")
|
|
||||||
|
|
||||||
change_re = re.compile(r'^\[\s*(\d{1,})\s*\]\s*([0-9a-f]{1,}) .*$')
|
|
||||||
to_replace = dict()
|
|
||||||
full_hashes = branch.unabbrev_commits
|
|
||||||
|
|
||||||
for line in script:
|
|
||||||
m = change_re.match(line)
|
|
||||||
if m:
|
|
||||||
c = m.group(1)
|
|
||||||
f = m.group(2)
|
|
||||||
try:
|
|
||||||
f = full_hashes[f]
|
|
||||||
except KeyError:
|
|
||||||
print 'fh = %s' % full_hashes
|
|
||||||
print >>sys.stderr, "error: commit %s not found" % f
|
|
||||||
sys.exit(1)
|
|
||||||
if c in to_replace:
|
|
||||||
print >>sys.stderr,\
|
|
||||||
"error: change %s cannot accept multiple commits" % c
|
|
||||||
sys.exit(1)
|
|
||||||
to_replace[c] = f
|
|
||||||
|
|
||||||
if not to_replace:
|
|
||||||
print >>sys.stderr, "error: no replacements specified"
|
|
||||||
print >>sys.stderr, " use 'repo upload' without --replace"
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
|
|
||||||
if not _ConfirmManyUploads(multiple_branches=True):
|
|
||||||
_die("upload aborted by user")
|
|
||||||
|
|
||||||
branch.replace_changes = to_replace
|
|
||||||
self._UploadAndReport(opt, [branch], people)
|
|
||||||
|
|
||||||
def _UploadAndReport(self, opt, todo, original_people):
|
def _UploadAndReport(self, opt, todo, original_people):
|
||||||
have_errors = False
|
have_errors = False
|
||||||
for branch in todo:
|
for branch in todo:
|
||||||
@ -383,14 +315,6 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
cc = _SplitEmails(opt.cc)
|
cc = _SplitEmails(opt.cc)
|
||||||
people = (reviewers,cc)
|
people = (reviewers,cc)
|
||||||
|
|
||||||
if opt.replace:
|
|
||||||
if len(project_list) != 1:
|
|
||||||
print >>sys.stderr, \
|
|
||||||
'error: --replace requires exactly one project'
|
|
||||||
sys.exit(1)
|
|
||||||
self._ReplaceBranch(project_list[0], people)
|
|
||||||
return
|
|
||||||
|
|
||||||
for project in project_list:
|
for project in project_list:
|
||||||
avail = project.GetUploadableBranches()
|
avail = project.GetUploadableBranches()
|
||||||
if avail:
|
if avail:
|
||||||
|
Reference in New Issue
Block a user