https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/trac/versioncontrol/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/versioncontrol/__pycache__/api.cpython-310.pyc
o

�k�`���@s�ddlZddlmZmZddlmZddlmZmZm	Z	ddl
mZmZddl
TddlmZmZmZddlmZmZdd	lmZmZdd
lmZmZddlmZmZmZddlm Z dd
l!m"Z"ddl#m$Z$m%Z%m&Z&dd�Z'Gdd�de(�Z)Gdd�de(�Z*Gdd�de+�Z,Gdd�de+�Z-Gdd�de+�Z.Gdd�de/�Z0Gdd�de/�Z1Gdd �d e�Z2Gd!d"�d"e�Z3Gd#d$�d$e4ed%�Z5Gd&d'�d'e4ed%�Z6Gd(d)�d)e4ed%�Z7Gd*d+�d+e7�Z8dS),�N)�ABCMeta�abstractmethod)�datetime)�AdminCommandError�IAdminCommandProvider�get_dir_list)�
ConfigSection�Option)�*)�IResourceManager�Resource�ResourceNotFound)�as_bool�native_path)�
get_thread_id�	threading)�time_now�utc)�exception_to_unicode�printout�
to_unicode��_)�IRequestFilter)�Chrome�ITemplateProvider�add_warningcCs|p
|dtd�fvS)z3Check whether `reponame` is the default repository.�	(default)r��reponame�r �9/usr/lib/python3/dist-packages/trac/versioncontrol/api.py�
is_default"�r"c@�eZdZdZdS)�InvalidRepositoryz.Exception raised when a repository is invalid.N��__name__�
__module__�__qualname__�__doc__r r r r!r%'�r%c@r$)�InvalidConnectorz8Exception raised when a repository connector is invalid.Nr&r r r r!r,+r+r,c@s$eZdZdZdZdd�Zdd�ZdS)�IRepositoryConnectorz6Provide support for a specific version control system.NcC�dS)a}Return the types of version control systems that are supported.

        Yields `(repotype, priority)` pairs, where `repotype` is used to
        match against the repository's `type` attribute.

        If multiple provider match a given type, the `priority` is used to
        choose between them (highest number is highest priority).

        If the `priority` returned is negative, this indicates that the
        connector for the given `repotype` indeed exists but can't be
        used for some reason. The `error` property can then be used to
        store an error message or exception relevant to the problem detected.
        Nr r r r r!�get_supported_types4�z(IRepositoryConnector.get_supported_typescCr.)zLReturn a Repository instance for the given repository type and dir.
        Nr )�
repos_type�	repos_dir�paramsr r r!�get_repositoryCr0z#IRepositoryConnector.get_repository)r'r(r)r*�errorr/r4r r r r!r-/s
r-c@seZdZdZdd�ZdS)�IRepositoryProviderz,Provide known named instances of Repository.cCr.)a�Generate repository information for known repositories.

        Repository information is a key,value pair, where the value is
        a dictionary which must contain at the very least either of
        the following entries:

         - `'dir'`: the repository directory which can be used by the
                    connector to create a `Repository` instance. This
                    defines a "real" repository.

         - `'alias'`: the name of another repository. This defines an
                      alias to another (real) repository.

        Optional entries:

         - `'type'`: the type of the repository (if not given, the
                     default repository type will be used).

         - `'description'`: a description of the repository (can
                            contain WikiFormatting).

         - `'hidden'`: if set to `'true'`, the repository is hidden
                       from the repository index (default: `'false'`).

         - `'sync_per_request'`: if set to `'true'`, the repository will be
                                 synchronized on every request (default:
                                 `'false'`).

         - `'url'`: the base URL for checking out the repository.
        Nr r r r r!�get_repositoriesKr0z$IRepositoryProvider.get_repositoriesN)r'r(r)r*r7r r r r!r6Hsr6c@s eZdZdZdd�Zdd�ZdS)�IRepositoryChangeListenerz#Listen for changes in repositories.cCr.)z8Called after a changeset has been added to a repository.Nr )�repos�	changesetr r r!�changeset_addedor0z)IRepositoryChangeListener.changeset_addedcCr.)z�Called after a changeset has been modified in a repository.

        The `old_changeset` argument contains the metadata of the changeset
        prior to the modification. It is `None` if the old metadata cannot
        be retrieved.
        Nr )r9r:�
old_changesetr r r!�changeset_modifiedrr0z,IRepositoryChangeListener.changeset_modifiedN)r'r(r)r*r;r=r r r r!r8lsr8c@s�eZdZdZeee�dZdd�Zdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zd"dd�Zdd�Zdd�Zdd�Zd"dd�Zdd�Zdd�Zd d!�ZdS)#�DbRepositoryProviderz6Component providing repositories registered in the DB.)�alias�description�dir�hidden�name�sync_per_request�type�urlcCs�i}|j�dd�dd�|jD���D]\}}}|dur$||�|i�|<qi}|��D]#\}}d|vrEd|vs;d|vrE||d	<|||d<t|�d
��|d
<q+t|���S)z;Retrieve repositories specified in the repository DB table.z9SELECT id, name, value FROM repository WHERE name IN (%s)�,css�|]}d|VqdS)z'%s'Nr )�.0�eachr r r!�	<genexpr>�s�z8DbRepositoryProvider.get_repositories.<locals>.<genexpr>NrCrAr?�idrD)	�env�db_query�join�repository_attrs�
setdefault�itemsr�get�iter)�selfr9rKrC�value�	reponames�infor r r!r7�s ���z%DbRepositoryProvider.get_repositoriesccsb�ddd|j|jfVddd|j|jfVddd	|j|jfVd
ddd
�|j�|j|j	fVdS)Nzrepository addz<repos> <dir> [type]zAdd a source repositoryzrepository aliasz<name> <target>z Create an alias for a repositoryzrepository removez<repos>zRemove a source repositoryzrepository setz<repos> <key> <value>zeSet an attribute of a repository

               The following keys are supported: %s
               z, )
�
_complete_add�_do_add�_complete_alias�	_do_alias�_complete_repos�
_do_removerNrO�
_complete_set�_do_set�rTr r r!�get_admin_commands�s&����
�
�z'DbRepositoryProvider.get_admin_commandscCst|j�}dd�|��D�S)NcSsg|]}|pd�qS)rr )rHrr r r!�
<listcomp>�sz6DbRepositoryProvider.get_reponames.<locals>.<listcomp>)�RepositoryManagerrL�get_all_repositories)rT�rmr r r!�
get_reponames�s
�z"DbRepositoryProvider.get_reponamescCs8t|�dkr
t|dd�St|�dkrt|j���SdS)N����T�)�lenrrcrLr/�rT�argsr r r!rX�s
�z"DbRepositoryProvider._complete_addcC�t|�dkr
|��SdS)Nrg�rjrfrkr r r!rZ���z$DbRepositoryProvider._complete_aliascCrm)N�rnrkr r r!r\�roz$DbRepositoryProvider._complete_reposcCs*t|�dkr
|��St|�dkr|jSdS)Nrprg)rjrfrOrkr r r!r^�s
�z"DbRepositoryProvider._complete_setNcCs|�|tj�|�|�dS�N)�add_repository�os�path�abspath)rTrrA�type_r r r!rY�szDbRepositoryProvider._do_addcCs|�||�dSrq)�	add_alias)rTr�targetr r r!r[��zDbRepositoryProvider._do_aliascCs|�|�dSrq)�remove_repository)rTrr r r!r]�szDbRepositoryProvider._do_removecCs�||jvr
ttd|d���|dkrtj�|�}|�|||i�|s#d}|dkr1ttd|d��dS|dkr?ttd|d��dSdS)	NzInvalid key "%(key)s"��keyrArz0You should now run "repository resync %(name)s".�rCrEz1You may have to run "repository resync %(name)s".)rOrrrsrtru�modify_repositoryr)rTrr|rUr r r!r_�s 
���zDbRepositoryProvider._do_setcCs�tj�|�sttd���t|�rd}t|j�}|r'||��vr'ttd|d���|jj	�}|�
|�}|�d|d|f|d|p=dfg�Wd�n1sKwY|��dS)	zAdd a repository.�)The repository directory must be absolute�z/The repository type '%(type)s' is not supported)rE�<INSERT INTO repository (id, name, value) VALUES (%s, %s, %s)rArEN)
rsrt�isabs�	TracErrorrr"rcrLr/�db_transaction�get_repository_id�executemany�reload_repositories)rTrrArvre�dbrKr r r!rr�s&
�

���z#DbRepositoryProvider.add_repositorycCs�t|�rd}t|�rd}t|j�}|��}||vr#ttd|pdd���d||vr3ttd|p/dd���|jj�}|�|�}|�d|dd	f|d|fg�Wd	�n1sUwY|�	�d	S)
zCreate an alias repository.r�z#Repository "%(repo)s" doesn't existr��repor?z.Cannot create an alias to the alias "%(repo)s"r�rAN)
r"rcrLrdr�rr�r�r�r�)rTrrxre�repositoriesr�rKr r r!rw�s0
��

���zDbRepositoryProvider.add_aliascs�t��rd�t|j�}|��}t�fdd�|��D��r&ttd�p"dd���|jj�}|�	��}|d|f�|d|f�|d	|f�Wd
�n1sLwY|�
�d
S)zRemove a repository.r�c3��|]
}�|�d�kVqdS�r?N�rR�rHr9rr r!rJ	���z9DbRepositoryProvider.remove_repository.<locals>.<genexpr>z8Cannot remove the repository "%(repos)s" used in aliasesr�r9z"DELETE FROM repository WHERE id=%sz#DELETE FROM revision WHERE repos=%sz&DELETE FROM node_change WHERE repos=%sN)r"rcrLrd�any�valuesr�rr�r�r�)rTrrer�r�rKr rr!rzs"
��

�z&DbRepositoryProvider.remove_repositoryc
snt��rd�|�d��}t|�rd}t|j�}�|kr6|��}t�fdd�|��D��r6ttd�p2dd���|jj	�o}|�
��}�|krT|d|f�rTttd	|pPdd
���|��D]I\}}	||jvrbqX|dvrlt|	�rld}	|dvrxt
|	�rvd
nd}	|dkr�tj�t|	��s�ttd���|d|	||f�|d||f�s�|d|||	f�qXWd�n1s�wY|��dS)z"Modify attributes of a repository.r�rCc3r�r�r�r�rr r!rJr�z9DbRepositoryProvider.modify_repository.<locals>.<genexpr>z8Cannot rename the repository "%(repos)s" used in aliasesrr�zQSELECT id FROM repository WHERE name='name' AND
                         value=%sz)The repository "%(name)s" already exists.r})r?rC)rBrD�1NrArz6UPDATE repository SET value=%s WHERE id=%s AND name=%sz4SELECT value FROM repository WHERE id=%s AND name=%szqINSERT INTO repository (id, name, value)
                          VALUES (%s, %s, %s)
                          )r"rRrcrLrdr�r�r�rr�r�rQrOrrsrtr�rr�)
rTr�changes�new_reponamerer�r�rK�k�vr rr!r~s\
��

��
������z&DbRepositoryProvider.modify_repositoryrq)r'r(r)r*�
implementsr6rrOr7rarfrXrZr\r^rYr[r]r_rrrwrzr~r r r r!r>{s&


r>c@seZdZdZeeeee�dZ	dZ
dZee
�Zee�Zee�Zedd�Zeddd	d
�Zdd�Zd
d�Zdd�Zdd�Zd:dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Z d"d#�Z!d$d%�Z"d&d'�Z#d(d)�Z$d*d+�Z%d,d-�Z&d.d/�Z'd0d1�Z(d2d3�Z)d:d4d5�Z*d6d7�Z+d8d9�Z,dS);rczVersion control system manager.r:�source�
repositoryr�aOne of the methods for registering repositories is to
        populate the `[repositories]` section of `trac.ini`.

        This is especially suited for setting up aliases, using a
        [TracIni#GlobalConfiguration shared configuration], or specifying
        repositories at the time of environment creation.

        See [TracRepositoryAdmin#ReposTracIni TracRepositoryAdmin] for
        details on the format of this section, and look elsewhere on the
        page for information on other repository providers.
        �versioncontrol�default_repository_type�svnz�Default repository connector type.

        This is used as the default repository type for repositories
        defined in the [TracIni#repositories-section repositories] section
        or using the "Repositories" admin panel.
        cCs i|_t��|_d|_d|_dSrq)�_cacher�Lock�_lock�_connectors�_all_repositoriesr`r r r!�__init__ds

zRepositoryManager.__init__cCs|t|j�ur�|����D]{}t|�d��sq
t�}|dpd}z
|�|d�}|��WnOt	y6Yq
t
yS}zt|td|t
|�d��WYd}~n.d}~wty|}zt|td|t
|�d��|j�d|t|dd	��WYd}~nd}~ww|j�d
|t�|�q
|S)NrDrCrzdCan't synchronize with repository "%(name)s" (%(error)s). Look in the Trac log for more information.�rCr5z�Failed to sync with repository "%(name)s": %(error)s; repository information may be out of date. Look in the Trac log for more information including mitigation strategies.z�Failed to sync with repository "%s"; You may be able to reduce the impact of this issue by configuring the sync_per_request option; see https://trac.edgewall.org/wiki/TracRepositoryAdmin#ExplicitSync for more detail: %sT)�	tracebackz-Synchronized '%s' repository in %0.2f seconds)rrLrdr�rrRrr4�syncr,r�rrr�	Exception�logr5rrW)rT�req�handler�	repo_info�start�	repo_namer��er r r!�pre_process_requestlsH�����
���
�z%RepositoryManager.pre_process_requestcCs
|||fSrqr )rTr��template�data�metadatar r r!�post_process_request�s
z&RepositoryManager.post_process_requestccs�|jV|jV|jVdSrq)�changeset_realm�source_realm�repository_realmr`r r r!�get_resource_realms�s�z%RepositoryManager.get_resource_realmsNcKs&|j|jkr |j}|o
|j}|j}|rtd||d�Std|d�S|j|jkr}|j}|o-|j}|j}d}|dkr^|�|�}|�|j|j�}	|	j	rLtd�}
n|	j
rStd�}
|jr]td	|jd�}ntd
�}
|jrjd|j}|rrtd|d
�nd}td|
|||d�S|j|jkr�|js�td�Std|jd
�SdS)NzChangeset %(rev)s in %(repo)s)�revr�zChangeset %(rev)s�r�r��summary�	directory�filez at version %(rev)srtz@%sz in %(repo)sr�z(%(kind)s %(id)s%(at_version)s%(in_repo)s)�kindrK�
at_version�in_repozDefault repositoryzRepository %(repo)s)�realmr��parentrKrr�r4�get_node�version�isdir�isfiler�)rT�resource�format�kwargsr�rrKr�r9�noder�r�r r r!�get_resource_description�sD



�
��z*RepositoryManager.get_resource_descriptioncKs~|j|jkr|j}|�|j|r|jpd�S|j|jkr/|j}|j|r%|jp&d|j|jp,dd�S|j|jkr=|�|jp;d�SdS)Nr�)	r�r�r�r:rKr��browserr�r�)rTr��hrefr�r�r r r!�get_resource_url�s��z"RepositoryManager.get_resource_urlcCs�|j|jkr
|j}n|jj}t|j��|�}|sdS|j|jkr4z	|�|j�WdSt	y3YdSw|j|j
krPz|�|j|j�WdSt
yOYdSw|j|jkrXdSdS)NFT)r�r�rKr�rcrLr4r��
get_changeset�NoSuchChangesetr�r�r��
NoSuchNode)rTr�rr9r r r!�resource_exists�s.���z!RepositoryManager.resource_existsc	cs��|j}i}|D]}|�d�r|�|�rddi||dd�<q|D]$}|�|�}d|vr0|d7}|�d�rE||vrE||�|dd�i�d	<q!|D]}d|vrg|�dd
�\}}||vrg|d	krg|�|�|||<qH|��D]	\}}||fVqldS)z�Retrieve repositories specified in TracIni.

        The `[repositories]` section can be used to specify a list
        of repositories.
        z.dirrDFN����.z.aliasi����r?rp)�repositories_section�endswithrRrP�rsplitrQ)	rTr�rV�optionr?rC�detailrrWr r r!r7�s.��
���z"RepositoryManager.get_repositoriescC�gSrqr r`r r r!�get_htdocs_dirssz!RepositoryManager.get_htdocs_dirscCsddlm}|dd�gS)Nr)�resource_filenameztrac.versioncontrol�	templates)�
pkg_resourcesr�)rTr�r r r!�get_templates_dirssz$RepositoryManager.get_templates_dirscCsdd�|jD�}t|�S)z.Return the list of supported repository types.cSs.h|]}|��p	gD]
\}}|dkr
|�q
qS)r)r/)rH�	connectorrv�prior r r!�	<setcomp>s
��z8RepositoryManager.get_supported_types.<locals>.<setcomp>)�
connectors�list)rT�typesr r r!r/
s�z%RepositoryManager.get_supported_typescCs�tj�tj�t|��d�}g}|����D])\}}t|�d��}|r>tj�tj�|�d�}|�|�r>|�	|�}|r>|�
|�q|S)z�Retrieve the repositories based on the given directory.

           :param directory: the key for identifying the repositories.
           :return: list of `Repository` instances.
        r�rA)rsrtrN�normcaserrdrQrR�
startswithr4�append)rTr�r�r�repoinforAr9r r r!�get_repositories_by_dirs


�z)RepositoryManager.get_repositories_by_dircCs||jj�0}|d|f�D]
\}|Wd�S|d�ddd}|d|d|f�|Wd�S1s7wYdS)z�Return a unique id for the given repository name.

        This will create and save a new id if none is found.

        Note: this should probably be renamed as we're dealing
              exclusively with *db* repository ids here.
        z8SELECT id FROM repository WHERE name='name' AND value=%sNz+SELECT COALESCE(MAX(id), 0) FROM repositoryrrpr�rC)rLr�)rTrr�rKr r r!r�$s

���$�z#RepositoryManager.get_repository_idc		Cs>|pd}|���|i�}d|vr|d}|���|i�}t|�d��}|s'dS|�d�p.|j}|jj�b|j�Nt�}||jvrF|j|}ni}|j|<|�|�}|sut	j
�|�sct	j
�|jj
|�}|�
|�}|�|||���}|||<|Wd�Wd�S1s�wYWd�dS1s�wYdS)aRetrieve the appropriate `Repository` for the given
        repository name.

        :param reponame: the key for specifying the repository.
                         If no name is given, take the default
                         repository.
        :return: if no corresponding repository was defined,
                 simply return `None`.

        :raises InvalidConnector: if the repository connector cannot be
                                  opened.
        :raises InvalidRepository: if the repository cannot be opened.
        r�r?rANrE)rdrRrr�rLr�r�rr�rsrtr�rN�_get_connectorr4�copy)	rTrr��rdir�rtype�tidr�r9r�r r r!r47s:



���"�z RepositoryManager.get_repositorycCs�g}|r|�d�dnd}|��D]}|�d�d}|�|�r(|�t|�|f�q|r<|��|d\}}||d�}nd}||�|�|�d�pIdfS)a9Retrieve a matching `Repository` for the given `path`.

        :param path: the eventually scoped repository-scoped path
        :return: a `(reponame, repos, path)` triple, where `path` is
                 the remaining part of `path` once the `reponame` has
                 been truncated, if needed.
        �/rhNr�)�striprdr�r�rj�sortr4�rstrip)rTrt�matchesr�stripped_reponame�lengthr r r!�get_repository_by_pathas
�
�z(RepositoryManager.get_repository_by_pathcCs<|r|jj|j|jfvr|jjr|jjjS|j}|sdSdS)z�Recover the appropriate repository from the current context.

        Lookup the closest source or changeset resource in the context
        hierarchy and return the name of its associated repository.
        N)r�r�r�r�r�rK)rT�contextr r r!�get_default_repositoryxs
��
�z(RepositoryManager.get_default_repositorycCsv|js8i}|jD],}|��pgD]#\}}||vr |j�d|�q||d<d|vr/|�|�|d<|||<qq||_|jS)z?Return a dictionary of repository information, indexed by name.z$Discarding duplicate repository '%s'rCrK)r��	providersr7r��warningr�)rT�all_repositories�providerrrWr r r!rd�s
�
�	z&RepositoryManager.get_all_repositoriesc	CsXt�}|��D]}z|�|�}Wn	tyYqw|dur#|�|�qt|dd�d�S)zXReturn a sorted list of all real repositories (i.e. excluding
        aliases).
        NcS�|jSrqr��rr r r!�<lambda>��z9RepositoryManager.get_real_repositories.<locals>.<lambda>r{)�setrdr4r��add�sorted)rTr�rr9r r r!�get_real_repositories�s�
�z'RepositoryManager.get_real_repositoriescCs@|j�i|_d|_Wd�n1swY|j��dS)z+Reload the repositories from the providers.N)r�r�r��config�touchr`r r r!r��s
�z%RepositoryManager.reload_repositoriescs�|j�d||pd|�|�|�}g}|r|���ntj�|�}|�|�}|r)d�n|��r8�fdd�|��D�}|sN|j�	d�pA|�t
d|pJt
d�d�gSg}t|d	d
�d�D]�}|jp^d}|�
�|D]�}g}	|dkr�z|�|�}
Wn"ty�}z|�t|��|j�	d
|||�WYd}~qed}~ww|	�|
�z|�|�}Wn9ty�z|�|�|�|�}Wn#ty�}z|�t|��|j�	d
|||�WYd}~Yqed}~wwYnw|j�d|||�|jD]}
t|
|�||g|	�R�q�qeqX|S)z�Notify repositories and change listeners about repository events.

        The supported events are the names of the methods defined in the
        `IRepositoryChangeListener` interface.
        z-Event %s on repository '%s' for changesets %rrNcsg|]
}|���kr|�qSr )�get_base)rHr��baser r!rb�s�z,RepositoryManager.notify.<locals>.<listcomp>z)Found no repositories matching '%s' base.zRepository '%(repo)s' not foundr�cSr�rqrr�r r r!r�rz*RepositoryManager.notify.<locals>.<lambda>r{r=zMNo changeset '%s' found in repository '%s'. Skipping subscribers for event %sz-Event %s on repository '%s' for revision '%s')r��debugr4r	rsrtrur�rr�rrrr��sync_changesetr�r�rr��change_listeners�getattr)rT�eventr�revsr9r�rA�errorsr�rlr<r�r:�listenerr r
r!�notify�s�
�


�
�
���

������
��zRepositoryManager.notifycCsj|r3|t�ks	J�|j�|j�|i�}|��D]\}}|��qWd�dS1s,wYdSdS)z>Free `Repository` instances bound to a given thread identifierN)rr�r��poprQ�close)rTr�r�rr9r r r!�shutdown�s
�"��zRepositoryManager.shutdownc	Cs�|�|�dd�\}}|sdSd}d|vr|�dd�\}}z|�||�}Wnttfy1YdSw|��}|r>t|���SdS)a�Read the file specified by `path`

        :param path: the repository-scoped path. The repository revision may
                     specified by appending `@` followed by the revision,
                     otherwise the HEAD revision is assumed.
        :return: the file content as a `str` string. `None` is returned if
                 the file is not found.

        :since: 1.2.2
        rpN�@)r��splitr�r�r��get_contentr�read)rTrtr9r�r��contentr r r!�read_file_by_path�s��z#RepositoryManager.read_file_by_pathcCs�|jdur4i|_|jD](}|��pgD]\}}||f}||jvr+||j|dkr+d}|r2||j|<qq||jvrR|j|\}}|dkrF|Sttd|t|j�d���ttd|d���)z�Retrieve the appropriate connector for the given repository type.

        Note that the self._lock must be held when calling this method.
        Nrprz8Unsupported version control system "%(name)s": %(error)sr�z�Unsupported version control system "%(name)s": Can't find an appropriate component, maybe the corresponding plugin was not enabled? r})r�r�r/r,rrr5)rTr�r�rvr��keepr r r!r�s6



��
����z RepositoryManager._get_connectorrq)-r'r(r)r*r�rrr6rr�r�r��ExtensionPointr-r�r�r8rrr�r	r�r�r�r�r�r�r�r�r7r�r�r/r�r�r4r�r�rdrr�rrrr�r r r r!rc@sR��
�	$
$*

D	rcc@seZdZdd�ZdS)r�cCst�|td|d�td��dS)Nz&No changeset %(rev)s in the repositoryr�zNo such changeset)r
r�r�rTr�r r r!r�6s��zNoSuchChangeset.__init__N�r'r(r)r�r r r r!r�5sr�c@seZdZddd�ZdS)r�NcCs>|durtd||d�}ntd|||d�}t�||td��dS)Nz$No node %(path)s at revision %(rev)s)rtr�z-%(msg)s: No node %(path)s at revision %(rev)s)�msgrtr�zNo such node)rr
r�)rTrtr�r"r r r!r�>s�zNoSuchNode.__init__rqr!r r r r!r�=sr�c@s`eZdZdZdZdZejZe	dd��Z
dd�Zdd	�Ze
d
d��Zdd
�ZdBdd�ZdCdd�Zdd�Zdd�Zdd�Ze
dd��Zdd�Zdd�ZdBdd �Ze
dBd!d"��Ze
d#d$��Ze	d%d&��Ze
d'd(��Ze	d)d&��Ze
dDd+d,��Ze
dDd-d.��Zd/d0�Z e
d1d2��Z!e
dEd3d4��Z"e
d5d6��Z#e
d7d8��Z$d9d:�Z%d;d<�Z&e
	=dFd>d?��Z'd@dA�Z(e(Z)dS)G�
RepositoryzABase class for a repository provided by a version control system.Fr�cCst|j|j�Srq)rr�rr`r r r!r�P�zRepository.resourcecCs*||_||_|d|_|d|_||_dS)auInitialize a repository.

           :param name: a unique name identifying the repository, usually a
                        type-specific prefix followed by the path to the
                        repository.
           :param params: a `dict` of parameters for the repository. Contains
                          the name of the repository under the key "name" and
                          the surrogate key that identifies the repository in
                          the database under the key "id".
           :param log: a logger instance.

           :raises InvalidRepository: if the repository cannot be opened.
        rCrKN)rCr3rrKr�)rTrCr3r�r r r!r�Ts



zRepository.__init__cCsd|jj|j|j|jfS)Nz
<%s %r %r %r>)�	__class__r'rKrC�scoper`r r r!�__repr__hs�zRepository.__repr__cCr.)z'Close the connection to the repository.Nr r`r r r!rl�zRepository.closecCr�)z�Return the name of the base repository for this repository.

        This function returns the name of the base repository to which scoped
        repositories belong. For non-scoped repositories, it returns the
        repository name.
        r}r`r r r!r	qszRepository.get_baseNcCr.)z�Clear any data that may have been cached in instance properties.

        `youngest_rev` can be specified as a way to force the value
        of the `youngest_rev` property (''will change in 0.12'').
        Nr )rT�youngest_revr r r!�clearz�zRepository.clearcCr.)acPerform a sync of the repository cache, if relevant.

        If given, `rev_callback` must be a callable taking a `rev` parameter.
        The backend will call this function for each `rev` it decided to
        synchronize, once the synchronization changes are committed to the
        cache. When `clean` is `True`, the cache is cleaned first.
        Nr )rT�rev_callback�cleanr r r!r���zRepository.synccCr.)aResync the repository cache for the given `rev`, if relevant.

        Returns a "metadata-only" changeset containing the metadata prior to
        the resync, or `None` if the old values cannot be retrieved (typically
        when the repository is not cached).
        Nr r r r r!r
��zRepository.sync_changesetcCr�)aGenerate a list of interesting places in the repository.

        `rev` might be used to restrict the list of available locations,
        but in general it's best to produce all known locations.

        The generated results must be of the form (category, name, path, rev).
        r r r r r!�get_quickjump_entries�r.z Repository.get_quickjump_entriescCr.)a2Return the repository URL for the given path and revision.

        The returned URL can be `None`, meaning that no URL has been specified
        for the repository, an absolute URL, or a scheme-relative URL starting
        with `//`, in which case the scheme of the request should be prepended.
        Nr �rTrtr�r r r!�get_path_url�r/zRepository.get_path_urlcCr.)z?Retrieve a Changeset corresponding to the given revision `rev`.Nr r r r r!r��r(zRepository.get_changesetcCr.)z�Return a globally unique identifier for the ''rev'' changeset.

        Two changesets from different repositories can sometimes refer to
        the ''very same'' changeset (e.g. the repositories are clones).
        Nr r r r r!�get_changeset_uid�r0zRepository.get_changeset_uidccsJ�|j}|r#|�|�}|j|krdS|j|kr|V|�|�}|sdSdS)zMGenerate Changeset belonging to the given time period (start, stop).
        N)r)r��date�previous_rev)rTr��stopr��chgsetr r r!�get_changesets�s�



�zRepository.get_changesetscCs(z	|�||�WdStyYdSw)z�Tell if there's a node at the specified (path,rev) combination.

        When `rev` is `None`, the latest revision is implied.
        TF)r�r�r1r r r!�has_node�s�zRepository.has_nodecCr.)aXRetrieve a Node from the repository at the given path.

        A Node represents a directory or a file at a given revision in the
        repository.
        If the `rev` parameter is specified, the Node corresponding to that
        revision is returned, otherwise the Node corresponding to the youngest
        revision is returned.
        Nr r1r r r!r��s
zRepository.get_nodecCr.)z4Return the oldest revision stored in the repository.Nr r`r r r!�get_oldest_rev�r(zRepository.get_oldest_revcC�|��Srq)r:r`r r r!r��zRepository.<lambda>cCr.)z/Return the youngest revision in the repository.Nr r`r r r!�get_youngest_rev�r(zRepository.get_youngest_revcCr;rq)r=r`r r r!r�r<r�cCr.)z�Return the revision immediately preceding the specified revision.

        If `path` is given, filter out ancestor revisions having no changes
        below `path`.

        In presence of multiple parents, this follows the first parent.
        Nr �rTr�rtr r r!r5��	zRepository.previous_revcCr.)z�Return the revision immediately following the specified revision.

        If `path` is given, filter out descendant revisions having no changes
        below `path`.

        In presence of multiple children, this follows the first child.
        Nr r>r r r!�next_rev�r?zRepository.next_revcCs|�|�}|dur|gSgS)z3Return a list of parents of the specified revision.N)r5)rTr�r�r r r!�parent_revs�s
zRepository.parent_revscCr.)zjProvides a total order over revisions.

        Return `True` if `rev1` is an ancestor of `rev2`.
        Nr )rT�rev1�rev2r r r!�rev_older_than�r+zRepository.rev_older_thancCr.)aRetrieve all the revisions containing this path.

        If given, `rev` is used as a starting point (i.e. no revision
        ''newer'' than `rev` should be returned).
        The result format should be the same as the one of Node.get_history()
        Nr )rTrtr��limitr r r!�get_path_historyr.zRepository.get_path_historycCr.)z7Return a canonical representation of path in the repos.Nr )rTrtr r r!�normalize_pathr(zRepository.normalize_pathcCr.)a�Return a (unique) canonical representation of a revision.

        It's up to the backend to decide which string values of `rev`
        (usually provided by the user) should be accepted, and how they
        should be normalized. Some backends may for instance want to match
        against known tags or branch names.

        In addition, if `rev` is `None` or '', the youngest revision should
        be returned.

        :raise NoSuchChangeset: If the given `rev` isn't found.
        Nr r r r r!�
normalize_revszRepository.normalize_revcC�|�|�}|dur
t|�S|S)z�Return a compact string representation of a revision in the
        repos.

        :raise NoSuchChangeset: If the given `rev` isn't found.
        :since 1.2: Always returns a string or `None`.
        N�rH�str�rTr��norm_revr r r!�	short_rev%s
zRepository.short_revcCrI)aAReturn a string representation of a revision in the repos for
        displaying to the user.

        This can be a shortened revision string, e.g. for repositories
        using long hashes.

        :raise NoSuchChangeset: If the given `rev` isn't found.
        :since 1.2: Always returns a string or `None`.
        NrJrLr r r!�display_rev/s

zRepository.display_revrpcCr.)afGenerates changes corresponding to generalized diffs.

        Generator that yields change tuples (old_node, new_node, kind, change)
        for each node change between the two arbitrary (path,rev) pairs.

        The old_node is assumed to be None when the change is an ADD,
        the new_node is assumed to be None when the change is a DELETE.
        Nr )rT�old_path�old_rev�new_path�new_rev�ignore_ancestryr r r!�get_changes<szRepository.get_changescCsd||j�dd��vS)z<Return True if view permission is granted on the repository.�BROWSER_VIEWr�r�)r��child�rT�permr r r!�is_viewableIr#zRepository.is_viewablerq)NF)r�)NN)rp)*r'r(r)r*�has_linear_changesetsr&rcr�r��propertyr�r�r'rrr	r*r�r
r0r2r�r3r8r9r�r:�
oldest_revr=r)r5r@rArDrFrGrHrNrOrUrZ�can_viewr r r r!r#Gsd


	

	
	






	



�r#)�	metaclassc@seZdZdZdZdZejZe	dd��Z
dZdZdd�Z
d	d
�Zedd��Zd+dd�Zedd��Zed,dd��Zdd�Zedd��Zedd��Zedd��Ze	dd��Zedd��Ze	d d��Zd!d"�Ze	d#d��Zed$d%��Ze	d&d��Ze	d'd��Ze	d(d��Z d)d*�Z!e!Z"dS)-�NodezERepresents a directory or file in the repository at a given revision.rAr�cCst|j|j|j|jj�Srq)rr�rtr�r9r�r`r r r!r�Xsz
Node.resourceNcCs<|tjtjfvsJd|��||_t|�|_||_||_dS)NzUnknown node kind %s)r`�	DIRECTORY�FILEr9rrtr�r�)rTr9rtr�r�r r r!r�ds�

z
Node.__init__cCs>d|jj|jf}|jdur|dt|j�7}d|jj|fS)Nz%s:%sr�<%s %r>)r9rCrtr�rKr%r'�rTrCr r r!r'ls
z
Node.__repr__cCr.)z�Return a stream for reading the content of the node.

        This method will return `None` for directories.
        The returned object must support a `read([len])` method.
        Nr r`r r r!rrr/zNode.get_contentTcCr;)a�Return a stream for reading the content of the node, with some
        standard processing applied.

        :param keyword_substitution: if `True`, meta-data keywords
            present in the content like ``$Rev$`` are substituted
            (which keyword are substituted and how they are
            substituted is backend specific)

        :param eol_hint: which style of line ending is expected if
            `None` was explicitly specified for the file itself in
            the version control backend (for example in Subversion,
            if it was set to ``'native'``).  It can be `None`,
            ``'LF'``, ``'CR'`` or ``'CRLF'``.
        )r)rT�keyword_substitution�eol_hintr r r!�get_processed_content{szNode.get_processed_contentcCr.)z�Generator that yields the immediate child entries of a directory.

        The entries are returned in no particular order.
        If the node is a file, this method returns `None`.
        Nr r`r r r!�get_entries�r/zNode.get_entriescCr.)a�Provide backward history for this Node.

        Generator that yields `(path, rev, chg)` tuples, one for each revision
        in which the node was changed. This generator will follow copies and
        moves of a node (if the underlying version control system supports
        that), which will be indicated by the first element of the tuple
        (i.e. the path) changing.
        Starts with an entry for the current revision.

        :param limit: if given, yield at most ``limit`` results.
        Nr )rTrEr r r!�get_history��
zNode.get_historycCs(d}|�d�D]
}|rd}q|SdS)zzReturn the change event corresponding to the previous revision.

        This returns a `(path, rev, chg)` tuple.
        TrgFN)ri)rT�skip�pr r r!�get_previous�s�zNode.get_previouscCr.)z�Provide detailed backward history for the content of this Node.

        Retrieve an array of revisions, one `rev` for each line of content
        for that node.
        Only expected to work on (text) FILE nodes, of course.
        Nr r`r r r!�get_annotations�r.zNode.get_annotationscCr.)z�Returns the properties (meta-data) of the node, as a dictionary.

        The set of properties depends on the version control system.
        Nr r`r r r!�get_properties�r+zNode.get_propertiescCr.)zUThe length in bytes of the content.

        Will be `None` for a directory.
        Nr r`r r r!�get_content_length�r+zNode.get_content_lengthcCr;rq)rpr`r r r!r�r<z
Node.<lambda>cCr.)zgThe MIME type corresponding to the content, if known.

        Will be `None` for a directory.
        Nr r`r r r!�get_content_type�r+zNode.get_content_typecCr;rq)rqr`r r r!r�r<cCs|j�d�dS)Nr�rh)rtrr`r r r!�get_name�ryz
Node.get_namecCr;rq)rrr`r r r!r�r<cCsdSrqr r`r r r!�get_last_modified�szNode.get_last_modifiedcCr;rq)rsr`r r r!r�r<cC�|jtjkSrq)r�r`rar`r r r!r��cCrtrq)r�r`rbr`r r r!r�rucCs|jrdnd||j�vS)z6Return True if view permission is granted on the node.rV�	FILE_VIEW)r�r�rXr r r!rZ�s�zNode.is_viewable)TNrq)#r'r(r)r*rarbrcr�r�r\r��created_rev�created_pathr�r'rrrgrhrirmrnrorp�content_lengthrq�content_typerrrCrs�
last_modifiedr�r�rZr^r r r r!r`PsL




	



r`c@s�eZdZdZdZdZdZdZdZeeefZ	eefZ
e	e
Zej
Zedd��Zd	d
�Zdd�Zd
d�Zedd��Zdd�Zdd�Zdd�Zdd�ZeZdS)�	Changesetz>Represents a set of changes committed at once in a repository.rr��delete�edit�movecCst|j|j|jjd�S)N)r�)rr�r�r9r�r`r r r!r��r#zChangeset.resourcecCs*||_||_|p	d|_|pd|_||_dS)Nr�)r9r��message�authorr4�rTr9r�r�r�r4r r r!r��s



zChangeset.__init__cCs"d|jj|jf}d|jj|fS)Nz%s@%src)r9rCr�r%r'rdr r r!r'szChangeset.__repr__cCr�)adReturns the properties (meta-data) of the node, as a dictionary.

        The set of properties depends on the version control system.

        Warning: this used to yield 4-elements tuple (besides `name` and
        `text`, there were `wikiflag` and `htmlclass` values).
        This is now replaced by the usage of IPropertyRenderer (see #1601).
        r r`r r r!ror?zChangeset.get_propertiescCr.)aSGenerator that produces a tuple for every change in the changeset.

        The tuple will contain `(path, kind, change, base_path, base_rev)`,
        where `change` can be one of Changeset.ADD, Changeset.COPY,
        Changeset.DELETE, Changeset.EDIT or Changeset.MOVE,
        and `kind` is one of Node.FILE or Node.DIRECTORY.
        The `path` is the targeted path for the `change` (which is
        the ''deleted'' path  for a DELETE change).
        The `base_path` and `base_rev` are the source path and rev for the
        action (`None` and `-1` in the case of an ADD change).
        Nr r`r r r!rUrjzChangeset.get_changescCr�)aYield branches to which this changeset belong.
        Each branch is given as a pair `(name, head)`, where `name` is
        the branch name and `head` a flag set if the changeset is a head
        for this branch (i.e. if it has no children changeset).
        r r`r r r!�get_branches!r+zChangeset.get_branchescCr�)zSYield tags associated with this changeset.

        .. versionadded :: 1.0
        r r`r r r!�get_tags)�zChangeset.get_tagscCr�)zZYield bookmarks associated with this changeset.

        .. versionadded :: 1.1.5
        r r`r r r!�
get_bookmarks0r�zChangeset.get_bookmarkscCsd||j�vS)z;Return True if view permission is granted on the changeset.�CHANGESET_VIEW)r�rXr r r!rZ7r$zChangeset.is_viewableN)r'r(r)r*�ADD�COPY�DELETE�EDIT�MOVE�DIFF_CHANGES�
OTHER_CHANGES�ALL_CHANGESrcr�r�r\r�r�r'rorrUr�r�r�rZr^r r r r!r|�s.


r|cs*eZdZdZd�fdd�	Zdd�Z�ZS)�EmptyChangesetzeChangeset that contains no changes. This is typically used when the
    changeset can't be retrieved.Ncs0|durtdddtd�}t��|||||�dS)Ni�rp)�tzinfo)rr�superr�r��r%r r!r�BszEmptyChangeset.__init__cCstg�Srq)rSr`r r r!rUGszEmptyChangeset.get_changes)NNN)r'r(r)r*r�rU�
__classcell__r r r�r!r�>sr�)9�os.pathrs�abcrrr�
trac.adminrrr�trac.configrr	�	trac.core�
trac.resourcerrr
�	trac.utilrr�trac.util.concurrencyrr�trac.util.datefmtrr�trac.util.textrrr�trac.util.translationr�trac.web.apir�trac.web.chromerrrr"r�r%r,�	Interfacer-r6r8�	Componentr>rcr�r��objectr#r`r|r�r r r r!�<module>sF$Fx
V

https://t.me/RX1948 - 2025