File: //usr/lib/python3/dist-packages/hgext/__pycache__/sqlitestore.cpython-310.pyc
o
�]Lb�� � @ sl d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl m
Z
mZmZ ddl
mZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZ dd lm Z m!Z! zdd
lm"Z" e"j# W n e$yp dZ"Y nw i Z%e�&e%�Z&e&dde"rd
nddd� dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dddddd d!d"e- gZ4dGd#d$�Z5d%d&� Z6G d'd(� d(ej7�Z8ej9G d)d*� d*e:��Z;e�<ej=�ej9dd+�G d,d-� d-e:���Z>e�<ej?�ej9dd.�G d/d0� d0e:���Z@e�<ejA�G d1d2� d2e:��ZBG d3d4� d4ejC�ZDd5d6� ZEd7d8� ZFd9d:� ZGe�<ejH�G d;d<� d<e:��ZId=d>� ZJd?d@� ZKdAdB� ZLdCdD� ZMdEdF� ZNdS )Ham store repository data in SQLite (EXPERIMENTAL)
The sqlitestore extension enables the storage of repository data in SQLite.
This extension is HIGHLY EXPERIMENTAL. There are NO BACKWARDS COMPATIBILITY
GUARANTEES. This means that repositories created with this extension may
only be usable with the exact version of this extension/Mercurial that was
used. The extension attempts to enforce this in order to prevent repository
corruption.
In addition, several features are not yet supported or have known bugs:
* Only some data is stored in SQLite. Changeset, manifest, and other repository
data is not yet stored in SQLite.
* Transactions are not robust. If the process is aborted at the right time
during transaction close/rollback, the repository could be in an inconsistent
state. This problem will diminish once all repository data is tracked by
SQLite.
* Bundle repositories do not work (the ability to use e.g.
`hg -R <bundle-file> log` to automatically overlay a bundle on top of the
existing repository).
* Various other features don't work.
This extension should work for basic clone/pull, update, and commit workflows.
Some history rewriting operations may fail due to lack of support for bundle
repositories.
To use, activate the extension and set the ``storage.new-repo-backend`` config
option to ``sqlite`` to enable new repositories to use SQLite for storage.
� )�absolute_importN��_)�nullrev�sha1nodeconstants�short)�attr)�ancestor�dagop�encoding�error�
extensions� localrepo�mdiff�pycompat� registrar�requirements�util�verify)�
repositoryr )�hashutil�storageutil)�zstd� storage� sqlite.compression� zstd� zlibT)�default�experimentals ships-with-hg-cores exp-sqlite-001s exp-sqlite-comp-001=zstds exp-sqlite-comp-001=zlibs exp-sqlite-comp-001=nones exp-sqlite-shallow-files� � � � z�CREATE TABLE delta ( id INTEGER PRIMARY KEY, compression INTEGER NOT NULL, hash BLOB UNIQUE ON CONFLICT ABORT, delta BLOB NOT NULL )zKCREATE TABLE filepath ( id INTEGER PRIMARY KEY, path BLOB NOT NULL )z4CREATE UNIQUE INDEX filepath_path ON filepath (path)ac CREATE TABLE fileindex ( id INTEGER PRIMARY KEY, pathid INTEGER REFERENCES filepath(id), revnum INTEGER NOT NULL, p1rev INTEGER NOT NULL, p2rev INTEGER NOT NULL, linkrev INTEGER NOT NULL, flags INTEGER NOT NULL, deltaid INTEGER REFERENCES delta(id), deltabaseid INTEGER REFERENCES fileindex(id), node BLOB NOT NULL )zJCREATE UNIQUE INDEX fileindex_pathrevnum ON fileindex (pathid, revnum)zBCREATE UNIQUE INDEX fileindex_pathnode ON fileindex (pathid, node)a� CREATE VIEW filedata AS SELECT fileindex.id AS id, filepath.id AS pathid, filepath.path AS path, fileindex.revnum AS revnum, fileindex.node AS node, fileindex.p1rev AS p1rev, fileindex.p2rev AS p2rev, fileindex.linkrev AS linkrev, fileindex.flags AS flags, fileindex.deltaid AS deltaid, fileindex.deltabaseid AS deltabaseid FROM filepath, fileindex WHERE fileindex.pathid=filepath.idzPRAGMA user_version=%dc C s� | � djd�dgt|� �d�t||gt|�� � ��}g }d}|D ]-\} }
}| }|
tkr3|�|�}n|
t kr:|}n|
t
krDt�|�}ntd|
��|�
|� q"||v r[||| }n|�� }|�� t�||�}
t|
t�srt|�}
|
S )z&Resolve a delta chain for a file node.a WITH RECURSIVE deltachain(deltaid, baseid) AS ( SELECT deltaid, deltabaseid FROM fileindex WHERE pathid=? AND node=? UNION ALL SELECT fileindex.deltaid, deltabaseid FROM fileindex, deltachain WHERE fileindex.id=deltachain.baseid AND deltachain.baseid IS NOT NULL AND fileindex.id NOT IN ({stops}) ) SELECT deltachain.baseid, compression, delta FROM deltachain, delta WHERE delta.id=deltachain.deltaid�,�?)�stopsNs unhandled compression type: %d)�execute�format�join�len�tuple�list�keys�COMPRESSION_ZSTD�
decompress�COMPRESSION_NONE�COMPRESSION_ZLIB�zlib�SQLiteStoreError�append�pop�reverser �patches�
isinstance�bytes)�db�pathid�node�
revisioncache�stoprids�zstddctx�res�deltas�lastdeltabaseid�deltabaseid�compression�delta�basetext�fulltext� rG �3/usr/lib/python3/dist-packages/hgext/sqlitestore.py�resolvedeltachain� s: ���
rI c C sB z| � d|||f�jW S tjy | � d|f��� d Y S w )Nz=INSERT INTO delta (compression, hash, delta) VALUES (?, ?, ?)z!SELECT id FROM delta WHERE hash=?r )r&