@@ -472,16 +472,30 @@ def flush(self):
472472_JST = timezone (timedelta (hours = 9 ), 'JST' )
473473
474474
475- def get_latest_commit_info (path ):
476- commit_log = subprocess .check_output (['git' , 'log' , '-1' , '--date=iso' , '--pretty=format:%at %an' , path + '.md' ], cwd = settings .INPUT_DIR , text = True , errors = 'ignore' )
477- if not commit_log :
478- return None
479- timestamp , author = commit_log .split (' ' , 1 )
480- return {
481- # git の %at は Unix 時刻 (UTC の瞬間) なので JST に変換して返す。
482- 'last_updated' : datetime .fromtimestamp (int (timestamp ), _JST ),
483- 'last_author' : author ,
484- }
475+ def make_commit_info_dict ():
476+ commit_info_dict = {}
477+ # 以下の git コマンドを実行すると、すべてのコミットの情報(タイムスタンプ、著者、編集されたファイル一覧)が新しい順に出力される。
478+ # 1767193200 Author Name
479+ # path/to/file1.md
480+ # path/to/file2.md
481+ # これを解析してファイルごとの最新のコミット情報を得る。
482+ log = subprocess .check_output (['git' , 'log' , '--date=iso' , '--pretty=format:%at %an' , '--name-only' ], cwd = settings .INPUT_DIR , text = True , errors = 'ignore' )
483+ timestamp_and_author = ''
484+ for line in log .split ('\n ' ):
485+ if len (line ) == 0 :
486+ continue
487+ if line [0 ].isdecimal (): # 数字から始まるパスは無いと仮定して、先頭が数字なら、タイムスタンプと著者の行
488+ timestamp_and_author = line
489+ else : # 編集されたファイルの行
490+ path = line
491+ if path not in commit_info_dict :
492+ timestamp , author = timestamp_and_author .split (' ' , 1 )
493+ commit_info_dict [path ] = {
494+ # git の %at は Unix 時刻 (UTC の瞬間) なので JST に変換して返す。
495+ 'last_updated' : datetime .fromtimestamp (int (timestamp ), _JST ),
496+ 'last_author' : author ,
497+ }
498+ return commit_info_dict
485499
486500
487501def get_self_latest_commit_info ():
@@ -517,12 +531,12 @@ def remove_not_target_paths(paths):
517531 pass
518532
519533
520- def convert_pageinfo (pageinfo , sidebar , sidebar_index , template , hrefs , global_qualify_list , global_defined_words ):
534+ def convert_pageinfo (pageinfo , sidebar , sidebar_index , template , hrefs , global_qualify_list , global_defined_words , commit_info_dict ):
521535 path = pageinfo ['path' ]
522536 if path .count ("/" ) <= 1 :
523537 print (path )
524538
525- latest_commit_info = get_latest_commit_info (pageinfo ['path' ])
539+ latest_commit_info = commit_info_dict . get (pageinfo ['path' ] + '.md' )
526540
527541 if not settings .DISABLE_SIDEBAR :
528542 sidebar .set_active (pageinfo ['paths' ])
@@ -591,6 +605,8 @@ def main():
591605 template = env .get_template ('content.html' )
592606 hrefs = {pageinfo ['href' ] for pageinfo in pageinfos }
593607
608+ commit_info_dict = make_commit_info_dict ()
609+
594610 target_pageinfos = []
595611 for pageinfo in pageinfos :
596612 if not pageinfo ['path' ].startswith (TARGET_PREFIX ):
@@ -604,7 +620,7 @@ def main():
604620 if settings .DISABLE_SIDEBAR :
605621 def run (pageinfos ):
606622 for pageinfo in pageinfos :
607- convert_pageinfo (pageinfo , sidebar , sidebar_index , template , hrefs , global_qualify_list , global_defined_words )
623+ convert_pageinfo (pageinfo , sidebar , sidebar_index , template , hrefs , global_qualify_list , global_defined_words , commit_info_dict )
608624
609625 target_pageinfos_list = [[] for n in range (CONCURRENCY )]
610626 for i , pageinfo in enumerate (target_pageinfos ):
@@ -625,7 +641,7 @@ def run(pageinfos):
625641 else :
626642 # サイドバーを出力する場合は sidebar への書き込みが発生して怖いので普通に出力する
627643 for pageinfo in target_pageinfos :
628- convert_pageinfo (pageinfo , sidebar , sidebar_index , template , hrefs , global_qualify_list , global_defined_words )
644+ convert_pageinfo (pageinfo , sidebar , sidebar_index , template , hrefs , global_qualify_list , global_defined_words , commit_info_dict )
629645
630646 for pageinfo in pageinfos :
631647 cache .converted (pageinfo ['path' ])
0 commit comments