2008-10-21 14:00:00 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2008 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from color import Coloring
|
2009-03-04 01:47:06 +00:00
|
|
|
from command import InteractiveCommand, MirrorSafeCommand
|
2008-10-21 14:00:00 +00:00
|
|
|
from error import ManifestParseError
|
Change repo sync to be more friendly when updating the tree
We now try to sync all projects that can be done safely first, before
we start rebasing user commits over the upstream. This has the nice
effect of making the local tree as close to the upstream as possible
before the user has to start resolving merge conflicts, as that extra
information in other projects may aid in the conflict resolution.
Informational output is buffered and delayed until calculation for
all projects has been done, so that the user gets one concise list
of notice messages, rather than it interrupting the progress meter.
Fast-forward output is now prefixed with the project header, so the
user can see which project that update is taking place in, and make
some relation of the diffstat back to the project name.
Rebase output is now prefixed with the project header, so that if
the rebase fails, the user can see which project we were operating
on and can try to address the failure themselves.
Since rebase sits on a detached HEAD, we now look for an in-progress
rebase during sync, so we can alert the user that the given project
is in a state we cannot handle.
Signed-off-by: Shawn O. Pearce <sop@google.com>
2009-04-16 18:21:18 +00:00
|
|
|
from project import SyncBuffer
|
2009-06-12 16:32:50 +00:00
|
|
|
from git_command import git_require, MIN_GIT_VERSION
|
2009-05-20 01:14:04 +00:00
|
|
|
from manifest_xml import XmlManifest
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2009-03-04 01:47:06 +00:00
|
|
|
class Init(InteractiveCommand, MirrorSafeCommand):
|
2008-10-21 14:00:00 +00:00
|
|
|
common = True
|
|
|
|
helpSummary = "Initialize repo in the current directory"
|
|
|
|
helpUsage = """
|
|
|
|
%prog [options]
|
|
|
|
"""
|
|
|
|
helpDescription = """
|
|
|
|
The '%prog' command is run once to install and initialize repo.
|
|
|
|
The latest repo source code and manifest collection is downloaded
|
|
|
|
from the server and is installed in the .repo/ directory in the
|
|
|
|
current working directory.
|
|
|
|
|
2009-04-18 18:33:32 +00:00
|
|
|
The optional -b argument can be used to select the manifest branch
|
|
|
|
to checkout and use. If no branch is specified, master is assumed.
|
|
|
|
|
|
|
|
Switching Manifest Branches
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
To switch to another manifest branch, `repo init -b otherbranch`
|
|
|
|
may be used in an existing client. However, as this only updates the
|
|
|
|
manifest, a subsequent `repo sync` (or `repo sync -d`) is necessary
|
|
|
|
to update the working directory files.
|
2008-10-21 14:00:00 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def _Options(self, p):
|
|
|
|
# Logging
|
|
|
|
g = p.add_option_group('Logging options')
|
|
|
|
g.add_option('-q', '--quiet',
|
|
|
|
dest="quiet", action="store_true", default=False,
|
|
|
|
help="be quiet")
|
|
|
|
|
|
|
|
# Manifest
|
|
|
|
g = p.add_option_group('Manifest options')
|
|
|
|
g.add_option('-u', '--manifest-url',
|
|
|
|
dest='manifest_url',
|
|
|
|
help='manifest repository location', metavar='URL')
|
|
|
|
g.add_option('-b', '--manifest-branch',
|
|
|
|
dest='manifest_branch',
|
|
|
|
help='manifest branch or revision', metavar='REVISION')
|
2009-07-04 00:24:17 +00:00
|
|
|
g.add_option('-o', '--origin',
|
|
|
|
dest='manifest_origin',
|
|
|
|
help="use REMOTE instead of 'origin' to track upstream",
|
|
|
|
metavar='REMOTE')
|
2009-05-20 01:14:04 +00:00
|
|
|
if isinstance(self.manifest, XmlManifest) \
|
|
|
|
or not self.manifest.manifestProject.Exists:
|
|
|
|
g.add_option('-m', '--manifest-name',
|
|
|
|
dest='manifest_name', default='default.xml',
|
|
|
|
help='initial manifest file', metavar='NAME.xml')
|
2008-11-04 15:37:10 +00:00
|
|
|
g.add_option('--mirror',
|
|
|
|
dest='mirror', action='store_true',
|
|
|
|
help='mirror the forrest')
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
# Tool
|
2009-04-18 18:28:57 +00:00
|
|
|
g = p.add_option_group('repo Version options')
|
2008-10-21 14:00:00 +00:00
|
|
|
g.add_option('--repo-url',
|
|
|
|
dest='repo_url',
|
|
|
|
help='repo repository location', metavar='URL')
|
|
|
|
g.add_option('--repo-branch',
|
|
|
|
dest='repo_branch',
|
|
|
|
help='repo branch or revision', metavar='REVISION')
|
|
|
|
g.add_option('--no-repo-verify',
|
|
|
|
dest='no_repo_verify', action='store_true',
|
|
|
|
help='do not verify repo source code')
|
|
|
|
|
2009-07-04 00:24:17 +00:00
|
|
|
def _ApplyOptions(self, opt, is_new):
|
2008-10-21 14:00:00 +00:00
|
|
|
m = self.manifest.manifestProject
|
|
|
|
|
2009-03-10 01:51:58 +00:00
|
|
|
if is_new:
|
2009-07-04 00:24:17 +00:00
|
|
|
if opt.manifest_origin:
|
|
|
|
m.remote.name = opt.manifest_origin
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
if opt.manifest_branch:
|
2009-05-30 01:38:17 +00:00
|
|
|
m.revisionExpr = opt.manifest_branch
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
2009-05-30 01:38:17 +00:00
|
|
|
m.revisionExpr = 'refs/heads/master'
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
2009-07-04 00:24:17 +00:00
|
|
|
if opt.manifest_origin:
|
|
|
|
print >>sys.stderr, 'fatal: cannot change origin name'
|
|
|
|
sys.exit(1)
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
if opt.manifest_branch:
|
2009-05-30 01:38:17 +00:00
|
|
|
m.revisionExpr = opt.manifest_branch
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
|
|
|
m.PreSync()
|
|
|
|
|
2009-07-04 00:24:17 +00:00
|
|
|
def _SyncManifest(self, opt):
|
|
|
|
m = self.manifest.manifestProject
|
|
|
|
is_new = not m.Exists
|
|
|
|
|
|
|
|
if is_new:
|
|
|
|
if not opt.manifest_url:
|
|
|
|
print >>sys.stderr, 'fatal: manifest url (-u) is required.'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not opt.quiet:
|
|
|
|
print >>sys.stderr, 'Getting manifest ...'
|
|
|
|
print >>sys.stderr, ' from %s' % opt.manifest_url
|
|
|
|
m._InitGitDir()
|
|
|
|
|
|
|
|
self._ApplyOptions(opt, is_new)
|
2008-10-21 14:00:00 +00:00
|
|
|
if opt.manifest_url:
|
|
|
|
r = m.GetRemote(m.remote.name)
|
|
|
|
r.url = opt.manifest_url
|
|
|
|
r.ResetFetch()
|
|
|
|
r.Save()
|
|
|
|
|
2008-11-04 15:37:10 +00:00
|
|
|
if opt.mirror:
|
2009-03-10 01:51:58 +00:00
|
|
|
if is_new:
|
|
|
|
m.config.SetString('repo.mirror', 'true')
|
2009-07-04 03:06:13 +00:00
|
|
|
m.config.ClearCache()
|
2009-03-10 01:51:58 +00:00
|
|
|
else:
|
|
|
|
print >>sys.stderr, 'fatal: --mirror not supported on existing client'
|
|
|
|
sys.exit(1)
|
2008-11-04 15:37:10 +00:00
|
|
|
|
2009-03-17 15:06:18 +00:00
|
|
|
if not m.Sync_NetworkHalf():
|
|
|
|
r = m.GetRemote(m.remote.name)
|
|
|
|
print >>sys.stderr, 'fatal: cannot obtain manifest %s' % r.url
|
|
|
|
sys.exit(1)
|
|
|
|
|
Change repo sync to be more friendly when updating the tree
We now try to sync all projects that can be done safely first, before
we start rebasing user commits over the upstream. This has the nice
effect of making the local tree as close to the upstream as possible
before the user has to start resolving merge conflicts, as that extra
information in other projects may aid in the conflict resolution.
Informational output is buffered and delayed until calculation for
all projects has been done, so that the user gets one concise list
of notice messages, rather than it interrupting the progress meter.
Fast-forward output is now prefixed with the project header, so the
user can see which project that update is taking place in, and make
some relation of the diffstat back to the project name.
Rebase output is now prefixed with the project header, so that if
the rebase fails, the user can see which project we were operating
on and can try to address the failure themselves.
Since rebase sits on a detached HEAD, we now look for an in-progress
rebase during sync, so we can alert the user that the given project
is in a state we cannot handle.
Signed-off-by: Shawn O. Pearce <sop@google.com>
2009-04-16 18:21:18 +00:00
|
|
|
syncbuf = SyncBuffer(m.config)
|
|
|
|
m.Sync_LocalHalf(syncbuf)
|
|
|
|
syncbuf.Finish()
|
|
|
|
|
2009-07-03 23:24:57 +00:00
|
|
|
if not self.manifest.InitBranch():
|
|
|
|
print >>sys.stderr, 'fatal: cannot create branch in manifest'
|
|
|
|
sys.exit(1)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _LinkManifest(self, name):
|
|
|
|
if not name:
|
|
|
|
print >>sys.stderr, 'fatal: manifest name (-m) is required.'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.manifest.Link(name)
|
|
|
|
except ManifestParseError, e:
|
|
|
|
print >>sys.stderr, "fatal: manifest '%s' not available" % name
|
|
|
|
print >>sys.stderr, 'fatal: %s' % str(e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-07-02 17:53:04 +00:00
|
|
|
def _Prompt(self, prompt, value):
|
2008-10-21 14:00:00 +00:00
|
|
|
mp = self.manifest.manifestProject
|
|
|
|
|
|
|
|
sys.stdout.write('%-10s [%s]: ' % (prompt, value))
|
|
|
|
a = sys.stdin.readline().strip()
|
2009-07-02 17:53:04 +00:00
|
|
|
if a == '':
|
|
|
|
return value
|
|
|
|
return a
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _ConfigureUser(self):
|
|
|
|
mp = self.manifest.manifestProject
|
|
|
|
|
2009-07-02 17:53:04 +00:00
|
|
|
while True:
|
|
|
|
print ''
|
|
|
|
name = self._Prompt('Your Name', mp.UserName)
|
|
|
|
email = self._Prompt('Your Email', mp.UserEmail)
|
|
|
|
|
|
|
|
print ''
|
|
|
|
print 'Your identity is: %s <%s>' % (name, email)
|
|
|
|
sys.stdout.write('is this correct [yes/no]? ')
|
|
|
|
if 'yes' == sys.stdin.readline().strip():
|
|
|
|
break
|
|
|
|
|
|
|
|
if name != mp.UserName:
|
|
|
|
mp.config.SetString('user.name', name)
|
|
|
|
if email != mp.UserEmail:
|
|
|
|
mp.config.SetString('user.email', email)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _HasColorSet(self, gc):
|
|
|
|
for n in ['ui', 'diff', 'status']:
|
|
|
|
if gc.Has('color.%s' % n):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _ConfigureColor(self):
|
|
|
|
gc = self.manifest.globalConfig
|
|
|
|
if self._HasColorSet(gc):
|
|
|
|
return
|
|
|
|
|
|
|
|
class _Test(Coloring):
|
|
|
|
def __init__(self):
|
|
|
|
Coloring.__init__(self, gc, 'test color display')
|
|
|
|
self._on = True
|
|
|
|
out = _Test()
|
|
|
|
|
|
|
|
print ''
|
|
|
|
print "Testing colorized output (for 'repo diff', 'repo status'):"
|
|
|
|
|
|
|
|
for c in ['black','red','green','yellow','blue','magenta','cyan']:
|
|
|
|
out.write(' ')
|
|
|
|
out.printer(fg=c)(' %-6s ', c)
|
|
|
|
out.write(' ')
|
|
|
|
out.printer(fg='white', bg='black')(' %s ' % 'white')
|
|
|
|
out.nl()
|
|
|
|
|
|
|
|
for c in ['bold','dim','ul','reverse']:
|
|
|
|
out.write(' ')
|
|
|
|
out.printer(fg='black', attr=c)(' %-6s ', c)
|
|
|
|
out.nl()
|
|
|
|
|
|
|
|
sys.stdout.write('Enable color display in this user account (y/n)? ')
|
|
|
|
a = sys.stdin.readline().strip().lower()
|
|
|
|
if a in ('y', 'yes', 't', 'true', 'on'):
|
|
|
|
gc.SetString('color.ui', 'auto')
|
|
|
|
|
|
|
|
def Execute(self, opt, args):
|
2009-06-12 16:32:50 +00:00
|
|
|
git_require(MIN_GIT_VERSION, fail=True)
|
2008-10-21 14:00:00 +00:00
|
|
|
self._SyncManifest(opt)
|
2009-05-20 01:14:04 +00:00
|
|
|
if isinstance(self.manifest, XmlManifest):
|
|
|
|
self._LinkManifest(opt.manifest_name)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2009-03-19 17:17:12 +00:00
|
|
|
if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror:
|
2008-10-21 14:00:00 +00:00
|
|
|
self._ConfigureUser()
|
|
|
|
self._ConfigureColor()
|
|
|
|
|
2009-03-19 17:17:12 +00:00
|
|
|
if self.manifest.IsMirror:
|
2008-11-04 15:37:10 +00:00
|
|
|
type = 'mirror '
|
|
|
|
else:
|
|
|
|
type = ''
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
print ''
|
2008-11-04 15:37:10 +00:00
|
|
|
print 'repo %sinitialized in %s' % (type, self.manifest.topdir)
|