ó
    ‘óýj(B  ã                   óN  • S r / SQrSSKrSSKrSSKrSSKJr  \(       a  SSKJr  SSK	J
r
  S\S\4S	 jrS
\S\4S jrS
\S\\\\\4      4S jrS
\S\4S jrS
\S\4S jr " S S5      rSSS\4S jrSSS\4S jr SSSS\\-  S\\   SSS\\\\\4      \\   4   4
S jjrg)aK  Git rerere (reuse recorded resolution) implementation.

This module implements Git's rerere functionality, which records and reuses
manual conflict resolutions. When a merge conflict occurs, rerere records the
conflict and the resolution. If the same conflict happens again, rerere can
automatically apply the recorded resolution.
)ÚRerereCacheÚis_rerere_autoupdateÚis_rerere_enabledÚrerere_autoé    N)ÚTYPE_CHECKING)ÚConfig)ÚRepoÚpreimageÚreturnc                 óJ   • [         R                  " U 5      R                  5       $ )a  Compute a unique ID for a conflict based on its preimage.

The preimage is the conflict with all conflict markers normalized
to a canonical form (without side names).

Args:
    preimage: The normalized conflict content

Returns:
    Hex digest of the SHA-1 hash
)ÚhashlibÚsha1Ú	hexdigest)r
   s    Ú9/usr/local/lib/python3.13/site-packages/dulwich/rerere.pyÚ_compute_conflict_idr   /   s   € ô �<Š<˜Ó!×+Ñ+Ó-Ð-ó    Úcontentc                 óT  • U R                  S5      n/ nU H  nUR                  S5      (       a  UR                  S5        M,  UR                  S5      (       a  UR                  S5        MU  US:X  a  UR                  U5        Mn  UR                  U5        M�     SR                  U5      $ )a0  Normalize conflict markers to a canonical form.

This removes the side names (ours/theirs) from conflict markers
to create a preimage that only depends on the structure of the conflict.

Args:
    content: File content with conflict markers

Returns:
    Normalized content with generic conflict markers
ó   
ó   <<<<<<<ó   >>>>>>>ó   =======©ÚsplitÚ
startswithÚappendÚjoin)r   ÚlinesÚresultÚlines       r   Ú_normalize_conflict_markersr!   >   sˆ   € ð �M‰M˜%Ó €EØ€Fãˆà�?‰?˜:×&Ñ&Ø�M‰M˜*Ö%à�_‰_˜Z×(Ñ(Ø�M‰M˜*Ö%à�ZÓØ�M‰M˜$Öà�M‰M˜$Öñ ð �:‰:�fÓÐr   c                 ó   • / nU R                  S5      nSnU[        U5      :  Gah  X#   R                  S5      (       Ga8  / n/ nUS-  nU[        U5      :  aY  X#   R                  S5      (       dA  UR                  X#   5        US-  nU[        U5      :  a  X#   R                  S5      (       d  MA  U[        U5      :¼  a   U$ US-  nU[        U5      :  aY  X#   R                  S5      (       dA  UR                  X#   5        US-  nU[        U5      :  a  X#   R                  S5      (       d  MA  U[        U5      :¼  a   U$ SR	                  U5      nSR	                  U5      nUR                  USU45        US-  nU[        U5      :  a  GMh  U$ )z³Extract conflict regions from file content.

Args:
    content: File content with conflict markers

Returns:
    List of tuples (ours, separator, theirs) for each conflict region
r   r   r   é   r   r   )r   Úlenr   r   r   )r   Ú	conflictsr   ÚiÚ
ours_linesÚtheirs_linesÚoursÚtheirss           r   Ú_extract_conflict_regionsr+   ]   sˆ  € ð €IØ�M‰M˜%Ó €EØ	€Aà
Œc�%‹jŒ.Ø‰8×Ñ˜z×*Ò*àˆJØˆLØ�‰FˆAð ”c˜%“j“.¨©×)<Ñ)<¸Z×)HÑ)HØ×!Ñ! %¡(Ô+Ø�Q‘�ð ”c˜%“j“.¨©×)<Ñ)<¸Z×)HÓ)Hð ”C˜“J‹Øð& Ðð! �‰FˆAð ”c˜%“j“.¨©×)<Ñ)<¸Z×)HÑ)HØ×#Ñ# E¡HÔ-Ø�Q‘�ð ”c˜%“j“.¨©×)<Ñ)<¸Z×)HÓ)Hð ”C˜“J‹Øð Ðð —:‘:˜jÓ)ˆDØ—Z‘Z Ó-ˆFØ×Ñ˜d J°Ð7Ô8à	ˆQ‰ˆð= Œc�%‹jŽ.ð@ Ðr   c                 ó<   • SU ;   =(       a    SU ;   =(       a    SU ;   $ )z‰Check if content contains conflict markers.

Args:
    content: File content to check

Returns:
    True if conflict markers are present
r   r   r   © )r   s    r   Ú_has_conflict_markersr.   �   s#   € ð ˜Ñ ×T Z°7Ñ%:×T¸zÈWÑ?TÐTr   c                 ó  • U R                  S5      n/ nSnU HY  nUR                  S5      (       a  SnM  UR                  S5      (       a  SnM7  US:X  a  M?  U(       a  MH  UR                  U5        M[     SR                  U5      $ )zòRemove all conflict markers from resolved content.

This is used to extract the resolution from a file that has been
manually resolved by the user.

Args:
    content: Resolved file content

Returns:
    Content with conflict markers removed
r   Fr   Tr   r   r   )r   r   r   Úin_conflictr    s        r   Ú_remove_conflict_markersr1   ™   s�   € ð �M‰M˜%Ó €EØ€FØ€KãˆØ�?‰?˜:×&Ñ&ØˆKÙØ�_‰_˜Z×(Ñ(ØˆKÙØ�ZÓÙçˆ{Ø�M‰M˜$Öñ ð �:‰:�fÓÐr   c                   ót  • \ rS rSrSrS\\-  SS4S jr\SS j5       r	SS jr
S	\S\4S
 jrS	\S\4S jrS	\S\4S jrS\S\S\S-  4S jrS	\S\SS4S jrS	\S\4S jrS	\S\S-  4S jrS	\S\S\S-  4S jrS	\SS4S jrSS jrSS\SS4S jjrS\\\\4      4S jrS	\S\\S-  \S-  4   4S jrSrg)r   é¹   z+Manages the rerere cache in .git/rr-cache/.Úrr_cache_dirr   Nc                 ór   • [        U[        5      (       a  [        R                  " U5      U l        gXl        g)zUInitialize RerereCache.

Args:
    rr_cache_dir: Path to the .git/rr-cache directory
N)Ú
isinstanceÚbytesÚosÚfsdecoder4   )Úselfr4   s     r   Ú__init__ÚRerereCache.__init__¼   s(   € ô �l¤E×*Ñ*Ü "§¢¨LÓ 9ˆDÕà ,Õr   c                 ón   • [         R                  R                  UR                  5       S5      nU " U5      $ )z‹Create a RerereCache from a repository.

Args:
    repo: A Dulwich repository object

Returns:
    RerereCache instance for the repository
zrr-cache)r8   Úpathr   Ú
controldir)ÚclsÚrepor4   s      r   Ú	from_repoÚRerereCache.from_repoÇ   s*   € ô —w‘w—|‘| D§O¡OÓ$5°zÓBˆÙ�<Ó Ð r   c                 óB   • [         R                  " U R                  SS9  g)z%Ensure the rr-cache directory exists.T©Úexist_okN)r8   Úmakedirsr4   )r:   s    r   Ú_ensure_cache_dirÚRerereCache._ensure_cache_dirÔ   s   € ä
�Š�D×%Ñ%°Ó5r   Úconflict_idc                 óV   • [         R                  R                  U R                  U5      $ )z’Get the directory path for a specific conflict.

Args:
    conflict_id: The conflict ID (SHA-1 hash)

Returns:
    Path to the conflict directory
)r8   r>   r   r4   ©r:   rJ   s     r   Ú_get_conflict_dirÚRerereCache._get_conflict_dirØ   s   € ô �w‰w�|‰|˜D×-Ñ-¨{Ó;Ð;r   c                 ó`   • [         R                  R                  U R                  U5      S5      $ )z‚Get the path to the preimage file for a conflict.

Args:
    conflict_id: The conflict ID

Returns:
    Path to the preimage file
r
   ©r8   r>   r   rM   rL   s     r   Ú_get_preimage_pathÚRerereCache._get_preimage_pathã   s$   € ô �w‰w�|‰|˜D×2Ñ2°;Ó?ÀÓLÐLr   c                 ó`   • [         R                  R                  U R                  U5      S5      $ )z„Get the path to the postimage file for a conflict.

Args:
    conflict_id: The conflict ID

Returns:
    Path to the postimage file
Ú	postimagerP   rL   s     r   Ú_get_postimage_pathÚRerereCache._get_postimage_pathî   s$   € ô �w‰w�|‰|˜D×2Ñ2°;Ó?ÀÓMÐMr   r>   r   c                 óR  • [        U5      (       d  gU R                  5         [        U5      n[        U5      nU R	                  U5      n[
        R                  " USS9  U R                  U5      n[        US5       nUR                  U5        SSS5        U$ ! , (       d  f       U$ = f)zÑRecord a conflict in the rerere cache.

Args:
    path: Path to the conflicted file
    content: File content with conflict markers

Returns:
    The conflict ID if recorded, None if no conflict markers found
NTrE   Úwb)
r.   rH   r!   r   rM   r8   rG   rQ   ÚopenÚwrite)r:   r>   r   r
   rJ   Úconflict_dirÚpreimage_pathÚfs           r   Úrecord_conflictÚRerereCache.record_conflictù   sœ   € ô % W×-Ñ-Øà×ÑÔ ô /¨wÓ7ˆÜ*¨8Ó4ˆð ×-Ñ-¨kÓ:ˆÜ
�Š�L¨4Ò0ð ×/Ñ/°Ó<ˆÜ�- Ô&¨!Ø�G‰G�GÔ÷ 'ð Ð÷ 'Ô&ð Ðús   Á;BÂ
B&c                 óà   • U R                  U5      nU R                  U5      n[        R                  " USS9  [	        US5       nUR                  U5        SSS5        g! , (       d  f       g= f)z·Record a resolution for a previously recorded conflict.

Args:
    conflict_id: The conflict ID to record resolution for
    content: Resolved file content (without conflict markers)
TrE   rX   N)rU   rM   r8   rG   rY   rZ   )r:   rJ   r   Úpostimage_pathr[   r]   s         r   Úrecord_resolutionÚRerereCache.record_resolution  sX   € ð ×1Ñ1°+Ó>ˆð ×-Ñ-¨kÓ:ˆÜ
�Š�L¨4Ò0ä�. $Ô'¨1Ø�G‰G�GÔ÷ (×'Ö'ús   ÁAÁ
A-c                 ób   • U R                  U5      n[        R                  R                  U5      $ )z�Check if a resolution exists for a conflict.

Args:
    conflict_id: The conflict ID

Returns:
    True if a postimage exists for this conflict
)rU   r8   r>   Úexists)r:   rJ   ra   s      r   Úhas_resolutionÚRerereCache.has_resolution(  s'   € ð ×1Ñ1°+Ó>ˆÜ�w‰w�~‰~˜nÓ-Ð-r   c                 ó´   • U R                  U5      n [        US5       nUR                  5       sSSS5        $ ! , (       d  f       g= f! [         a     gf = f)z�Get the recorded resolution for a conflict.

Args:
    conflict_id: The conflict ID

Returns:
    The resolution content, or None if not found
ÚrbN)rU   rY   ÚreadÚFileNotFoundError)r:   rJ   ra   r]   s       r   Úget_resolutionÚRerereCache.get_resolution4  sK   € ð ×1Ñ1°+Ó>ˆð	Ü�n dÔ+¨qØ—v‘v“x÷ ,×+×+ûä ó 	Ùð	ús+   “A
 Ÿ9¯	A
 ¹
AÁA
 ÁA
 Á

AÁAc                 ó0   • U R                  U5      nUc  gU$ )zãApply a recorded resolution to current conflict content.

Args:
    conflict_id: The conflict ID
    content: Current file content with conflict markers

Returns:
    Resolved content, or None if resolution couldn't be applied
N)rl   )r:   rJ   r   Ú
resolutions       r   Úapply_resolutionÚRerereCache.apply_resolutionE  s%   € ð ×(Ñ(¨Ó5ˆ
ØÑØð
 Ðr   c                 ó  • U R                  U5      nS H9  n[        R                  R                  X#5      n [        R                  " U5        M;      [        R                  " U5        g! [
         a     Mb  f = f! [         a     gf = f)zaForget a recorded conflict and its resolution.

Args:
    conflict_id: The conflict ID to forget
)r
   rT   N)rM   r8   r>   r   Úremoverk   ÚrmdirÚOSError)r:   rJ   r[   Úfilenamer>   s        r   ÚforgetÚRerereCache.forgetX  sz   € ð ×-Ñ-¨kÓ:ˆó 2ˆHÜ—7‘7—<‘< Ó7ˆDðÜ—	’	˜$–ñ 2ð	Ü�HŠH�\Õ"øô %ó Úðûô ó 	Ùð	ús#   ·A)ÁA: Á)
A7Á6A7Á:
BÂBc                 ó  • [         R                  R                  U R                  5      (       d  g[         R                  " U R                  5       H¹  n[         R                  R                  U R                  U5      n[         R                  R                  U5      (       d  MS  [         R                  " U5       H6  n[         R                  " [         R                  R                  X#5      5        M8     [         R                  " U5        M»     g)z-Clear all recorded conflicts and resolutions.N)	r8   r>   re   r4   Úlistdirr   Úisdirrs   rt   )r:   Úentryr[   rv   s       r   ÚclearÚRerereCache.clearn  sž   € ä�w‰w�~‰~˜d×/Ñ/×0Ñ0Øô —Z’Z × 1Ñ 1Ö2ˆEÜŸ7™7Ÿ<™<¨×(9Ñ(9¸5ÓAˆLÜ�w‰w�}‰}˜\×*Ó*ä "§
¢
¨<Ö 8�HÜ—I’IœbŸg™gŸl™l¨<ÓBÖCñ !9ä—’˜Ö&ò 3r   Úmax_age_daysc                 óŒ  • [         R                  R                  U R                  5      (       d  g[        R                  " 5       US-  S-  S-  -
  n[         R
                  " U R                  5       HÐ  n[         R                  R                  U R                  U5      n[         R                  R                  U5      (       d  MS  [         R                  R                  US5      n[         R                  R                  U5      (       d  M™  [         R                  R                  U5      nXb:  d  M¿  U R                  U5        MÒ     g)zoGarbage collect old conflict resolutions.

Args:
    max_age_days: Maximum age in days for keeping resolutions
Né   é<   rT   )
r8   r>   re   r4   Útimerz   r   r{   Úgetmtimerw   )r:   r   Úcutoff_timer|   r[   ra   Úmtimes          r   ÚgcÚRerereCache.gc|  s×   € ô �w‰w�~‰~˜d×/Ñ/×0Ñ0Øä—i’i“k \°BÑ%6¸Ñ%;¸bÑ%@ÑAˆä—Z’Z × 1Ñ 1Ö2ˆEÜŸ7™7Ÿ<™<¨×(9Ñ(9¸5ÓAˆLÜ—7‘7—=‘= ×.Ñ.ÙäŸW™WŸ\™\¨,¸ÓDˆNô �w‰w�~‰~˜n×-Ó-ÜŸ™×(Ñ(¨Ó8�ØÕ&Ø—K‘K Ö&ò 3r   c                 ó°  • [         R                  R                  U R                  5      (       d  / $ / n[         R                  " U R                  5       Hv  n[         R                  R                  U R                  U5      n[         R                  R                  U5      (       d  MS  U R                  U5      nUR                  X$45        Mx     [        U5      $ )ziGet the status of all conflicts in the cache.

Returns:
    List of tuples (conflict_id, has_resolution)
)
r8   r>   re   r4   rz   r   r{   rf   r   Úsorted)r:   r   r|   r[   Úhas_ress        r   ÚstatusÚRerereCache.status”  s˜   € ô �w‰w�~‰~˜d×/Ñ/×0Ñ0ØˆIàˆÜ—Z’Z × 1Ñ 1Ö2ˆEÜŸ7™7Ÿ<™<¨×(9Ñ(9¸5ÓAˆLÜ�w‰w�}‰}˜\×*Ó*Ø×-Ñ-¨eÓ4�Ø—‘˜uÐ.Ö/ñ	 3ô �f‹~Ðr   c                 óx  • U R                  U5      nU R                  U5      nSnSn [        US5       nUR                  5       nSSS5         [        US5       nUR                  5       nSSS5        XE4$ ! , (       d  f       N7= f! [         a     NFf = f! , (       d  f       XE4$ = f! [         a     XE4$ f = f)z˜Get the preimage and postimage for a conflict.

Args:
    conflict_id: The conflict ID

Returns:
    Tuple of (preimage, postimage), either may be None
Nri   )rQ   rU   rY   rj   rk   )r:   rJ   r\   ra   r
   rT   r]   s          r   ÚdiffÚRerereCache.diff¦  sÅ   € ð ×/Ñ/°Ó<ˆØ×1Ñ1°+Ó>ˆàˆØˆ	ð	Ü�m TÔ*¨aØŸ6™6›8�÷ +ð
	Ü�n dÔ+¨qØŸF™F›H�	÷ ,ð
 Ð"Ð"÷ +Õ*ûä ó 	Ùð	ú÷ ,Ô+ð
 Ð"Ð"ûô !ó 	ØàÐ"Ð"ð	ús^   ¨B ´A6ÁB ÁB* ÁBÁ+B* Á6
BÂ B ÂB Â
BÂBÂ
B'Â!B* Â'B* Â*
B9Â8B9)r4   )rA   r	   r   r   )r   N)r‚   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r7   Ústrr;   ÚclassmethodrB   rH   rM   rQ   rU   r^   rb   Úboolrf   rl   rp   rw   r}   Úintr‡   ÚlistÚtuplerŒ   r�   Ú__static_attributes__r-   r   r   r   r   ¹   s^  † Ù5ð	- U¨S¡[ð 	-°Tô 	-ð ó
!ó ð
!ô6ð	<¨Sð 	<°Sô 	<ð	M¨cð 	M°cô 	Mð	N¨sð 	N°sô 	Nð Eð °Eð ¸cÀD¹jô ð<¨Sð ¸5ð ÀTô ð"
.¨#ð 
.°$ô 
.ð¨#ð °%¸$±,ô ð"¨Cð ¸%ð ÀEÈDÁLô ð& #ð ¨$ô ô,'ñ'˜sð '¨Dõ 'ð0˜˜U 3¨ 9Ñ-Ñ.ô ð$# ð #¨¨e°d©l¸EÀD¹LÐ.HÑ(I÷ #r   r   Úconfigr   c                 ó¶   •  U R                  SS5      nUc  g[        U[        5      (       a  UR                  5       S;   $ [	        U5      $ ! [
         a     gf = f)zwCheck if rerere is enabled in the config.

Args:
    config: Git configuration

Returns:
    True if rerere is enabled
©s   rereres   enabledF©s   trueó   1s   yess   on©Úgetr6   r7   Úlowerr˜   ÚKeyError)r�   Úenableds     r   r   r   Ä  sZ   € ðØ—*‘*˜\¨:Ó6ˆØ‰?ØÜ�gœu×%Ñ%Ø—=‘=“?Ð&DÑDÐDÜ�G‹}ÐøÜó Ùðúó   ‚A ˜'A Á 
A Á
AÁAc                 ó¶   •  U R                  SS5      nUc  g[        U[        5      (       a  UR                  5       S;   $ [	        U5      $ ! [
         a     gf = f)z�Check if rerere.autoupdate is enabled in the config.

Args:
    config: Git configuration

Returns:
    True if rerere.autoupdate is enabled
rŸ   s
   autoupdateFr    r¢   )r�   Ú
autoupdates     r   r   r   Ø  s_   € ðØ—Z‘Z ¨mÓ<ˆ
ØÑØÜ�j¤%×(Ñ(Ø×#Ñ#Ó%Ð)GÑGÐGÜ�JÓÐøÜó Ùðúr§   rA   r	   Úworking_tree_pathr%   zConfig | Nonec                 óX  • Uc  U R                  5       n[        U5      (       d  / / 4$ [        R                  U 5      n/ n/ n[	        U[
        5      (       a  [        R                  " U5      n[        U5      nU Hø  n[        R                  R                  U[        R                  " U5      5      n	 [        U	S5       n
U
R                  5       nSSS5        UR                  UW5      nU(       d  Mx  UR                  XŒ45        U(       d  M“  UR!                  U5      (       d  M«  UR#                  U5      nUc  MÁ  [        U	S5       n
U
R%                  U5        SSS5        UR                  U5        Mú     XV4$ ! , (       d  f       N°= f! [         a     GM  f = f! , (       d  f       NI= f)aU  Automatically record conflicts and apply known resolutions.

This is the main entry point for rerere integration with merge operations.
It should be called after a merge that resulted in conflicts.

Args:
    repo: Repository object
    working_tree_path: Path to the working tree
    conflicts: List of conflicted file paths
    config: Configuration to consult for rerere settings. If None,
        falls back to ``repo.get_config_stack()``.

Returns:
    Tuple of:
    - List of tuples (path, conflict_id) for recorded conflicts
    - List of paths where resolutions were automatically applied
Nri   rX   )Úget_config_stackr   r   rB   r6   r7   r8   r9   r   r>   r   rY   rj   rk   r^   r   rf   rl   rZ   )rA   rª   r%   r�   ÚcacheÚrecordedÚresolvedr©   r>   Ú	file_pathr]   r   rJ   ro   s                 r   r   r   ì  se  € ð. �~Ø×&Ñ&Ó(ˆÜ˜V×$Ñ$Ø�2ˆvˆä×!Ñ! $Ó'€EØ€HØ€HäÐ#¤U×+Ñ+ÜŸKšKÐ(9Ó:Ðä% fÓ-€Jó ˆä—G‘G—L‘LÐ!2´B·K²KÀÓ4EÓFˆ	ð	Ü�i Ô&¨!ØŸ&™&›(�÷ 'ð ×+Ñ+¨D°'Ó:ˆÞÙà�‰˜Ð+Ô,÷ ˆ:˜%×.Ñ.¨{×;Ó;Ø×-Ñ-¨kÓ:ˆJØÓ%ä˜) TÔ*¨aØ—G‘G˜JÔ'÷ +à—‘ Ö%ñ3 ð6 ÐÐ÷- 'Õ&ûä ó 	ãð	ú÷  +Õ*ús<   Â1F	Â=E8ÃF	ÅFÅ8
F	ÆF	ÆF	Æ	
FÆFÆ
F)	)N)r•   Ú__all__r   r8   rƒ   Útypingr   Údulwich.configr   Údulwich.repor	   r7   r–   r   r!   rš   r›   r+   r˜   r.   r1   r   r   r   r   r-   r   r   Ú<module>rµ      s2  ðñ,ò€ó Û 	Û Ý  æÝ%Ý!ð. 5ð .¨Sô .ð¨ð °5ô ð>- uð -°°e¸EÀ5È%Ð<OÑ6PÑ1Qô -ð`	U 5ð 	U¨Tô 	Uð eð °ô ÷@H#ñ H#ðV˜hð ¨4ô ð( ð ¨dô ð0 #ñ	AØ
ðAà˜s‘{ðAð �E‰{ðAð ð	Að
 ˆ4��e˜S�jÑ!Ñ" D¨¡KÐ/Ñ0öAr   