Don't log spam repo sync by default

Most times a repo sync after some time (week+) results in a bunch of
messages, which are not very useful for average user:
- discarding 1 commits
- Deleting obsolete checkout.

Bug: N/A
Test: repo sync
Change-Id: I881eab61f9f261e98f3656c09e73ddd159ce288c
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/397038
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Tested-by: Tomasz Wasilczyk <twasilczyk@google.com>
This commit is contained in:
Tomasz Wasilczyk 2023-12-08 13:42:17 -08:00 committed by LUCI
parent f56484c05b
commit 4c80921d22
2 changed files with 23 additions and 14 deletions

View File

@ -1467,7 +1467,12 @@ class Project:
self.revisionId = revisionId self.revisionId = revisionId
def Sync_LocalHalf( def Sync_LocalHalf(
self, syncbuf, force_sync=False, submodules=False, errors=None self,
syncbuf,
force_sync=False,
submodules=False,
errors=None,
verbose=False,
): ):
"""Perform only the local IO portion of the sync process. """Perform only the local IO portion of the sync process.
@ -1548,7 +1553,7 @@ class Project:
return return
else: else:
lost = self._revlist(not_rev(revid), HEAD) lost = self._revlist(not_rev(revid), HEAD)
if lost: if lost and verbose:
syncbuf.info(self, "discarding %d commits", len(lost)) syncbuf.info(self, "discarding %d commits", len(lost))
try: try:
@ -1738,7 +1743,7 @@ class Project:
self.bare_git.rev_parse("FETCH_HEAD"), self.bare_git.rev_parse("FETCH_HEAD"),
) )
def DeleteWorktree(self, quiet=False, force=False): def DeleteWorktree(self, verbose=False, force=False):
"""Delete the source checkout and any other housekeeping tasks. """Delete the source checkout and any other housekeeping tasks.
This currently leaves behind the internal .repo/ cache state. This This currently leaves behind the internal .repo/ cache state. This
@ -1747,7 +1752,7 @@ class Project:
at some point. at some point.
Args: Args:
quiet: Whether to hide normal messages. verbose: Whether to show verbose messages.
force: Always delete tree even if dirty. force: Always delete tree even if dirty.
Returns: Returns:
@ -1768,7 +1773,7 @@ class Project:
logger.error(msg) logger.error(msg)
raise DeleteDirtyWorktreeError(msg, project=self) raise DeleteDirtyWorktreeError(msg, project=self)
if not quiet: if verbose:
print(f"{self.RelPath(local=False)}: Deleting obsolete checkout.") print(f"{self.RelPath(local=False)}: Deleting obsolete checkout.")
# Unlock and delink from the main worktree. We don't use git's worktree # Unlock and delink from the main worktree. We don't use git's worktree
@ -3900,13 +3905,13 @@ class RepoProject(MetaProject):
class ManifestProject(MetaProject): class ManifestProject(MetaProject):
"""The MetaProject for manifests.""" """The MetaProject for manifests."""
def MetaBranchSwitch(self, submodules=False): def MetaBranchSwitch(self, submodules=False, verbose=False):
"""Prepare for manifest branch switch.""" """Prepare for manifest branch switch."""
# detach and delete manifest branch, allowing a new # detach and delete manifest branch, allowing a new
# branch to take over # branch to take over
syncbuf = SyncBuffer(self.config, detach_head=True) syncbuf = SyncBuffer(self.config, detach_head=True)
self.Sync_LocalHalf(syncbuf, submodules=submodules) self.Sync_LocalHalf(syncbuf, submodules=submodules, verbose=verbose)
syncbuf.Finish() syncbuf.Finish()
return ( return (
@ -4437,10 +4442,10 @@ class ManifestProject(MetaProject):
return False return False
if manifest_branch: if manifest_branch:
self.MetaBranchSwitch(submodules=submodules) self.MetaBranchSwitch(submodules=submodules, verbose=verbose)
syncbuf = SyncBuffer(self.config) syncbuf = SyncBuffer(self.config)
self.Sync_LocalHalf(syncbuf, submodules=submodules) self.Sync_LocalHalf(syncbuf, submodules=submodules, verbose=verbose)
syncbuf.Finish() syncbuf.Finish()
if is_new or self.CurrentBranch is None: if is_new or self.CurrentBranch is None:

View File

@ -956,12 +956,13 @@ later is required to fix a server side protocol bug.
return _FetchMainResult(all_projects) return _FetchMainResult(all_projects)
def _CheckoutOne(self, detach_head, force_sync, project): def _CheckoutOne(self, detach_head, force_sync, verbose, project):
"""Checkout work tree for one project """Checkout work tree for one project
Args: Args:
detach_head: Whether to leave a detached HEAD. detach_head: Whether to leave a detached HEAD.
force_sync: Force checking out of the repo. force_sync: Force checking out of the repo.
verbose: Whether to show verbose messages.
project: Project object for the project to checkout. project: Project object for the project to checkout.
Returns: Returns:
@ -975,7 +976,7 @@ later is required to fix a server side protocol bug.
errors = [] errors = []
try: try:
project.Sync_LocalHalf( project.Sync_LocalHalf(
syncbuf, force_sync=force_sync, errors=errors syncbuf, force_sync=force_sync, errors=errors, verbose=verbose
) )
success = syncbuf.Finish() success = syncbuf.Finish()
except GitError as e: except GitError as e:
@ -1042,7 +1043,7 @@ later is required to fix a server side protocol bug.
proc_res = self.ExecuteInParallel( proc_res = self.ExecuteInParallel(
opt.jobs_checkout, opt.jobs_checkout,
functools.partial( functools.partial(
self._CheckoutOne, opt.detach_head, opt.force_sync self._CheckoutOne, opt.detach_head, opt.force_sync, opt.verbose
), ),
all_projects, all_projects,
callback=_ProcessResults, callback=_ProcessResults,
@ -1288,7 +1289,7 @@ later is required to fix a server side protocol bug.
groups=None, groups=None,
) )
project.DeleteWorktree( project.DeleteWorktree(
quiet=opt.quiet, force=opt.force_remove_dirty verbose=opt.verbose, force=opt.force_remove_dirty
) )
new_project_paths.sort() new_project_paths.sort()
@ -1533,7 +1534,10 @@ later is required to fix a server side protocol bug.
syncbuf = SyncBuffer(mp.config) syncbuf = SyncBuffer(mp.config)
start = time.time() start = time.time()
mp.Sync_LocalHalf( mp.Sync_LocalHalf(
syncbuf, submodules=mp.manifest.HasSubmodules, errors=errors syncbuf,
submodules=mp.manifest.HasSubmodules,
errors=errors,
verbose=opt.verbose,
) )
clean = syncbuf.Finish() clean = syncbuf.Finish()
self.event_log.AddSync( self.event_log.AddSync(