
    6                     h    d Z ddlZddlmZmZmZ  ej                  dg d      Zd Zd Z	d Z
d
d	Zy)z.Utilities for reading and generating reflogs.
    N)format_timezoneparse_timezoneZERO_SHAEntryold_shanew_sha	committer	timestamptimezonemessagec                     | t         } | dz   |z   dz   |z   dz   t        t        |            j                  d      z   dz   t	        |      z   dz   |z   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
        ascii   	)r   strintencoder   r   s         !lib/third_party/dulwich/reflog.pyformat_reflog_liner   &   s     
	
	 	 		
 	 c)n

$
$W
-	. 	 (
#	$ 		 
	    c           	          | j                  dd      \  }}|j                  dd      \  }}}|j                  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   )splitrsplitr   r   r   )	linebeginr   r   r	   restr
   timestamp_strtimezone_strs	            r   parse_reflog_liner"   B   su     zz%+UG${{43Wgt/3{{4/C,Y|M|$Q' r   c              #   4   K   | D ]  }t        |        yw)z_Read reflog.

    Args:
      f: File-like object
    Returns: Iterator over Entry objects
    N)r"   )fr   s     r   read_reflogr%   W   s      %% s   c                    |dk  rt        d|z        g }| j                         }| D ].  }|j                  |t        |      f       | j                         }0 t	        |      |z
  dz
  }||   d   }| j                  |       |dk(  r| j                          y||= |rw|dkD  rr|rp|dk(  rt        }n||dz
     d   j                  }||   \  }}	|t        ||	j                  |	j                  |	j                  |	j                  |	j                        f||<   ||d D ]`  \  }
}	| j                  t        |	j                   |	j                  |	j                  |	j                  |	j                  |	j                               b | j                          y)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 %dr   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_s              r   drop_reflog_entryr7   b   s    qy2U:;;
CVVXF

F-d345  Hu$q(M}%a(LFF<z	

M519A#L}q01!4<<LM*

M '5			
 ( JJLr   )F)__doc__collectionsdulwich.objectsr   r   r   
namedtupler   r   r"   r%   r7    r   r   <module>r=      sG   *   	K	8*&8r   