HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/fastimport/__pycache__/parser.cpython-39.pyc
a

�+yW�X�@s�dZddlmZddlZddlZddlZddlZddlmZm	Z	m
Z
ddlmZ
mZGdd�de
�Ze�d�Ze�d	�ZGd
d�de�Ze�dej�Ze�d
ejejB�Zdd�Ze�dd�ZdS)aSParser of import data into command objects.

In order to reuse existing front-ends, the stream format is a subset of
the one used by git-fast-import (as of the 1.5.4 release of git at least).
The grammar is:

  stream ::= cmd*;

  cmd ::= new_blob
        | new_commit
        | new_tag
        | reset_branch
        | checkpoint
        | progress
        ;

  new_blob ::= 'blob' lf
    mark?
    file_content;
  file_content ::= data;

  new_commit ::= 'commit' sp ref_str lf
    mark?
    ('author' sp name '<' email '>' when lf)?
    'committer' sp name '<' email '>' when lf
    commit_msg
    ('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
    ('merge' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)*
    file_change*
    lf?;
  commit_msg ::= data;

  file_change ::= file_clr
    | file_del
    | file_rnm
    | file_cpy
    | file_obm
    | file_inm;
  file_clr ::= 'deleteall' lf;
  file_del ::= 'D' sp path_str lf;
  file_rnm ::= 'R' sp path_str sp path_str lf;
  file_cpy ::= 'C' sp path_str sp path_str lf;
  file_obm ::= 'M' sp mode sp (hexsha1 | idnum) sp path_str lf;
  file_inm ::= 'M' sp mode sp 'inline' sp path_str lf
    data;

  new_tag ::= 'tag' sp tag_str lf
    'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
    'tagger' sp name '<' email '>' when lf
    tag_msg;
  tag_msg ::= data;

  reset_branch ::= 'reset' sp ref_str lf
    ('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
    lf?;

  checkpoint ::= 'checkpoint' lf
    lf?;

  progress ::= 'progress' sp not_lf* lf
    lf?;

     # note: the first idnum in a stream should be 1 and subsequent
     # idnums should not have gaps between values as this will cause
     # the stream parser to reserve space for the gapped values.  An
     # idnum can be updated in the future to a new object by issuing
     # a new mark directive with the old idnum.
     #
  mark ::= 'mark' sp idnum lf;
  data ::= (delimited_data | exact_data)
    lf?;

    # note: delim may be any string but must not contain lf.
    # data_line may contain any data but must not be exactly
    # delim. The lf after the final data_line is included in
    # the data.
  delimited_data ::= 'data' sp '<<' delim lf
    (data_line lf)*
    delim lf;

     # note: declen indicates the length of binary_data in bytes.
     # declen does not include the lf preceeding the binary data.
     #
  exact_data ::= 'data' sp declen lf
    binary_data;

     # note: quoted strings are C-style quoting supporting \c for
     # common escapes of 'c' (e..g 
, 	, \, ") or 
nn where nnn
     # is the signed byte value in octal.  Note that the only
     # characters which must actually be escaped to protect the
     # stream formatting is: \, " and LF.  Otherwise these values
     # are UTF8.
     #
  ref_str     ::= ref;
  sha1exp_str ::= sha1exp;
  tag_str     ::= tag;
  path_str    ::= path    | '"' quoted(path)    '"' ;
  mode        ::= '100644' | '644'
                | '100755' | '755'
                | '120000'
                ;

  declen ::= # unsigned 32 bit value, ascii base10 notation;
  bigint ::= # unsigned integer value, ascii base10 notation;
  binary_data ::= # file content, not interpreted;

  when         ::= raw_when | rfc2822_when;
  raw_when     ::= ts sp tz;
  rfc2822_when ::= # Valid RFC 2822 date and time;

  sp ::= # ASCII space character;
  lf ::= # ASCII newline (LF) character;

     # note: a colon (':') must precede the numerical value assigned to
     # an idnum.  This is to distinguish it from a ref or tag name as
     # GIT does not permit ':' in ref or tag strings.
     #
  idnum   ::= ':' bigint;
  path    ::= # GIT style file path, e.g. "a/b/c";
  ref     ::= # GIT ref name, e.g. "refs/heads/MOZ_GECKO_EXPERIMENT";
  tag     ::= # GIT tag name, e.g. "FIREFOX_1_5";
  sha1exp ::= # Any valid GIT SHA1 expression;
  hexsha1 ::= # SHA1 in hexadecimal format;

     # note: name and email are UTF8 strings, however name must not
     # contain '<' or lf and email must not contain any of the
     # following: '<', '>', lf.
     #
  name  ::= # valid GIT author/committer name;
  email ::= # valid GIT author/committer email;
  ts    ::= # time since the epoch in seconds, ascii base10 notation;
  tz    ::= # GIT style timezone;

     # note: comments may appear anywhere in the input, except
     # within a data command.  Any form of the data command
     # always escapes the related input from comment processing.
     #
     # In case it is not clear, the '#' that starts the comment
     # must be the first character on that the line (an lf have
     # preceeded it).
     #
  comment ::= '#' not_lf* lf;
  not_lf  ::= # Any byte that is not ASCII newline (LF);
�)�print_functionN)�commands�dates�errors)�	newobject�utf8_bytes_stringc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�LineBasedParsercCs||_d|_g|_dS)zlA Parser that keeps track of line numbers.

        :param input: the file-like object to read from
        rN)�input�lineno�_buffer)�self�input_stream�r�3/usr/lib/python3/dist-packages/fastimport/parser.py�__init__�szLineBasedParser.__init__cGs||jg|�R��dS)z5Raise an exception providing line number information.N�r
)rZ	exception�argsrrr�abort�szLineBasedParser.abortcCs,|jd7_|jr|j��S|j��SdS)z5Get the next line including the newline or '' on EOF.�N)r
r�popr	�readline)rrrrr�s
zLineBasedParser.readlinecCs |��}|r|dd�SdSdS)z5Get the next line without the newline or None on EOF.N���)r�r�linerrr�	next_line�szLineBasedParser.next_linecCs"|jd8_|j�|d�dS)zePush line back onto the line buffer.

        :param line: the line with no trailing newline
        r�
N)r
r�appendrrrr�	push_line�szLineBasedParser.push_linecCsD|j�|�}t|�}|j|�d�7_||kr@|�tj||�|S)z�Read a given number of bytes from the input stream.

        Throws MissingBytes if the bytes are not found.

        Note: This method does not read from the line buffer.

        :return: a string
        r)r	�read�lenr
�countrrZMissingBytes)rr �result�foundrrr�
read_bytes�s	zLineBasedParser.read_bytescCs8g}|d}|j��}||kr"q.q|�|�qd�|�S)aRead the input stream until the terminator is found.

        Throws MissingTerminator if the terminator is not found.

        Note: This method does not read from the line buffer.

        :return: the bytes read up to but excluding the terminator.
        r�)r	rr�join)r�
terminator�linesZtermrrrr�
read_until�s

zLineBasedParser.read_untilN)
�__name__�
__module__�__qualname__rrrrrr#r(rrrrr�s
rs([^<]*)<(.*)> (.+)s
([^<]*)<(.*)>c@s�eZdZdejddfdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd/dd�Zdd�Zdd�Zd0d d!�Zd1d#d$�Zd2d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�ZdS)3�ImportParserFNTcCs4t�||�||_||_||_||_d|_i|_dS)a�A Parser of import commands.

        :param input_stream: the file-like object to read from
        :param verbose: display extra information of not
        :param output: the file-like object to write messages to (YAGNI?)
        :param user_mapper: if not None, the UserMapper used to adjust
          user-ids for authors, committers and taggers.
        :param strict: Raise errors on strictly invalid data
        N)rr�verbose�output�user_mapper�strict�date_parser�features)rr
r-r.r/r0rrrrszImportParser.__init__cCstj�d|j|f�dS)Nzwarning line %d: %s
)�sys�stderr�writer
)r�msgrrr�warningszImportParser.warningccsP|��}|dur,d|jvr&t�|j���qLqt|�dks|�d�rFqq|�d�rj|�|td�d��Vq|�d�r�|��Vq|�d�r��qLq|�d�r�t	�
|td�d��Vq|�d�r�|�|td�d��Vq|�d	��r�|�|td	�d��Vq|�d
��rt	�
�Vq|�d��r<|�|td�d��Vq|�tj|�qdS)
z)Iterator returning ImportCommand objects.Nsdoner�#scommit �blobs	progress sreset stag s
checkpointsfeaturesfeature )rr2rZPrematureEndOfStreamr
r�
startswith�
_parse_commit�_parse_blobrZProgressCommand�_parse_reset�
_parse_tagZCheckpointCommand�_parse_featurerZInvalidCommandrrrr�
iter_commands"s0





zImportParser.iter_commandsccs|��}|durq�qt|�dks|�d�r.qq|�d�rN|�|dd��Vq|�d�rx|�|dd��}t�|�Vq|�d�r�|�|dd��\}}t�||�Vq|�d�r�|�|dd��\}}t�	||�Vq|�d	�r�t�
�Vq|�|�q�qdS)
z�Iterator returning FileCommand objects.

        If an invalid file command is found, the line is silently
        pushed back and iteration ends.
        Nrr8sM �sD sR sC s	deleteall)rrr:�_parse_file_modify�_pathrZFileDeleteCommand�
_path_pairZFileRenameCommandZFileCopyCommandZFileDeleteAllCommandr)rr�path�old�new�src�destrrr�iter_file_commands@s(





zImportParser.iter_file_commandscCs&|j}|��}|�d�}t�|||�S)zParse a blob command.r9)r
�_get_mark_if_any�	_get_datarZBlobCommand)rr
�mark�datarrrr<^s
zImportParser._parse_blobc
Cs�|j}|��}|�ddd�}g}|�ddd�}|durF|�|�q qFq |�dd�}|�dd�}|��}	g}
|��}|dur�|�d�}|
�|�qjq�qji}
|�	�}|dur�|\}}||
|<q�q�q�t
j||||||	|
t|�
��|||
d�S)	zParse a commit command.scommitsauthorFNs	committer�message� )r
�more_authors�
properties)r
rK�_get_user_inforrL�	_get_from�
_get_merge�split�extend�
_get_propertyrZ
CommitCommand�listrJ)r�refr
rMZauthorrQZanother_authorZ	committer�message�from_Zmerges�mergeZthese_mergesrRZ
name_value�name�valuerrrr;es6

�zImportParser._parse_commitcCsP|�dd�}|d}t|�dkr0|�|d�}nd}||j|<tj|||jd�S)zParse a feature command.�=rrNr)rVrrCr2rZFeatureCommandr
)r�info�partsr^r_rrrr?�s
zImportParser._parse_featurecCs`|�dd�}|�|d�}|�|d�}|ddkrDd}|�d�}n|d}d}t�||||�S)z�Parse a filemodify command within a commit.

        :param info: a string in the format "mode dataref path"
          (where dataref might be the hard-coded literal 'inline').
        rPrArrsinlineNs
filemodify)rVrC�_moderLrZFileModifyCommand)rra�paramsrE�modeZdatarefrNrrrrB�s
�zImportParser._parse_file_modifycCs|��}t�||�S)zParse a reset command.)rTrZResetCommand)rrZr\rrrr=�szImportParser._parse_resetcCs6|�d�}|jdddd�}|�dd�}t�||||�S)zParse a tag command.stagstaggerT��accept_just_whorO)rTrSrLrZ
TagCommand)rr^r\Ztaggerr[rrrr>�s
�zImportParser._parse_tagcCs4|��}|�d�r"|td�d�S|�|�dSdS)zParse a mark section.smark :N�rr:rrrrrrrK�s


zImportParser._get_mark_if_anycCsV|��}|durdS|�d�r.|td�d�S|rD|�tj|d�n|�|�dSdS)zParse a from section.Nsfrom �from)rr:rrr�MissingSectionr)r�required_forrrrrrT�s

zImportParser._get_fromcCs@|��}|durdS|�d�r.|td�d�S|�|�dSdS)zParse a merge section.Nsmerge rhrrrrrU�s

zImportParser._get_mergecCsF|��}|durdS|�d�r4|�|td�d��S|�|�dSdS)zParse a property section.Ns	property )rr:�_name_valuerrrrrrrX�s

zImportParser._get_propertycCs`|��}|�|d�r8|j|t|d�d�|||d�S|rN|�tj||�n|�|�dSdS)zParse a user section.rPNrf)rr:�	_who_whenrrrrjr)r�cmd�sectionZrequiredrgrrrrrS�s�
zImportParser._get_user_info�datacCs�|��}|�d�r�|td�d�}|�d�r>|�|dd��St|�}|�|�}|j��}|jd7_t|�dks||dkr�|�	|dd��|Sn|�
tj||�dS)zParse a data section.sdata Ns<<rArrr)
rr:rr(�intr#r	rr
rrrrj)rrkror�rest�sizer#rrrrrL�s



zImportParser._get_datacCsht�|�}|r�|�d���}|jdur\t|�d��dkr>d}n|dkrLd}nd}tj||_z|�||j	�}Wn"t
y�td	|f��Yn0|�d
���}	|�d�}
nft
�|�}|r�|r�tjdd�}|�d
�}	|�d�}
n0|jr�|�tj|||�n|}	d}
tjdd�}t|	�dk�r8|	�d��r8|	dd�}	|j�rR|j�|	|
�\}	}
t|	|
|d|d
�S)
z�Parse who and when information from a string.

        :return: a tuple of (name,email,timestamp,timezone). name may be
            the empty string if only an email address was given.
        �NrPrA�rawsnowZnowZrfc2822zfailed to parse datestr '%s'rrr)�_WHO_AND_WHEN_RE�search�group�lstripr1rrVrZDATE_PARSERS_BY_NAMEr
�
ValueError�print�rstrip�_WHO_REr0rr�	BadFormat�endswithr/Zmap_name_and_email�
Authorship)r�srnrorg�matchZdatestrZdate_formatZwhenr^ZemailrrrrmsB



zImportParser._who_whencCsx|�dd�}|d}t|�dkr&d}nJt|d�}|d}|t|�}|dkrp|�|�}|d|d|d�7}||fS)z:Parse a (name,value) tuple from 'name value-length value'.rPrArrNr)rVrrqr#)rr�rbr^r_rsZ
still_to_readr#rrrrl3s
zImportParser._name_valuecCs<|�d�r8|�d�s(|�tjdd|�nt|dd��S|S)z
Parse a path.�"�?rr)r:rrrr~�_unquote_c_string�rr�rrrrCBs


zImportParser._pathcCs�|�d�r |dd��dd�}n|�dd�}t|�dkrL|�tjdd|�n`|d�d�r~|d�d�r~|ddd�|d<n.|d�d�s�|d�d�r�|�tjdd|�d	d
�|D�S)z%Parse two paths separated by a space.r�rNs" rPrAr�rcSsg|]}t|��qSr)r�)�.0r�rrr�
<listcomp>Xr$z+ImportParser._path_pair.<locals>.<listcomp>)r:rVrrrr~r)rr�rbrrrrDKs
zImportParser._path_paircCsR|dvrdS|dvrdS|dvr$dS|dvr0dS|d	vr<d
S|�tjdd|�d
S)zXCheck file mode format and parse into an int.

        :return: mode as integer
        )s644s100644s0100644i��)s755s100755s0100755i�)s040000s0040000i@)s120000s0120000i�)s160000s0160000i�Z
filemodifyreN)rrr~r�rrrrcZszImportParser._mode)N)TF)rp)F)r)r*r+r3�stdoutrr7r@rJr<r;r?rBr=r>rKrTrUrXrSrLrmrlrCrDrcrrrrr,	s2�
&	

�


2	r,s
    ( \\U........      # 8-digit hex escapes
    | \\u....          # 4-digit hex escapes
    | \\x..            # 2-digit hex escapes
    | \\[0-7]{1,3}     # Octal escapes
    | \\N\{[^}]+\}     # Unicode characters by name
    | \\[\\'"abfnrtv]  # Single-character escapes
    )zn
    ( \\U........
    | \\u....
    | \\x..
    | \\[0-7]{1,3}
    | \\N\{[^}]+\}
    | \\[\\'"abfnrtv]
    )cCs<dd�}tjddkr,t|t�r,t�||�St�||�SdS)z>replace C-style escape sequences (
, ", etc.) with real chars.cSstt�|�d�d��S)Nrzunicode-escape)r�codecs�decoderx)r�rrr�decode_match�s�z'_unquote_c_string.<locals>.decode_matchrrtN)r3�version_info�
isinstance�bytes�ESCAPE_SEQUENCE_BYTES_RE�sub�ESCAPE_SEQUENCE_RE)r�r�rrrr��sr�r�zname email timestamp timezone)�__doc__Z
__future__r�collections�rer3r�Z
fastimportrrrZfastimport.helpersr�objectrr�compilervr}r,�VERBOSEr��UNICODEr�r��
namedtupler�rrrr�<module>s,Q

g�

�