
    .Ph~1                        d Z ddlZddlZddlmZ ddlmZmZm	Z	m
Z
 ddlmZmZmZ ddlmZ dZ	 d	 d d
Zd Zd	efdZ	 	 	 	 	 	 	 	 d!dZd Zd Zd Z	 d"ded	dfdZd Zd dZd"d dZd#de
e	ef         dee         fdZd#dZdS )$z~Classes for dealing with git am-style patches.

These patches are basically unified diffs with some extra metadata tacked
on.
    N)SequenceMatcher)BinaryIOOptionalTextIOUnion   )S_ISGITLINKBlobCommit)ObjectContaineri@  returnc                    |pt          | dd          }t          |t                    r|                    |          }|\  }}|                     d|j        z   dz   t          j        |j                                      |          z   dz              |                     d|j	        z   dz              |                     dt          j
        d                              |          z   dz              |                     d	| d
| d                    |          |j        z   dz              |                     d           |                     d           	 ddl}|                    dg|j        |j                  }	|	                    |          \  }
}|                     |
           |                     d           n# t           t"          f$ r Y nw xY w|                     |           |                     d           | ddlm} |                     d|z             dS |                     |                    |          dz              dS )zWrite a individual file patch.

    Args:
      commit: Commit object
      progress: Tuple with current patch number and total.

    Returns:
      tuple with filename and contents
    encodingasciis   From        
   From: s   Date: z%a, %d %b %Y %H:%M:%S %ZzSubject: [PATCH /]    ---
r   Ndiffstat)stdoutstdin   -- 
)__version__s   Dulwich %d.%d.%d
)getattr
isinstancestrencodewriteidtimectimecommit_timeauthorstrftimemessage
subprocessPopenPIPEcommunicateImportErrorOSErrordulwichr   )fcommitcontentsprogressversionr   numtotalr(   pr   _dulwich_versions                M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/patch.pywrite_commit_patchr:   '   s    :71j'::H(C   -??8,,LS%GG
)	
	 *V'
(
(
/
/
9
9	: 		   GGI%-...GGDM"<==DDXNNNQVV   GG	+C	+	+%	+	+	+33H==NQVV   GGENNNGGHL
  
 
 h//1		 !    GGHGGH::::::	%788888	x((5011111s   'G GGc                     | j                             d          }|                                d                             dd          S )zrDetermine the summary line for use in a filename.

    Args:
      commit: Commit
    Returns: Summary string
    replace)errorsr    -)r'   decode
splitlinesr<   )r0   decodeds     r9   get_summaryrC   ]   sC     n##9#55G"**3444    c                 D    | dz   }|| z
  }|dk    r| S |s|dz  }| d| S )z!Convert range to the "ed" format.r   , )startstop	beginninglengths       r9   _format_range_unifiedrL   i   sL     	IE\F{{~ Q	""&"""rD       
utf-8c
              #     K   d}
t          d| |                              |          D ]_}|
svd}
|rd| nd}|rd| nd}d|                    |           | |                     |	          V  d|                    |           | |                     |	          V  |d         |d	         }}t	          |d
         |d                   }t	          |d         |d                   }d| d| d|                     |	          V  |D ]y\  }}}}}|dk    r| ||         D ]	}d|z   V  
#|dv r'| ||         D ]}|d	d         dk    s|dz  }d|z   V  |dv r'|||         D ]}|d	d         dk    s|dz  }d|z   V  zadS )zdifflib.unified_diff that can detect "No newline at end of file" as
    original "git diff" does.

    Based on the same function in Python2.7 difflib.py
    FNT	rM   z--- z+++ r   r      rN      z@@ -z +z @@equalr   )r<   deleter   s   
\ No newline at end of file
   -)r<   insert   +)r   get_grouped_opcodesr@   r   rL   )abfromfiletofilefromfiledate
tofiledatenlinetermtree_encodingoutput_encodingstartedgroupfromdatetodatefirstlastfile1_rangefile2_rangetagi1i2j1j2lines                           r9   unified_diffrt   u   sw     " G q!,,@@CC & & 		G.:B*L***H*4<&*&&&"FM77MM8MMTT     J}55IvIxIIPP     Ahb	t+E!Hd1g>>+E!Hd1g>>>[>>K>>H>>EEoVVVVV#( 	& 	&CRRg~~beH & &D+%%%%+++beH & &D9-- CC+%%%%+++beH & &D9-- CC+%%%%	&#& &rD   c                 $    d| dt                    v S )z}See if the first few bytes contain any null characters.

    Args:
      content: Bytestring to check for binary content
        N)FIRST_FEW_BYTEScontents    r9   	is_binaryrz      s     G,_,---rD   c                     | dS | d d         S )Ns   0000000   rG   )hexshas    r9   shortidr~      s    ~xbqbzrD   c                     | dS |dz   | z   S )Ns	   /dev/null   /rG   )r6   roots     r9   patch_filenamer      s    y|d{QrD   Fstorec                     |\  }}}|\  }}	}
t          |d          }t          |d          }fd}d }|                     t          ||f||	f||
f                      |||          } ||	|
          }|sMt          |j                  st          |j                  r%d|z   dz   |z   dz   }|                     |           dS |                     t           ||           ||          ||                     dS )	a  Write the diff for an object.

    Args:
      f: File-like object to write to
      store: Store to retrieve objects from, if necessary
      old_file: (path, mode, hexsha) tuple
      new_file: (path, mode, hexsha) tuple
      diff_binary: Whether to diff files even if they
        are considered binary files by is_binary().

    Note: the tuple elements should be None for nonexistent files
       a   bc                     |t          j        d          S t          |           rt          j        d|z   dz             S |         S )NrD   s   Subproject commit r   )r
   from_stringr	   )moder}   r   s     r9   ry   z"write_object_diff.<locals>.content   sO    >#C((( 	!#$9F$BU$JKKK= rD   c                 2    | sg S |                                  S NrA   rx   s    r9   linesz write_object_diff.<locals>.lines   s!     	(I%%'''rD   s   Binary files s    and s    differ
N)r   
writelinesgen_diff_headerrz   datar    rt   )r/   r   old_filenew_filediff_binaryold_pathold_modeold_idnew_pathnew_modenew_idpatched_old_pathpatched_new_pathry   r   old_contentnew_contentbinary_diffs    `                r9   write_object_diffr      s~    $, Xx#+ Xx%h55%h55! ! ! ! !( ( ( LL8,x.BVVDTUU   '(F++K'(F++K 
Ik&677 
9[EU;V;V 
  	 	 	
	k""k""  	 	
 	
 	
 	
 	
rD   c              #     K   | \  }}|\  }}|\  }}|||}|||}t          |d          }t          |d          }d|z   dz   |z   dz   V  ||k    rY|;|d|dd	                    d
          V  d|dd	                    d
          V  nd|dd	                    d
          V  dt          |          z   dz   t          |          z   V  ||d|d                    d
          V  dV  dS )zWrite a blob diff header.

    Args:
      paths: Tuple with old and new path
      modes: Tuple with old and new modes
      shas: Tuple with old and new shas
    Nr   r   s   diff --git r   r   zold file mode orO   r   znew file mode zdeleted file mode s   index s   ..r>   )r   r   r~   )	pathsmodesshasr   r   r   r   old_shanew_shas	            r9   r   r      s~      !Xx XxWgH0H0h--Hh--H
8
#d
*X
5
====8#66666>>wGGGGG2H2222::7CCCCCC66666>>wGGGGG
gg&&
&
.1A1A
AAAA 48''00000
KKKKKrD   c                 j   |\  }}}|\  }}}t          |d          }	t          |d          }
d }|                     t          ||f||ft          |dd          t          |dd          f                      ||          } ||          }|                     t	          |||	|
                     dS )a  Write blob diff.

    Args:
      f: File-like object to write to
      old_file: (path, mode, hexsha) tuple (None if nonexisting)
      new_file: (path, mode, hexsha) tuple (None if nonexisting)

    Note: The use of write_object_diff is recommended over this function.
    r   r   c                 2    | |                                  S g S r   r   )blobs    r9   r   zwrite_blob_diff.<locals>.lines,  s    ??$$$IrD   r!   N)r   r   r   r   rt   )r/   r   r   r   r   old_blobr   r   new_blobr   r   r   old_contentsnew_contentss                 r9   write_blob_diffr     s     &."Xx%-"Xx%h55%h55   LLx x XtT**GHdD,I,IJ	
 	
   5??L5??LLL\<1ACSTT    rD   c           	          |                     ||          }|D ])\  \  }}\  }}	\  }
}t          | ||||
f||	|f|           *dS )zWrite tree diff.

    Args:
      f: File-like object to write to.
      old_tree: Old tree id
      new_tree: New tree id
      diff_binary: Whether to diff files even if they
        are considered binary files by is_binary().
    )r   N)tree_changesr   )r/   r   old_treenew_treer   changesoldpathnewpatholdmodenewmodeoldshanewshas               r9   write_tree_diffr   @  s       844GDK 
 
@'.Wg0@gv&gv&#	
 	
 	
 	
 	

 
rD   r/   r   c                 p   |pt          | dd          }|pd}|                                 }t          |t                    r4t          j                                        }|                    |          }n3t          j                                        }|	                    |          }t          ||          S )zParse a git-am-style patch and split it up into bits.

    Args:
      f: File-like object to parse
      encoding: Encoding to use when creating Git objects
    Returns: Tuple with commit object, diff contents and git version
    r   r   )r   readr   bytesemailparserBytesParser
parsebytesParserparsestrparse_patch_message)r/   r   r1   bparsermsguparsers         r9   git_am_patch_splitr   U  s     :71j'::H"7HvvxxH(E"" ),**,,  **,%%''x((sH---rD   c                    t                      }| d                             |          |_        | d                             |          |_        	 | d                             d          }| d                             d|          }| d         |dz   d         }n# t
          $ r | d         }Y nw xY w|                    dd          dz                       |          |_        d	}|                     d	
          }|	                    d	          }t          |          }	|	D ]v}
|
dk    r nm|rZ|
                    d          r/|
t          d          d                                         |_        n|xj        d|
z   z  c_        d}f|xj        |
z  c_        wd}|	D ]}
|
dk    r n||
z  }	 t          |	                              d          }n# t          $ r d}Y nw xY w|||fS )zExtract a Commit object and patch from an e-mail message.

    Args:
      msg: An email message (email.message.Message)
      encoding: Encoding to use to encode Git commits
    Returns: Tuple with commit object, diff contents and git version
    fromsubjectz[PATCHr   rT   NrO   rM   T)r@   r   r   r   FrD   r   )r   r   r%   	committerindex
ValueErrorr<   r'   get_payloadrA   iter
startswithlenrstripnextStopIteration)r   r   cpatch_tag_startcloser   rj   bodyr   	line_iterrs   diffr3   s                r9   r   r   i  s$    	A6{!!(++AHf+$$X..AK.i...x88 I$$T?;;i.-	  ! ! !i.!
 r**T199(CCAIE??$?''DOOD!!EUI 
 
8E 	y)) *I 0 0188::		UT\)		EEIIIIID  8Ey//((//   dGs$   B B0/B0."G G G )NN)r   N)rM   rM   rM   rM   rN   rO   rP   rP   )Fr   ) __doc__email.parserr   r"   difflibr   typingr   r   r   r   objectsr	   r
   r   packr   rw   r:   rC   r   rL   rt   rz   r~   r   r   r   r   r   r   r   rG   rD   r9   <module>r      s  ,       # # # # # # 4 4 4 4 4 4 4 4 4 4 4 4 . . . . . . . . . . ! ! ! ! ! ! ;?32	32 32 32 32l5 5 5	## 	# 	# 	# 	# 1& 1& 1& 1&h. . .     @E8
 8
8
	8
 8
 8
 8
x  B       F
 
 
 
 
*. .% 01 .Xc] . . . .(- - - - - -rD   