sync --quiet: be more quiet

Change-Id: I5e8363c7b32e4546d1236cfc5a32e01c3e5ea8e6
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce 2010-10-29 12:05:43 -07:00
parent 88443387b1
commit 16614f86b3
2 changed files with 27 additions and 14 deletions

View File

@ -618,18 +618,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.
""" """
is_new = not self.Exists is_new = not self.Exists
if is_new: if is_new:
print >>sys.stderr if not quiet:
print >>sys.stderr, 'Initializing project %s ...' % self.name print >>sys.stderr
print >>sys.stderr, 'Initializing project %s ...' % self.name
self._InitGitDir() self._InitGitDir()
self._InitRemote() self._InitRemote()
if not self._RemoteFetch(initial = is_new): 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
@ -642,7 +643,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()
@ -1025,7 +1026,9 @@ class Project(object):
## Direct Git Commands ## ## Direct Git Commands ##
def _RemoteFetch(self, name=None, tag=None, initial=False): 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
@ -1088,6 +1091,8 @@ class Project(object):
ref_dir = None 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)

View File

@ -110,6 +110,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,8 +129,8 @@ 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() sem.release()
sys.exit(1) sys.exit(1)
@ -138,14 +141,14 @@ 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
@ -157,7 +160,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 +299,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 +316,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 +328,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