a ~_C"@svdZddlmZddlmZmZmZmZddlm Z m Z m Z m Z ddlZddZGdd d eZGd d d e jZdS) z!Fast export/import functionality.) commit_tree)BlobCommitTagZERO_SHA)commandserrorsparser processorNcCs|dd\}}||dfS)N <>)rsplitrstrip)textnameZemailr4/usr/lib/python3/dist-packages/dulwich/fastexport.py split_email+src@sTeZdZdZddZddZddZdd Zd d Zd d Z dddZ dddZ dS)GitFastExporterz5Generate a fast-export output stream for Git objects.cCs||_||_i|_d|_dS)Nr)outfstoremarkers _marker_idx)selfrrrrr__init__3szGitFastExporter.__init__cCs |jt|d|jddS)N __bytes__ )rwritegetattr__repr__rcmdrrr print_cmd9szGitFastExporter.print_cmdcCs |jd7_d|jfdS)Nr z%dascii)rencode)rrrr_allocate_marker<sz GitFastExporter._allocate_markercCs&|}|j|j|<t||j|fSN)r&idrrZ BlobCommanddata)rblobmarkerrrr _export_blob@s zGitFastExporter._export_blobcCs||\}}|||Sr')r,r#)rr*r"r+rrr emit_blobEs zGitFastExporter.emit_blobc cs|j||D]\\}}\}}\}}|dur:t|Vqt|sX|j|} || } ||krv|durvt||V||ks||krd| } t||| dVqdS)N:) rZ tree_changesrZFileDeleteCommandstatS_ISDIRr-ZFileRenameCommandZFileModifyCommand) r base_treeZnew_treeold_pathnew_pathZold_modeZnew_modeZ old_hexshaZ new_hexshar*r+Zprefixed_markerrrr _iter_filesJs      zGitFastExporter._iter_filesNc Cst|||j}|}|jr:|jd}|jdd}nd}g}t|j\}} t|j\} } t |||| |j |j f| | |j |j f|j|||} | |fS)Nrr )listr4treer&parentsrauthor committerrZ CommitCommand author_timeauthor_timezone commit_timecommit_timezonemessage) rcommitrefr1Z file_cmdsr+from_mergesr8 author_emailr9committer_emailr"rrr_export_commit\s$  zGitFastExporter._export_commitcCs ||||\}}|||Sr')rEr#)rr?r@r1r"r+rrr emit_commitos zGitFastExporter.emit_commit)N)N) __name__ __module__ __qualname____doc__rr#r&r,r-r4rErFrrrrr0s rc@sjeZdZdZdddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZdS)GitImportProcessorzKAn import processor that imports into a Git repository using Dulwich. NFcCs,tj|||||_t|_i|_i|_dSr')r ImportProcessorrrepor last_commitr _contents)rrMparamsverboserrrrr{s zGitImportProcessor.__init__cCs |dr|j|ddS|S)Nr.r ) startswithr)rZ objectishrrr lookup_objects z GitImportProcessor.lookup_objectcCst|}||j|jSr')r Z ImportParserZprocessZ iter_commandsr)rstreamprrr import_streams  z GitImportProcessor.import_streamcCs2t|j}|jj||jr.|j|j|j<dS)zProcess a BlobCommand.N) r from_stringr)rM object_store add_objectmarkr(r)rr"r*rrr blob_handlers zGitImportProcessor.blob_handlercCsdS)zProcess a CheckpointCommand.Nrr!rrrcheckpoint_handlersz%GitImportProcessor.checkpoint_handlercCs0t}|jdur|j}n|j}|\}}}}|j\}} } } |d|d|_||_t||_|d| d|_| |_t| |_|j|_g|_ |j r| |j |_ | |j | D]} | jdkr| jdurt| j} |jj| | j}n | | j}| j|f|j| j<q| jdkr&|j| j=q| jdkrH|j| j|j| j<q| jdkrt|j| j|j| j<|j| j=q| jdkri|_qtd | jqt|jjd d |j D|_!|j"t#kr|j $|j"|j%D]}|j $| |q|jj&||j|j|j'<|j|_"|j(r,|j|j)|j(<dS) zProcess a CommitCommand.Nr r s filemodifys filedeletesfilecopys filerenames filedeleteallzCommand %s not supportedcss |]\}\}}|||fVqdSr'r).0pathmodehexsharrr z4GitImportProcessor.commit_handler..)*rr8r9r;intr:r=r<r>r7rArS _reset_baseZ iter_filesrr)rrWrMrXaddr(Zdatarefr_rOr^Zsrc_pathZ dest_pathr2r3 Exceptionritemsr6rNrappendrBrYr@rZr)rr"r?r8Z author_namerCZauthor_timestampr;Zcommitter_namerDZcommit_timestampr=Zfilecmdr*Zblob_idmergerrrcommit_handlersp                   z!GitImportProcessor.commit_handlercCsdS)zProcess a ProgressCommand.Nrr!rrrprogress_handlersz#GitImportProcessor.progress_handlercCsZ|j|krdSi|_||_|tkrV|j|j}|jj|D]\}}}||f|j|<qtagrrMrYr(rl)rr"rnrrr tag_handlers  zGitImportProcessor.tag_handlercCst|jdS)zProcess a FeatureCommand.N)fastimport_errorsZUnknownFeatureZ feature_namer!rrrfeature_handlersz"GitImportProcessor.feature_handler)NFN)rGrHrIrJrrSrVr[r\rjrkrdrmrorqrrrrrKus 9   rK)rJZ dulwich.indexrZdulwich.objectsrrrrZ fastimportrrrpr r r/robjectrrLrKrrrrs E