diff options
| author | Mike Frysinger <vapier@google.com> | 2019-08-26 15:32:06 -0400 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2019-11-12 23:33:51 +0000 |
| commit | 3538dd224d6d48c60b140103f25d94f0e5f76160 (patch) | |
| tree | 37b3c16bec3b7d7228c3040ba800377ec068e077 | |
| parent | b610b850ac2d791e193383dd77501565fca60aa4 (diff) | |
| download | git-repo-3538dd224d6d48c60b140103f25d94f0e5f76160.tar.gz | |
sync: merge project updates with status bar
The current sync output displays "Fetching project" and "Checking out
project" messages and progress bar updates independently leading to a
lot of spam. Lets merge these periodic outputs with the status bar to
get a little bit tighter output in the normal case. This doesn't solve
all our problems, but gets us closer.
Bug: https://crbug.com/gerrit/11293
Change-Id: Icd627830af4dd934a9355b7ace754b56dc96cfef
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/244934
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
| -rw-r--r-- | progress.py | 5 | ||||
| -rw-r--r-- | subcmds/sync.py | 15 |
2 files changed, 7 insertions, 13 deletions
diff --git a/progress.py b/progress.py index 1eff04ac..d2ed4bae 100644 --- a/progress.py +++ b/progress.py | |||
| @@ -39,7 +39,7 @@ class Progress(object): | |||
| 39 | self._print_newline = print_newline | 39 | self._print_newline = print_newline |
| 40 | self._always_print_percentage = always_print_percentage | 40 | self._always_print_percentage = always_print_percentage |
| 41 | 41 | ||
| 42 | def update(self, inc=1): | 42 | def update(self, inc=1, msg=''): |
| 43 | self._done += inc | 43 | self._done += inc |
| 44 | 44 | ||
| 45 | if _NOT_TTY or IsTrace(): | 45 | if _NOT_TTY or IsTrace(): |
| @@ -62,12 +62,13 @@ class Progress(object): | |||
| 62 | 62 | ||
| 63 | if self._lastp != p or self._always_print_percentage: | 63 | if self._lastp != p or self._always_print_percentage: |
| 64 | self._lastp = p | 64 | self._lastp = p |
| 65 | sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s' % ( | 65 | sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s%s%s' % ( |
| 66 | CSI_ERASE_LINE, | 66 | CSI_ERASE_LINE, |
| 67 | self._title, | 67 | self._title, |
| 68 | p, | 68 | p, |
| 69 | self._done, self._units, | 69 | self._done, self._units, |
| 70 | self._total, self._units, | 70 | self._total, self._units, |
| 71 | ' ' if msg else '', msg, | ||
| 71 | "\n" if self._print_newline else "")) | 72 | "\n" if self._print_newline else "")) |
| 72 | sys.stderr.flush() | 73 | sys.stderr.flush() |
| 73 | 74 | ||
diff --git a/subcmds/sync.py b/subcmds/sync.py index 97da6204..2973a16e 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -315,9 +315,6 @@ later is required to fix a server side protocol bug. | |||
| 315 | # We'll set to true once we've locked the lock. | 315 | # We'll set to true once we've locked the lock. |
| 316 | did_lock = False | 316 | did_lock = False |
| 317 | 317 | ||
| 318 | if not opt.quiet: | ||
| 319 | print('Fetching project %s' % project.name) | ||
| 320 | |||
| 321 | # Encapsulate everything in a try/except/finally so that: | 318 | # Encapsulate everything in a try/except/finally so that: |
| 322 | # - We always set err_event in the case of an exception. | 319 | # - We always set err_event in the case of an exception. |
| 323 | # - We always make sure we unlock the lock if we locked it. | 320 | # - We always make sure we unlock the lock if we locked it. |
| @@ -350,7 +347,7 @@ later is required to fix a server side protocol bug. | |||
| 350 | raise _FetchError() | 347 | raise _FetchError() |
| 351 | 348 | ||
| 352 | fetched.add(project.gitdir) | 349 | fetched.add(project.gitdir) |
| 353 | pm.update() | 350 | pm.update(msg=project.name) |
| 354 | except _FetchError: | 351 | except _FetchError: |
| 355 | pass | 352 | pass |
| 356 | except Exception as e: | 353 | except Exception as e: |
| @@ -371,7 +368,6 @@ later is required to fix a server side protocol bug. | |||
| 371 | fetched = set() | 368 | fetched = set() |
| 372 | lock = _threading.Lock() | 369 | lock = _threading.Lock() |
| 373 | pm = Progress('Fetching projects', len(projects), | 370 | pm = Progress('Fetching projects', len(projects), |
| 374 | print_newline=not(opt.quiet), | ||
| 375 | always_print_percentage=opt.quiet) | 371 | always_print_percentage=opt.quiet) |
| 376 | 372 | ||
| 377 | objdir_project_map = dict() | 373 | objdir_project_map = dict() |
| @@ -461,9 +457,6 @@ later is required to fix a server side protocol bug. | |||
| 461 | # We'll set to true once we've locked the lock. | 457 | # We'll set to true once we've locked the lock. |
| 462 | did_lock = False | 458 | did_lock = False |
| 463 | 459 | ||
| 464 | if not opt.quiet: | ||
| 465 | print('Checking out project %s' % project.name) | ||
| 466 | |||
| 467 | # Encapsulate everything in a try/except/finally so that: | 460 | # Encapsulate everything in a try/except/finally so that: |
| 468 | # - We always set err_event in the case of an exception. | 461 | # - We always set err_event in the case of an exception. |
| 469 | # - We always make sure we unlock the lock if we locked it. | 462 | # - We always make sure we unlock the lock if we locked it. |
| @@ -474,11 +467,11 @@ later is required to fix a server side protocol bug. | |||
| 474 | try: | 467 | try: |
| 475 | try: | 468 | try: |
| 476 | project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync) | 469 | project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync) |
| 477 | success = syncbuf.Finish() | ||
| 478 | 470 | ||
| 479 | # Lock around all the rest of the code, since printing, updating a set | 471 | # Lock around all the rest of the code, since printing, updating a set |
| 480 | # and Progress.update() are not thread safe. | 472 | # and Progress.update() are not thread safe. |
| 481 | lock.acquire() | 473 | lock.acquire() |
| 474 | success = syncbuf.Finish() | ||
| 482 | did_lock = True | 475 | did_lock = True |
| 483 | 476 | ||
| 484 | if not success: | 477 | if not success: |
| @@ -487,7 +480,7 @@ later is required to fix a server side protocol bug. | |||
| 487 | file=sys.stderr) | 480 | file=sys.stderr) |
| 488 | raise _CheckoutError() | 481 | raise _CheckoutError() |
| 489 | 482 | ||
| 490 | pm.update() | 483 | pm.update(msg=project.name) |
| 491 | except _CheckoutError: | 484 | except _CheckoutError: |
| 492 | pass | 485 | pass |
| 493 | except Exception as e: | 486 | except Exception as e: |
| @@ -527,7 +520,7 @@ later is required to fix a server side protocol bug. | |||
| 527 | syncjobs = 1 | 520 | syncjobs = 1 |
| 528 | 521 | ||
| 529 | lock = _threading.Lock() | 522 | lock = _threading.Lock() |
| 530 | pm = Progress('Syncing work tree', len(all_projects)) | 523 | pm = Progress('Checking out projects', len(all_projects)) |
| 531 | 524 | ||
| 532 | threads = set() | 525 | threads = set() |
| 533 | sem = _threading.Semaphore(syncjobs) | 526 | sem = _threading.Semaphore(syncjobs) |
