#!/usr/bin/env python3 import json import subprocess import sys from pathlib import Path from concurrent.futures import ThreadPoolExecutor, as_completed # — CONFIG — # files per batch BATCH_SIZE = 200 # number of parallel git lfs processes WORKERS = 8 # — /CONFIG — def chunk_list(lst, size): """Yield successive `size`-sized chunks from lst.""" for i in range(0, len(lst), size): yield lst[i:i+size] def pull_batch(batch, batch_idx): """Run one `git lfs pull --include=…` for this batch.""" include_arg = ",".join(batch) cmd = ["git", "lfs", "pull", "--include", include_arg] try: subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) return batch_idx, True, None except subprocess.CalledProcessError as e: return batch_idx, False, e.stderr def main(jsonl_path: Path): # 1) load and dedupe file_name entries file_names = set() with jsonl_path.open(encoding="utf-8") as f: for line in f: try: rec = json.loads(line) fn = rec.get("file_name") if fn: file_names.add(fn) except json.JSONDecodeError: continue if not file_names: print("No file_name fields found.", file=sys.stderr) sys.exit(1) sorted_files = sorted(file_names) batches = list(chunk_list(sorted_files, BATCH_SIZE)) total = len(batches) # 2) run them in parallel print(f"▶️ Pulling {len(sorted_files)} files in {total} batches, {WORKERS} at a time…\n") with ThreadPoolExecutor(max_workers=WORKERS) as executor: futures = { executor.submit(pull_batch, batch, idx): idx for idx, batch in enumerate(batches, start=1) } for fut in as_completed(futures): idx, success, err = fut.result() if success: print(f"[{idx}/{total}] ✅") else: print(f"[{idx}/{total}] ❌ error:\n{err}", file=sys.stderr) print("\nAll done.") if __name__ == "__main__": if len(sys.argv) != 2: print(f"Usage: {sys.argv[0]} path/to/your.jsonl", file=sys.stderr) sys.exit(1) path = Path(sys.argv[1]) if not path.is_file(): print(f"File not found: {path}", file=sys.stderr) sys.exit(1) main(path)