8000 Introduce Refdb type by ddevault · Pull Request #982 · libgit2/pygit2 · GitHub
[go: up one dir, main page]

Skip to content

Introduce Refdb type #982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
libgit2: ['maint/v0.99']
libgit2: ['master']
py:
- ver: '3.6'
release: '3.6.8' # last Python.org binary release
Expand Down
2 changes: 1 addition & 1 deletion .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi

cd ~

git clone --depth=1 -b "maint/v${LIBGIT2_VERSION}" https://github.com/libgit2/libgit2.git
git clone --depth=1 -b "${LIBGIT2_VERSION}" https://github.com/libgit2/libgit2.git
cd libgit2/

mkdir build && cd build
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
global:
LIBGIT2: ~/libgit2/_install/
LD_LIBRARY_PATH: ${LIBGIT2}/lib:${LD_LIBRARY_PATH}
LIBGIT2_VERSION: "0.99"
LIBGIT2_VERSION: "master"


jobs:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ build_script:
# Clone, build and install libgit2
- cmd: |
set LIBGIT2=%APPVEYOR_BUILD_FOLDER%\venv
git clone --depth=1 -b maint/v0.99 https://github.com/libgit2/libgit2.git libgit2
git clone --depth=1 -b master https://github.com/libgit2/libgit2.git libgit2
cd libgit2
cmake . -DBUILD_CLAR=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%LIBGIT2%" -G "%GENERATOR%"
cmake --build . --target install
Expand Down
40 changes: 37 additions & 3 deletions docs/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,41 @@
Backends
**********************************************************************

There is some support for custom backends, but undocumented. See
`<https://github.com/libgit2/pygit2/pull/690/commits>`_
The use of custom backends for the git object database (odb) and reference
database (refdb) are supported by pygit2.

Documentation contributions are very welcome.
.. contents:: Contents
:local:

The OdbBackend class
===================================

The OdbBackend class is subclassable and can be used to build a custom object
database.

.. autoclass:: pygit2.OdbBackend
:members:

Built-in OdbBackend implementations
===================================

.. autoclass:: pygit2.OdbBackendLoose
:members:

.. autoclass:: pygit2.OdbBackendPack
:members:

The RefdbBackend class
===================================

The RefdbBackend class is subclassable and can be used to build a custom
reference database.

.. autoclass:: pygit2.RefdbBackend
:members:

Built-in RefdbBackend implementations
=====================================

.. autoclass:: pygit2.RefdbFsBackend
:members:
< 6D40 div class="file-header d-flex flex-md-row flex-column flex-md-items-center file-header--expandable js-file-header js-skip-tagsearch sticky-file-header" data-path="docs/repository.rst" data-short-path="1176db5" data-anchor="diff-1176db57aea7c04e21ef4d052ab753fb8235916cd2b42309b7153f1e0e311109" data-file-type=".rst" data-file-deleted="false" >
13 changes: 10 additions & 3 deletions docs/repository.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ Below there are some general attributes and methods:
:members: ahead_behind, apply, create_reference, default_signature,
descendant_of, describe, free, is_bare, is_empty, odb, path,
path_is_ignored, reset, revert_commit, state_cleanup, workdir,
write_archive
write_archive, set_odb, set_refdb

The Repository constructor only takes one argument, the path of the
repository to open.
repository to open. Alternatively, constructing a repository with no
arguments will create a repository with no backends. You can use this path
to create repositories with custom backends. Note that most operations on
the repository are considered invalid and may lead to undefined behavior if
attempted before providing an odb and refdb via set_odb and set_refdb.

Example::

Expand All @@ -73,5 +77,8 @@ The Odb class
.. autoclass:: pygit2.Odb
:members:

.. autoclass:: pygit2.OdbBackend
The Refdb class
===================================

.. autoclass:: pygit2.Refdb
:members:
25 changes: 14 additions & 11 deletions pygit2/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@


class BaseRepository(_Repository):
def __init__(self, backend, *args, **kwargs):
super().__init__(backend, *args, **kwargs)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._common_init()

def _common_init(self):
Expand Down Expand Up @@ -1279,15 +1279,18 @@ def compress(self):


class Repository(BaseRepository):
def __init__(self, path, *args, **kwargs):
if hasattr(path, "__fspath__"):
path = path.__fspath__()

if not isinstance(path, str):
path = path.decode('utf-8')

path_backend = init_file_backend(path)
super().__init__(backend=path_backend, *args, **kwargs)
def __init__(self, *args, **kwargs):
if len(args) != 0:
path = args[0]
args = args[1:]
if hasattr(path, "__fspath__"):
path = path.__fspath__()
if not isinstance(path, str):
path = path.decode('utf-8')
path_backend = init_file_backend(path)
super().__init__(path_backend, *args, **kwargs)
else:
super().__init__(*args, **kwargs)

@classmethod
def _from_c(cls, ptr, owned):
Expand Down
Loading
0