11# -*- coding: utf-8 -*-
22
3+ from concurrent .futures import ThreadPoolExecutor , as_completed
34from typing import List
45from PySide6 .QtGui import (
56 QColor ,
@@ -461,7 +462,7 @@ class CheckLocalChangesThread(QThread):
461462 def __init__ (self , branch , submodules , parent = None ):
462463 super ().__init__ (parent )
463464 self ._branch = branch
464- self ._submodules = submodules or [ None ]
465+ self ._submodules = submodules
465466
466467 def run (self ):
467468 if self .isInterruptionRequested ():
@@ -470,41 +471,59 @@ def run(self):
470471 lccCommit = Commit ()
471472 lucCommit = Commit ()
472473
473- for submodule in self ._submodules :
474- if self .isInterruptionRequested ():
475- return
476- hasLCC , hasLUC = self .fetchLocalChanges (submodule )
477- if hasLCC :
478- lccCommit .sha1 = Git .LCC_SHA1
479- if not lccCommit .repoDir :
480- lccCommit .repoDir = submodule
481- else :
482- subCommit = Commit ()
483- subCommit .sha1 = Git .LCC_SHA1
484- subCommit .repoDir = submodule
485- lccCommit .subCommits .append (subCommit )
486-
487- if hasLUC :
488- lucCommit .sha1 = Git .LUC_SHA1
489- if not lucCommit .repoDir :
490- lucCommit .repoDir = submodule
491- else :
492- subCommit = Commit ()
493- subCommit .sha1 = Git .LUC_SHA1
494- subCommit .repoDir = submodule
495- lucCommit .subCommits .append (subCommit )
474+ if not self ._submodules :
475+ hasLCC , hasLUC , _ = self .fetchLocalChanges ()
476+ self .makeCommits (lccCommit , lucCommit , hasLCC , hasLUC )
477+ else :
478+ executor = ThreadPoolExecutor ()
479+ tasks = []
480+ for submodule in self ._submodules :
481+ if self .isInterruptionRequested ():
482+ return
483+ task = executor .submit (self .fetchLocalChanges , submodule )
484+ tasks .append (task )
485+
486+ for task in as_completed (tasks ):
487+ if self .isInterruptionRequested ():
488+ return
489+ hasLCC , hasLUC , repoDir = task .result ()
490+ self .makeCommits (lccCommit , lucCommit , hasLCC , hasLUC , repoDir )
496491
497492 if not self .isInterruptionRequested ():
498493 self .checkFinished .emit (lccCommit , lucCommit )
499494
500495 def fetchLocalChanges (self , repoDir = None ):
501- hasLCC = Git .hasLocalChanges (self ._branch , True , repoDir )
496+ repoPath = repoDir
497+ if repoPath :
498+ repoPath = os .path .join (Git .REPO_DIR , repoDir )
499+ hasLCC = Git .hasLocalChanges (self ._branch , True , repoPath )
502500 if self .isInterruptionRequested ():
503- return False , False
504- hasLUC = Git .hasLocalChanges (self ._branch , repoDir = repoDir )
501+ return False , False , repoDir
502+ hasLUC = Git .hasLocalChanges (self ._branch , repoDir = repoPath )
505503 if self .isInterruptionRequested ():
506- return False , False
507- return hasLCC , hasLUC
504+ return False , False , repoDir
505+ return hasLCC , hasLUC , repoDir
506+
507+ def makeCommits (self , lccCommit : Commit , lucCommit : Commit , hasLCC , hasLUC , repoDir = None ):
508+ if hasLCC :
509+ lccCommit .sha1 = Git .LCC_SHA1
510+ if not lccCommit .repoDir :
511+ lccCommit .repoDir = repoDir
512+ else :
513+ subCommit = Commit ()
514+ subCommit .sha1 = Git .LCC_SHA1
515+ subCommit .repoDir = repoDir
516+ lccCommit .subCommits .append (subCommit )
517+
518+ if hasLUC :
519+ lucCommit .sha1 = Git .LUC_SHA1
520+ if not lucCommit .repoDir :
521+ lucCommit .repoDir = repoDir
522+ else :
523+ subCommit = Commit ()
524+ subCommit .sha1 = Git .LUC_SHA1
525+ subCommit .repoDir = repoDir
526+ lucCommit .subCommits .append (subCommit )
508527
509528
510529class LogGraph (QWidget ):
0 commit comments