o
    Uh]                     @   sX   d Z ddlZddlmZmZmZ edg dZdd Zd	d
 Z	dd Z
ddddZdS )z-Utilities for reading and generating reflogs.    N   )ZERO_SHAformat_timezoneparse_timezoneEntryold_shanew_sha	committer	timestamptimezonemessagec                 C   sJ   | du rt } | d | d | d tt|d d t| d | S )zGenerate a single reflog line.

    Args:
      old_sha: Old Commit SHA
      new_sha: New Commit SHA
      committer: Committer name and e-mail
      timestamp: Timestamp
      timezone: Timezone
      message: Message
    N    ascii   	)r   strintencoder   r    r   b/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/dulwich/reflog.pyformat_reflog_line"   s0   	
r   c           	      C   sR   |  dd\}}| dd\}}}|dd\}}}t|||t|t|d |S )zParse a reflog line.

    Args:
      line: Line to parse
    Returns: Tuple of (old_sha, new_sha, committer, timestamp, timezone,
        message)
    r   r   r      r   )splitrsplitr   r   r   )	linebeginr   r   r	   restr
   timestamp_strtimezone_strr   r   r   parse_reflog_line>   s   
r   c                 c   s    | D ]}t |V  qdS )z_Read reflog.

    Args:
      f: File-like object
    Returns: Iterator over Entry objects
    N)r   )fr   r   r   r   read_reflogS   s   r!   Freturnc              
   C   s,  |dk rt d| g }|  }| D ]}||t|f |  }qt|| d }|| d }| | |dkr@|   dS ||= |rs|dkrs|rs|dkrRt}n	||d  d j}|| \}}	|t	||	j|	j
|	j|	j|	jf||< ||d D ]\}
}	| t|	j|	j|	j
|	j|	j|	j qy|   dS )a   Drop the specified reflog entry.

    Args:
        f: File-like object
        index: Reflog entry index (in Git reflog reverse 0-indexed order)
        rewrite: If a reflog entry's predecessor is removed, set its
            old SHA to the new SHA of the entry that now precedes it
    r   zInvalid reflog index r   N)
ValueErrortellappendr   lenseektruncater   r	   r   r
   r   r   r   writer   r   )r    indexrewritelogoffsetr   inverse_indexwrite_offsetprevious_newentry_r   r   r   drop_reflog_entry^   sR   	


r3   )F)r"   N)__doc__collectionsobjectsr   r   r   
namedtupler   r   r   r!   r3   r   r   r   r   <module>   s   