@@ -1214,6 +1214,38 @@ def stream_lock_names(streams: str) -> tuple[str, ...]:
12141214 return (streams ,)
12151215
12161216
1217+ def populate_code_source_cache (
1218+ work_root : Path ,
1219+ source_cache_dir : Path ,
1220+ should_process ,
1221+ progress : ProgressWriter ,
1222+ * ,
1223+ max_repos : int | None = None ,
1224+ ) -> dict :
1225+ """Populate the code source cache without running index/tokenize stages."""
1226+ started = time .monotonic ()
1227+ report = sr .populate_source_cache (
1228+ work_root ,
1229+ should_process ,
1230+ source_cache_dir ,
1231+ max_repos = max_repos ,
1232+ )
1233+ for idx , item in enumerate (report ["repos" ], start = 1 ):
1234+ progress .emit (
1235+ "source_cache_repo_ready" ,
1236+ repo = item ["repo" ],
1237+ repo_dir = item ["path" ],
1238+ source_cache_dir = str (source_cache_dir ),
1239+ repo_count = idx ,
1240+ )
1241+ report = {
1242+ ** report ,
1243+ "elapsed_s" : round (time .monotonic () - started , 6 ),
1244+ }
1245+ progress .emit ("source_cache_populated" , ** report )
1246+ return report
1247+
1248+
12171249# --------------------------------------------------------------------------- #
12181250# CODE half: orchestrate streaming_reindex.process_one_repo (no reimplementation).
12191251# Its append_output already lands outputs/reindexed/<L>/<repo>.parquet; we then
@@ -2402,6 +2434,10 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
24022434 help = "For --streams code, only process complete repos already "
24032435 "in --source-cache-dir; do not open/decompress the source "
24042436 "tarball." )
2437+ p .add_argument ("--source-cache-populate-only" , action = "store_true" ,
2438+ help = "For --streams code, populate --source-cache-dir from "
2439+ "the source tarball and exit without indexing/tokenizing. "
2440+ "Follow with --source-cache-only for hot code runs." )
24052441 p .add_argument ("--source-dir-root" , action = "append" , default = [],
24062442 help = "For --streams code, process already-extracted repo dirs "
24072443 "directly without opening the source tarball. May be passed "
@@ -2469,6 +2505,12 @@ def main(argv: list[str]) -> int:
24692505 source_dir_roots = [Path (p ) for p in args .source_dir_root ]
24702506 if args .source_cache_only and source_cache_dir is None :
24712507 raise SystemExit ("--source-cache-only requires --source-cache-dir" )
2508+ if args .source_cache_populate_only and source_cache_dir is None :
2509+ raise SystemExit ("--source-cache-populate-only requires --source-cache-dir" )
2510+ if args .source_cache_populate_only and args .source_cache_only :
2511+ raise SystemExit ("--source-cache-populate-only cannot be combined with --source-cache-only" )
2512+ if args .source_cache_populate_only and args .streams != "code" :
2513+ raise SystemExit ("--source-cache-populate-only is only valid with --streams code" )
24722514 if args .source_cache_only and args .streams != "code" :
24732515 raise SystemExit ("--source-cache-only is only valid with --streams code" )
24742516 if source_cache_dir is not None and args .streams != "code" :
@@ -2659,6 +2701,7 @@ def _on_signal(signum, _frame):
26592701 code_recompress_workers = args .code_recompress_workers if code_recompressor else 0 ,
26602702 source_cache_dir = str (source_cache_dir ) if source_cache_dir is not None else None ,
26612703 source_cache_only = args .source_cache_only ,
2704+ source_cache_populate_only = args .source_cache_populate_only ,
26622705 source_dir_roots = [str (p ) for p in source_dir_roots ],
26632706 reservation_file = str (args .reservation_file )
26642707 if reservations is not None else None ,
@@ -2737,6 +2780,42 @@ def should_process(repo: str) -> bool:
27372780 )
27382781 return should_stage
27392782
2783+ if args .source_cache_populate_only :
2784+ try :
2785+ report = populate_code_source_cache (
2786+ work_root ,
2787+ source_cache_dir ,
2788+ should_process ,
2789+ progress ,
2790+ max_repos = args .max_repos ,
2791+ )
2792+ summary = {
2793+ "repos_this_run" : 0 ,
2794+ "code_halves_this_run" : 0 ,
2795+ "commit_ranges_this_run" : 0 ,
2796+ "commit_ranges_failed_this_run" : 0 ,
2797+ "workers" : workers ,
2798+ "repo_workers" : repo_workers ,
2799+ "max_active_repos" : max_active_repos ,
2800+ "parse_workers" : parse_workers ,
2801+ "memory_plan" : memory_plan ,
2802+ "streams" : args .streams ,
2803+ "source_cache_populate_only" : True ,
2804+ "source_cache_report" : report ,
2805+ "manifest" : str (CONVEYOR_MANIFEST ),
2806+ "interrupted" : STOP_EVENT .is_set (),
2807+ }
2808+ progress .emit ("run_finished" , ** summary )
2809+ print (json .dumps (summary , indent = 2 ))
2810+ return 130 if STOP_EVENT .is_set () else 0
2811+ finally :
2812+ if code_recompressor is not None :
2813+ code_recompressor .shutdown ()
2814+ if own_work_root and not args .keep_temp :
2815+ remove_tree (work_root , reason = "source-cache populate work_root" )
2816+ for lock in reversed (run_locks ):
2817+ lock .close ()
2818+
27402819 range_pool = ThreadPoolExecutor (max_workers = workers )
27412820 repo_pool = ThreadPoolExecutor (max_workers = repo_workers ) if repo_workers > 1 else None
27422821
0 commit comments