yL iAdZgdZddlmZddlZddlmZddlm Z ddl m Z m Z m Z mZmZmZmZddlZddlZddlmZddlmZdd lmZmZdd lmZmZmZmZdd l m!Z!m"Z"dd l#m$Z$m%Z%m&Z&dd l'm(Z(m)Z)ddl*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0m1Z1ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddlm?Z?ddl@mAZAddlBmCZCe e zZD e-ZEdeFde=deFfdZGdeFdeFfdZHdeFdddeFddfdZId eJdeJfd!ZKde(fd"e6e:e+d#fd$e4eLd%e:deLfd&e9e(ddf d'ZMd$e4eLde8eJeJffd(ZNd)e:e+e=eJfde8e=eJffd*ZOd$e4eLde8eJe3e8e=eJfd#feLeLffd+ZP d7d"e5e,d,d-d.eQd/eJde8eLe5d0ff d1ZRd2d0d3eJde+fd4ZSd,d-d5e6eLde5e+fd6ZTy)8zVStandalone functions to accompany the index implementation and make it more versatile.) write_cache read_cachewrite_tree_from_cache entry_keystat_mode_to_index_mode S_IFGITLINKrun_commit_hook hook_path)BytesION)Path)S_IFDIRS_IFLNKS_IFMTS_IFREGS_ISDIRS_ISLNKS_IXUSR)IStream) str_tree_type)handle_process_output safer_popen)defenc force_bytes force_text safe_decode)HookExecutionErrorUnmergedEntriesError)traverse_tree_recursivetraverse_trees_recursivetree_to_stream)IndexFileSHA1Writerfinalize_process)BaseIndexEntry IndexEntry CE_NAMEMASK CE_STAGESHIFT)packunpack) DictIOListSequence TYPE_CHECKINGTupleTypeUnioncast)PathLike)GitCmdObjectDB) TreeCacheTup) IndexFilenamegit_dirreturnc0tj|d|S)zK:return: path to the given named hook in the given git repository directoryhooks)ospjoin)r7r8s S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/git/index/fun.pyr r >s 88GWd ++pathc2tj|dS)Nr#)r<splitext)r@s r>_has_file_extensionrCCs << a  r?indexr6argsct||jj}tj|tj sytj j}tt|j|d<d|d<|g} tjdk(rKt|s@t|j|jj j#}d|g}t%|t'|z|t(j*t(j*|jj }g}g} t-||j.| j.t0dj3|} dj3| } |j4d k7r8t7| t8} t7| t8} t;||j4| | y#t<$r} t;|| | d} ~ wwxYw) a:Run the commit hook of the given name. Silently ignore hooks that do not exist. :param name: Name of hook, like ``pre-commit``. :param index: :class:`~git.index.base.IndexFile` instance. :param args: Arguments passed to hook file. :raise git.exc.HookExecutionError: NGIT_INDEX_FILE: GIT_EDITORwin32zbash.exe)envstdoutstderrcwdr )r repor8osaccessX_OKenvironcopyrstrr@sysplatformrCr relative_to working_diras_posixrlist subprocessPIPErappendr"r= returncoderrr Exception) r7rDrEhprKcmd relative_hpprocess stdout_list stderr_listrLrMexs r>rrGs 4++ ,B 99R ! **// C'EJJ8CC  $CM <<7 "+>r+Br(..uzz/E/EFOOQK{+C $t* ???? &&  "$ !# g{'9'9;;M;MO_`%%    "/F/F$R););VVL L # 1 R(b01sB*G G' G""G'modect|rtSt|st|tk(rtSt |t zxrdxsdzS)zZConvert the given mode from a stat call to the corresponding index mode and return it.ii)rrrrrrr)ris r>rrzsAt}t}t 3 dWn.7% 88r?entriesr%streamextension_data ShaStreamClsc8||}|j}|j}d}|d|td|t||D]+}|} ||j||j t |j} t| t} t| tz} | t| k(sJd|jz| |jtzz} |td|j|j|j|j |j"|j$|j&| || || z dzdz}|d | |z|z z.||j||j)y ) aWrite the cache represented by entries to a stream. :param entries: **Sorted** list of entries. :param stream: Stream to wrap into the AdapterStreamCls - it is used for final output. :param ShaStreamCls: Type to use when writing to the stream. It produces a sha while writing to it, before the data is passed on to the wrapped stream. :param extension_data: Any kind of data to write as a trailer, it must begin a 4 byte identifier, followed by its size (4 bytes). DIRC>LL)encodingz"Path %s too long to fit into index >LLLLLL20sHN)tellwriter(len ctime_bytes mtime_bytesrVr@rrr&flagsCE_NAMEMASK_INVdevinoderiuidgidsizebinsha write_sha)rkrlrmrn stream_sharxryversionentry beginoffsetpath_strr@plenr} real_sizes r>rrsw.f%J ??D   EG 'N $ugs7| ,-<f  e  e uzz?!(V<4y;&s4y S"F"SS  o56           d Vk)A-3  e i/469:;1<8!(r?c |jd}|dk7rtd|zttttft d|jd}|\}}|dvs Jd|z||fS)z>Return tuple(version_long, num_entries) from the given stream.rqzInvalid index file header: %rrrrur#rpz read_headerrs}kk!nG'` dictionary. :param entry: One instance of type BaseIndexEntry or the path and the stage. r#r ) rz isinstancer$r@stager2r/r3r)r entry_firsts r>rrs[ 5zQAh +~666  +"3"344U8S=)51 r?c nt|\}}d}i}|j}|j}||kr|}td|dd}td|dd} td|d\} } } } }}}}|tz}||j t }||z dzdz}|||z|z t| ||||| | | | ||f }||||jf<|dz }||kr|jd}t|d kDsJd t|z|d d }|d d }||||fS) aRead a cache file from the given stream. :return: tuple(version, entries_dict, extension_data, content_sha) * *version* is the integer version number. * *entries_dict* is a dictionary which maps IndexEntry instances to a path at a stage. * *extension_data* is ``""`` or 4 bytes of type + 4 bytes of size + size bytes. * *content_sha* is a 20 byte sha on all cache file contents. r z>8srurt.rvr#zNIndex Footer was not at least a sha on content as it was only %i bytes in sizeiN) rrrxr)r&decoderr%rrz)rlrrcountrkrrxrctimemtimerinorirrrshar} path_sizer@rrrm content_shas r>rrs'v.G[ E8:G ;;D ;;D + f ud1g&q)ud1g&q)7=mTR`Ma7b4c4c4eK' I%%f-Vk)A-3  kI% /0D#udE5#sCQTVZ[\',u{{#$   + ,[[_N ~  #X[^_m[nn #!&K$DS)N Wnk ::r?odbr4slsir5c \g}|j}|j}||kr||}|jdk7r t||dz }|jj d|}|dk(r6|j |j|j|j|dfn|j||} |} | |krD|| } | jj d|} | dk(s| j|| | k7rn | dz } | |krDt||t|dz | |dz\} }|j | t| f| }||krt}t||j|jd|j!t#t$t'|j)|}|j|fS)aNCreate a tree from the given sorted list of entries and put the respective trees into the given object database. :param entries: **Sorted** list of :class:`~git.index.typ.IndexEntry`\s. :param odb: Object database to store the trees in. :param si: Start index at which we should start creating subtrees. :param sl: Slice indicating the range we should process on the entries list. :return: tuple(binsha, list(tree_entry, ...)) A tuple of a sha and a list of tree entries being a tuple of hexsha, mode, name. r r#/rN)startstoprrr@findr_rrirslicer r r ryseekstorerrrzgetvalue)rkrrr tree_itemsciendrrboundbasexioentryorboundr_tree_entry_listsioistreams r>rr%s.(*J B ''C s(  ;;! &u- - ab) R<   u||UZZBCI J::b(DBs(  ++**33b=FKK7$;t$Ca s(%:'3bSTfVXHY[ade[e$f !C!   sGT2 3B; s(D )C:syy)HHQKii s3<<>/BCHIG NNJ ''r? tree_entryrc@t|d|d|tz|dfS)Nr#r rp)r$r')rrs r>_tree_entry_to_baseindexentryrjs* :a=*Q--9OQ[\]Q^_ ``r? tree_shasctg}t|dvr2t||ddD]}|jt|d|St|dkDrt dt|zt ||dD]@\}}}||4||d|dk7r|d|dk7r |d|dk7s!|d|dk7rh|d|dk7r]|d|dk7rR|jt|d|jt|d|jt|d|d|dk7s |d|dk7r|jt|d|jt|d|d|dk7s |d|dk7s |jt|d|jt|dB|F|d|dk7s |d|dk7s^|jt|d|jt|d|!|J|jt|d||jt|d|d|dk7s |d|dk7r8|jt|d|jt|d&|jt|dC|S) a7 :return: List of :class:`~git.index.typ.BaseIndexEntry`\s representing the aggressive merge of the given trees. All valid entries are on stage 0, whereas the conflicting ones are left on stage 1, 2 or 3, whereas stage 1 corresponds to the common ancestor tree, 2 to our tree and 3 to 'their' tree. :param tree_shas: 1, 2 or 3 trees as identified by their binary 20 byte shas. If 1 or two, the entries will effectively correspond to the last given tree. If 3 are given, a 3 way merge is performed. rrrOr zCannot handle %i trees at oncer#rp)rzrr_r ValueErrorr)rroutrrourstheirss r>aggressive_tree_mergerns!#C 9~,S)B-D @E JJ4UA> ? @  9~9C NJKK7sIrJAGdF  %Q47*tAw&)/CQSYZ[S\H\Q47*tAw&)/CQSYZ[S\H\ #@q#IJ #@q#IJ #@#KLaDG+tAw$q'/A #@q#IJ #@#KLAw$q')T!WQ-? #@q#IJ #@q#IJ>ayDG+vayDG/C #@q#IJ #@#KL|))) 8CD 8qAB7fQi'47fQi+?JJrsm  MMM #6CC< ;GGUTT%- ,,C,(,s, !c!c!/M#/Mk/M#/M$/Mf9#9#9*..A B eNL89 :B uIB$+&B*+ B  BJ  5  eCHo  eNHc9:uXs]?S04; uI4; 3U8S=)<78% FG4;pLMB( * B($4B(:?B(EHB( 5$~& &'B(JanaSa^ac/cHUOcPTUcPdcr?