summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py39
1 files changed, 36 insertions, 3 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 8f73d27f..da9918b9 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -66,7 +66,7 @@ from command import (
66from error import RepoChangedException, GitError 66from error import RepoChangedException, GitError
67import platform_utils 67import platform_utils
68from project import SyncBuffer 68from project import SyncBuffer
69from progress import Progress 69from progress import Progress, elapsed_str
70from repo_trace import Trace 70from repo_trace import Trace
71import ssh 71import ssh
72from wrapper import Wrapper 72from wrapper import Wrapper
@@ -596,7 +596,7 @@ later is required to fix a server side protocol bug.
596 The projects we're given share the same underlying git object store, so 596 The projects we're given share the same underlying git object store, so
597 we have to fetch them in serial. 597 we have to fetch them in serial.
598 598
599 Delegates most of the work to _FetchHelper. 599 Delegates most of the work to _FetchOne.
600 600
601 Args: 601 Args:
602 opt: Program options returned from optparse. See _Options(). 602 opt: Program options returned from optparse. See _Options().
@@ -615,6 +615,8 @@ later is required to fix a server side protocol bug.
615 Whether the fetch was successful. 615 Whether the fetch was successful.
616 """ 616 """
617 start = time.time() 617 start = time.time()
618 k = f"{project.name} @ {project.relpath}"
619 self._sync_dict[k] = start
618 success = False 620 success = False
619 remote_fetched = False 621 remote_fetched = False
620 buf = io.StringIO() 622 buf = io.StringIO()
@@ -660,15 +662,31 @@ later is required to fix a server side protocol bug.
660 % (project.name, type(e).__name__, str(e)), 662 % (project.name, type(e).__name__, str(e)),
661 file=sys.stderr, 663 file=sys.stderr,
662 ) 664 )
665 del self._sync_dict[k]
663 raise 666 raise
664 667
665 finish = time.time() 668 finish = time.time()
669 del self._sync_dict[k]
666 return _FetchOneResult(success, project, start, finish, remote_fetched) 670 return _FetchOneResult(success, project, start, finish, remote_fetched)
667 671
668 @classmethod 672 @classmethod
669 def _FetchInitChild(cls, ssh_proxy): 673 def _FetchInitChild(cls, ssh_proxy):
670 cls.ssh_proxy = ssh_proxy 674 cls.ssh_proxy = ssh_proxy
671 675
676 def _GetLongestSyncMessage(self):
677 if len(self._sync_dict) == 0:
678 return None
679
680 earliest_time = float("inf")
681 earliest_proj = None
682 for project, t in self._sync_dict.items():
683 if t < earliest_time:
684 earliest_time = t
685 earliest_proj = project
686
687 elapsed = time.time() - earliest_time
688 return f"{elapsed_str(elapsed)} {earliest_proj}"
689
672 def _Fetch(self, projects, opt, err_event, ssh_proxy): 690 def _Fetch(self, projects, opt, err_event, ssh_proxy):
673 ret = True 691 ret = True
674 692
@@ -681,8 +699,22 @@ later is required to fix a server side protocol bug.
681 delay=False, 699 delay=False,
682 quiet=opt.quiet, 700 quiet=opt.quiet,
683 show_elapsed=True, 701 show_elapsed=True,
702 elide=True,
684 ) 703 )
685 704
705 self._sync_dict = multiprocessing.Manager().dict()
706 sync_event = _threading.Event()
707
708 def _MonitorSyncLoop():
709 while True:
710 pm.update(inc=0, msg=self._GetLongestSyncMessage())
711 if sync_event.wait(timeout=1):
712 return
713
714 sync_progress_thread = _threading.Thread(target=_MonitorSyncLoop)
715 sync_progress_thread.daemon = True
716 sync_progress_thread.start()
717
686 objdir_project_map = dict() 718 objdir_project_map = dict()
687 for project in projects: 719 for project in projects:
688 objdir_project_map.setdefault(project.objdir, []).append(project) 720 objdir_project_map.setdefault(project.objdir, []).append(project)
@@ -712,7 +744,7 @@ later is required to fix a server side protocol bug.
712 ret = False 744 ret = False
713 else: 745 else:
714 fetched.add(project.gitdir) 746 fetched.add(project.gitdir)
715 pm.update(msg=f"Last synced: {project.name}") 747 pm.update()
716 if not ret and opt.fail_fast: 748 if not ret and opt.fail_fast:
717 break 749 break
718 return ret 750 return ret
@@ -764,6 +796,7 @@ later is required to fix a server side protocol bug.
764 # crash. 796 # crash.
765 del Sync.ssh_proxy 797 del Sync.ssh_proxy
766 798
799 sync_event.set()
767 pm.end() 800 pm.end()
768 self._fetch_times.Save() 801 self._fetch_times.Save()
769 802