Skip to content
Open
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
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Authors:
Michał Górny
Mukunda Rao Katta
Na'aman Hirschfeld
Nicholas Williams
Nicolas Rybowski
Nicolás Sanguinetti
Nikita Kartashov
Expand Down
21 changes: 15 additions & 6 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@
Configuration files
**********************************************************************

.. autoclass:: pygit2.Repository
:members: config
:noindex:
.. autoclass:: pygit2.repository.BaseRepository
:members: config, config_snapshot


The Config type
The Config types
================

.. autoclass:: pygit2.Config
:members:
:undoc-members:
:special-members: __contains__, __delitem__, __getitem__, __iter__, __setitem__
:special-members: __contains__, __delitem__, __getitem__, __init__, __iter__, __setitem__

.. autoclass:: pygit2.DefaultConfig
:members: __enter__, __exit__, add_file, snapshot
:undoc-members:
:special-members: __init__

.. autoclass:: pygit2.RepositoryConfig
:members: __enter__, __exit__, add_file, snapshot
:undoc-members:
:special-members: __init__


The ConfigEntry type
====================

.. autoclass:: pygit2.config.ConfigEntry
:members: name, value, level
:members: level, name, raw_level, raw_name, raw_value, value
8 changes: 7 additions & 1 deletion pygit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@
git_fetch_options,
git_proxy_options,
)
from .config import Config
from .config import (
Config,
DefaultConfig,
RepositoryConfig,
)
from .credentials import *
from .errors import Passthrough, check_error
from .ffi import C, ffi
Expand Down Expand Up @@ -897,6 +901,7 @@ def filter_unregister(name: str) -> None:
'get_credentials',
'config',
'Config',
'DefaultConfig',
'credentials',
'CredentialType',
'Username',
Expand All @@ -921,6 +926,7 @@ def filter_unregister(name: str) -> None:
'Remote',
'repository',
'Repository',
'RepositoryConfig',
'branches',
'references',
'settings',
Expand Down
8 changes: 8 additions & 0 deletions pygit2/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,13 @@ def get_libgit2_paths() -> tuple[Path, dict[str, list[str]]]:
'libraries': ['git2'],
'include_dirs': [str(x) for x in include_dirs],
'library_dirs': [str(x) for x in library_dirs],
# For debugging memory issues (segfaults) during development, uncomment the
# following lines and rebuild everything. YMMV
# 'extra_compile_args': [
# '-fsanitize=address',
# '-fsanitize-address-use-after-scope',
# '-fsanitize-address-use-odr-indicator',
# ],
# 'extra_link_args': ['-fsanitize=address'],
},
)
153 changes: 148 additions & 5 deletions pygit2/_libgit2/ffi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

from typing import Any, Generic, Literal, NewType, SupportsIndex, TypeVar, overload

from __future__ import annotations

from collections.abc import Callable
from typing import (
Any,
Generic,
Literal,
NewType,
ParamSpec,
SupportsIndex,
TypeVar,
overload,
)

P = ParamSpec('P')
T = TypeVar('T')

NULL_TYPE = NewType('NULL_TYPE', object)
Expand All @@ -45,6 +57,11 @@ class int64_t:
class ssize_t:
def __getitem__(self, item: Literal[0]) -> int: ...

class uintptr_t:
def __int__(self) -> int: ...

class git_config_level_t(int): ...

class _Pointer(Generic[T]):
def __setitem__(self, item: Literal[0], a: T) -> None: ...
@overload
Expand Down Expand Up @@ -181,15 +198,66 @@ class GitConfigC:
pass

class GitConfigIteratorC:
# incomplete
pass
backend: 'GitConfigBackendC'
flags: int
next: Callable[['GitConfigBackendEntryC', GitConfigIteratorC], int]
free: Callable[[GitConfigIteratorC], None]

class GitConfigEntryC:
# incomplete
name: char_pointer
value: char_pointer
backend_type: char_pointer
origin_path: char_pointer
include_depth: int
level: int

class GitConfigBackendEntryC:
entry: GitConfigEntryC
free: Callable[[GitConfigBackendEntryC], None]

class GitConfigBackendC:
version: int
readonly: int
cfg: GitConfigC
open: Callable[[GitConfigBackendC, int, GitRepositoryC], int]
get: Callable[
[GitConfigBackendC, char_pointer, _Pointer[GitConfigBackendEntryC]], int
]
set: Callable[[GitConfigBackendC, char_pointer, char_pointer], int]
set_multivar: Callable[
[GitConfigBackendC, char_pointer, char_pointer, char_pointer], int
]
# this unfortunate name is actually `del`, but that conflicts with a Python keyword
del_: Callable[[GitConfigBackendC, char_pointer], int]
del_multivar: Callable[[GitConfigBackendC, char_pointer, char_pointer], int]
iterator: Callable[[_Pointer[GitConfigIteratorC], GitConfigBackendC], int]
snapshot: Callable[[_Pointer[GitConfigBackendC], GitConfigBackendC], int]
lock: Callable[[GitConfigBackendC], int]
unlock: Callable[[GitConfigBackendC, int], int]
free: Callable[[GitConfigBackendC], None]

class GitConfigBackendMemoryOptionsC:
version: int
backend_type: char_pointer
origin_path: char_pointer

class PyGitConfigBackendWrapperC:
parent: GitConfigBackendC
self: Any

class PyGitConfigBackendEntryC:
parent: GitConfigBackendEntryC
owner: PyGitConfigBackendWrapperC

class PyGitConfigIteratorWrapperC:
parent: GitConfigIteratorC
self: Any

class PyGitConfigIteratorEntryC:
parent: GitConfigBackendEntryC
owner: PyGitConfigIteratorWrapperC

class GitDescribeFormatOptionsC:
version: int
abbreviated_size: int
Expand Down Expand Up @@ -334,10 +402,41 @@ def new(a: Literal['git_config *']) -> GitConfigC: ...
@overload
def new(a: Literal['git_config **']) -> _Pointer[GitConfigC]: ...
@overload
def new(a: Literal['git_config_iterator *']) -> GitConfigIteratorC: ...
@overload
def new(a: Literal['git_config_iterator **']) -> _Pointer[GitConfigIteratorC]: ...
@overload
def new(a: Literal['git_config_entry **']) -> _Pointer[GitConfigEntryC]: ...
@overload
def new(a: Literal['git_config_backend *']) -> GitConfigBackendC: ...
@overload
def new(a: Literal['git_config_backend **']) -> _Pointer[GitConfigBackendC]: ...
@overload
def new(a: Literal['git_config_backend_entry *']) -> GitConfigBackendEntryC: ...
@overload
def new(
a: Literal['git_config_backend_memory_options *'],
) -> GitConfigBackendMemoryOptionsC: ...
@overload
def new(
a: Literal['git_config_level_t[]'],
b: list[git_config_level_t],
) -> list[git_config_level_t]: ...
@overload
def new(
a: Literal['_pygit_in_memory_backend_entry *'],
) -> PyGitConfigBackendEntryC: ...
@overload
def new(
a: Literal['_pygit_in_memory_backend_iterator_entry *'],
) -> PyGitConfigIteratorEntryC: ...
@overload
def new(a: Literal['_pygit_in_memory_backend *']) -> PyGitConfigBackendWrapperC: ...
@overload
def new(
a: Literal['_pygit_in_memory_backend_iterator *'],
) -> PyGitConfigIteratorWrapperC: ...
@overload
def new(a: Literal['git_describe_format_options *']) -> GitDescribeFormatOptionsC: ...
@overload
def new(a: Literal['git_describe_options *']) -> GitDescribeOptionsC: ...
Expand Down Expand Up @@ -399,7 +498,12 @@ def new(
def new(
a: Literal['char *[]'], b: list[Any]
) -> ArrayC[char_pointer]: ... # For string arrays
@overload
def addressof(a: object) -> _Pointer[object]: ...
@overload
def addressof(a: object, attribute: str) -> _Pointer[object]: ...
def def_extern() -> Callable[[Callable[P, T]], Callable[P, T]]: ...
def from_handle(a: _Pointer[T]) -> T: ...
def new_handle(a: T) -> _Pointer[T]: ...

class buffer(bytes):
Expand All @@ -420,3 +524,42 @@ def cast(a: Literal['size_t'], b: object) -> int: ...
def cast(a: Literal['ssize_t'], b: object) -> int: ...
@overload
def cast(a: Literal['char *'], b: object) -> char_pointer: ...
@overload
def cast(a: Literal['uintptr_t'], b: object) -> uintptr_t: ...
@overload
def cast(a: Literal['git_config_level_t'], b: int) -> git_config_level_t: ...
@overload
def cast(
a: Literal['git_config_backend *'],
b: PyGitConfigBackendWrapperC,
) -> GitConfigBackendC: ...
@overload
def cast(
a: Literal['_pygit_in_memory_backend *'],
b: GitConfigBackendC,
) -> PyGitConfigBackendWrapperC: ...
@overload
def cast(
a: Literal['git_config_iterator *'],
b: PyGitConfigIteratorWrapperC,
) -> GitConfigIteratorC: ...
@overload
def cast(
a: Literal['_pygit_in_memory_backend_iterator *'],
b: GitConfigIteratorC,
) -> PyGitConfigIteratorWrapperC: ...
@overload
def cast(
a: Literal['git_config_backend_entry *'],
b: PyGitConfigBackendEntryC | PyGitConfigIteratorEntryC,
) -> GitConfigBackendEntryC: ...
@overload
def cast(
a: Literal['_pygit_in_memory_backend_entry *'],
b: GitConfigBackendEntryC,
) -> PyGitConfigBackendEntryC: ...
@overload
def cast(
a: Literal['_pygit_in_memory_backend_iterator_entry *'],
b: GitConfigBackendEntryC,
) -> PyGitConfigIteratorEntryC: ...
12 changes: 6 additions & 6 deletions pygit2/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
# Boston, MA 02110-1301, USA.

"""
This is an special module, it provides stuff used by by pygit2 at run-time.
This is a special module, it provides stuff used by pygit2 at run-time.
"""

# Import from the Standard Library
import codecs
import sys
from pathlib import Path

Expand Down Expand Up @@ -69,6 +68,7 @@
'clone.h',
'common.h',
'config.h',
'config_bridge.h',
'describe.h',
'errors.h',
'graph.h',
Expand All @@ -88,17 +88,17 @@
]
h_source = []
for h_file in h_files:
h_file = dir_path / 'decl' / h_file # type: ignore
with codecs.open(h_file, 'r', 'utf-8') as f:
h_source.append(f.read())
h_path = dir_path / 'decl' / h_file
h_source.append(h_path.read_text(encoding='utf-8'))

C_HEADER_SRC = '\n'.join(h_source)

C_PREAMBLE = """\
#include <git2.h>
#include <git2/sys/config.h>
#include <git2/sys/repository.h>
#include <git2/sys/filter.h>
"""
""" + (dir_path / 'decl' / 'config_bridge.h').read_text(encoding='utf-8')

# ffi
_, libgit2_kw = get_libgit2_paths()
Expand Down
4 changes: 2 additions & 2 deletions pygit2/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def wrapper(*args):
data._stored_exception = e
return C.GIT_EUSER

return ffi.def_extern()(wrapper) # type: ignore[attr-defined]
return ffi.def_extern()(wrapper) # type: ignore[arg-type]


def libgit2_callback_void(f: Callable[P, T]) -> Callable[P, T]:
Expand All @@ -577,7 +577,7 @@ def wrapper(*args):
data._stored_exception = e
pass # Function returns void, so we can't do much here.

return ffi.def_extern()(wrapper) # type: ignore[attr-defined]
return ffi.def_extern()(wrapper) # type: ignore[arg-type]


@libgit2_callback
Expand Down
Loading
Loading