@@ -560,88 +560,6 @@ def create_ignored_markdown_content(data: Dict[str, Any], reason: str) -> str:
560560 return markdown_body
561561
562562
563- def _process_files_with_git_batch (json_files , output_dir , output_modes , year_folder , verbose , git_branch , predocs , apply_links ):
564- """Process files with git batch workflow."""
565- import shutil
566- import subprocess
567- from datetime import datetime
568- import random
569- from exporters .git import clone_target_repository_to_temp
570- from exporters .git .git_utils import GIT_TIMEOUT
571-
572- # Clone target repository once for all documents
573- repo_dir , original_cwd = clone_target_repository_to_temp (verbose = verbose )
574- if repo_dir is None :
575- print ("Fel: Kunde inte klona target repository, faller tillbaka på lokal bearbetning" )
576- # Fallback to normal processing
577- for json_file in json_files :
578- try :
579- with open (json_file , 'r' , encoding = 'utf-8' ) as f :
580- data = json .load (f )
581- except (json .JSONDecodeError , FileNotFoundError ) as e :
582- print (f"Fel vid läsning av { json_file } : { e } " )
583- continue
584- make_document (data , output_dir , output_modes , year_folder , verbose , git_branch , predocs , apply_links )
585- return
586-
587- try :
588- # Change to cloned repository directory
589- os .chdir (repo_dir )
590-
591- # Create unique branch name for this batch
592- timestamp = datetime .now ().strftime ("%Y%m%d_%H%M%S" )
593- random_suffix = random .randint (1000 , 9999 )
594- unique_branch = f"{ git_branch } _batch_{ timestamp } _{ random_suffix } "
595-
596- # Create and checkout new branch directly
597- try :
598- subprocess .run (['git' , 'checkout' , '-b' , unique_branch ],
599- check = True , capture_output = True , timeout = GIT_TIMEOUT )
600- if verbose :
601- print (f"Skapade och bytte till branch '{ unique_branch } ' för batch-commits" )
602- except subprocess .CalledProcessError as e :
603- print (f"Fel: Kunde inte skapa git branch: { e } " )
604- return
605-
606- # Process each JSON file
607- for json_file in json_files :
608- # Use absolute path since we changed working directory
609- abs_json_file = Path (original_cwd ) / json_file
610- try :
611- with open (abs_json_file , 'r' , encoding = 'utf-8' ) as f :
612- data = json .load (f )
613- except (json .JSONDecodeError , FileNotFoundError ) as e :
614- print (f"Fel vid läsning av { abs_json_file } : { e } " )
615- continue
616-
617- # Create documents in the cloned repository
618- make_document (data , output_dir , output_modes , year_folder , verbose , git_branch , predocs , apply_links )
619-
620- # Push all commits to target repository
621- if verbose :
622- print (f"Pushar batch till target repository..." )
623-
624- subprocess .run (['git' , 'push' , 'origin' , unique_branch ],
625- check = True , capture_output = True , timeout = GIT_TIMEOUT )
626-
627- print (f"Batch pushad till target repository som branch '{ unique_branch } '" )
628-
629- except subprocess .CalledProcessError as e :
630- print (f"Fel vid git batch processing: { e } " )
631- if hasattr (e , 'stderr' ) and e .stderr :
632- print (f"Git stderr: { e .stderr .decode ('utf-8' , errors = 'replace' )} " )
633- except Exception as e :
634- print (f"Oväntat fel vid git batch processing: { e } " )
635- finally :
636- # Always change back to original directory
637- os .chdir (original_cwd )
638- # Clean up temporary directory
639- try :
640- shutil .rmtree (repo_dir .parent )
641- except Exception as e :
642- if verbose :
643- print (f"Varning: Kunde inte rensa temporär katalog: { e } " )
644-
645563
646564def main ():
647565 """Main function to process all JSON files in the json directory."""
@@ -733,7 +651,8 @@ def main():
733651
734652 # Handle git mode with batch processing
735653 if "git" in output_modes :
736- _process_files_with_git_batch (json_files , output_dir , output_modes , args .year_folder , args .verbose , args .git_branch , args .predocs , args .apply_links )
654+ from exporters .git import process_files_with_git_batch
655+ process_files_with_git_batch (json_files , output_dir , output_modes , args .year_folder , args .verbose , args .git_branch , args .predocs , args .apply_links )
737656 else :
738657 # Convert each JSON file normally
739658 for json_file in json_files :
0 commit comments