Skip to content

Update to libgit2 v0.23 #540

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 2 commits into from
Jul 12, 2015
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 .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cd ~

git clone --depth=1 -b maint/v0.22 https://github.com/libgit2/libgit2.git
git clone --depth=1 -b maint/v0.23 https://github.com/libgit2/libgit2.git
cd libgit2/

mkdir build && cd build
Expand Down
30 changes: 15 additions & 15 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ while the last number |lq| *.micro* |rq| auto-increments independently.

As illustration see this table of compatible releases:

+-----------+--------+----------------------------------------+-------------------------------+
|**libgit2**| 0.22.0 | 0.21.1, 0.21.2 |0.20.0 |
+-----------+--------+----------------------------------------+-------------------------------+
|**pygit2** | 0.22.0 | 0.21.0, 0.21.1, 0.21.2, 0.21.3, 0.21.4 | 0.20.0, 0.20.1, 0.20.2, 0.20.3|
+-----------+--------+----------------------------------------+-------------------------------+
+-----------+--------+--------+----------------------------------------+
|**libgit2**| 0.23.0 | 0.22.0 | 0.21.1, 0.21.2 |
+-----------+--------+--------+----------------------------------------+
|**pygit2** | 0.23.0 | 0.22.0 | 0.21.0, 0.21.1, 0.21.2, 0.21.3, 0.21.4 |
+-----------+--------+--------+----------------------------------------+

.. warning::

Expand All @@ -56,9 +56,9 @@ directory, do:

.. code-block:: sh

$ wget https://github.com/libgit2/libgit2/archive/v0.22.0.tar.gz
$ tar xzf v0.22.0.tar.gz
$ cd libgit2-0.22.0/
$ wget https://github.com/libgit2/libgit2/archive/v0.23.0.tar.gz
$ tar xzf v0.23.0.tar.gz
$ cd libgit2-0.23.0/
$ cmake .
$ make
$ sudo make install
Expand Down Expand Up @@ -140,9 +140,9 @@ Install libgit2 (see we define the installation prefix):

.. code-block:: sh

$ wget https://github.com/libgit2/libgit2/archive/v0.22.0.tar.gz
$ tar xzf v0.22.0.tar.gz
$ cd libgit2-0.22.0/
$ wget https://github.com/libgit2/libgit2/archive/v0.23.0.tar.gz
$ tar xzf v0.23.0.tar.gz
$ cd libgit2-0.23.0/
$ cmake . -DCMAKE_INSTALL_PREFIX=$LIBGIT2
$ make
$ make install
Expand Down Expand Up @@ -178,7 +178,7 @@ everytime. Verify yourself if curious:

.. code-block:: sh

$ readelf --dynamic lib/python2.7/site-packages/pygit2-0.21.3-py2.7-linux-x86_64.egg/_pygit2.so | grep PATH
$ readelf --dynamic lib/python2.7/site-packages/pygit2-0.23.0-py2.7-linux-x86_64.egg/_pygit2.so | grep PATH
0x000000000000001d (RUNPATH) Library runpath: [/tmp/venv/lib]


Expand All @@ -195,9 +195,9 @@ from a bash shell:
.. code-block:: sh

$ export LIBGIT2=C:/Dev/libgit2
$ wget https://github.com/libgit2/libgit2/archive/v0.22.0.tar.gz
$ tar xzf v0.22.0.tar.gz
$ cd libgit2-0.22.0/
$ wget https://github.com/libgit2/libgit2/archive/v0.23.0.tar.gz
$ tar xzf v0.23.0.tar.gz
$ cd libgit2-0.23.0/
$ cmake . -DSTDCALL=OFF -DCMAKE_INSTALL_PREFIX=$LIBGIT2 -G "Visual Studio 9 2008"
$ cmake --build . --config release --target install
$ ctest -v
Expand Down
8 changes: 4 additions & 4 deletions pygit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def clone_repository(

opts.bare = bare
if credentials:
opts.remote_callbacks.credentials = _credentials_cb
opts.remote_callbacks.payload = d_handle
opts.fetch_opts.callbacks.credentials = _credentials_cb
opts.fetch_opts.callbacks.payload = d_handle

if certificate:
opts.remote_callbacks.certificate_check = _certificate_cb
opts.remote_callbacks.payload = d_handle
opts.fetch_opts.callbacks.certificate_check = _certificate_cb
opts.fetch_opts.callbacks.payload = d_handle

err = C.git_clone(crepo, to_bytes(url), to_bytes(path), opts)

Expand Down
43 changes: 31 additions & 12 deletions pygit2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ def __del__(self):
def _get(self, key):
assert_string(key, "key")

cstr = ffi.new('char **')
err = C.git_config_get_string(cstr, self._config, to_bytes(key))
entry = ffi.new('git_config_entry **')
err = C.git_config_get_entry(entry, self._config, to_bytes(key))

return err, cstr
return err, ConfigEntry._from_c(entry[0])

def _get_string(self, key):
err, cstr = self._get(key)
def _get_entry(self, key):
err, entry = self._get(key)

if err == C.GIT_ENOTFOUND:
raise KeyError(key)

check_error(err)
return cstr[0]
return entry

def __contains__(self, key):
err, cstr = self._get(key)
Expand All @@ -126,9 +126,9 @@ def __contains__(self, key):
return True

def __getitem__(self, key):
val = self._get_string(key)
entry = self._get_entry(key)

return ffi.string(val).decode('utf-8')
return ffi.string(entry.value).decode('utf-8')

def __setitem__(self, key, value):
assert_string(key, "key")
Expand Down Expand Up @@ -192,9 +192,10 @@ def get_bool(self, key):
Truthy values are: 'true', 1, 'on' or 'yes'. Falsy values are: 'false',
0, 'off' and 'no'
"""
val = self._get_string(key)

entry = self._get_entry(key)
res = ffi.new('int *')
err = C.git_config_parse_bool(res, val)
err = C.git_config_parse_bool(res, entry.value)
check_error(err)

return res[0] != 0
Expand All @@ -206,9 +207,10 @@ def get_int(self, key):
A value can have a suffix 'k', 'm' or 'g' which stand for 'kilo',
'mega' and 'giga' respectively.
"""
val = self._get_string(key)

entry = self._get_entry(key)
res = ffi.new('int64_t *')
err = C.git_config_parse_int64(res, val)
err = C.git_config_parse_int64(res, entry.value)
check_error(err)

return res[0]
Expand Down Expand Up @@ -283,3 +285,20 @@ def get_xdg_config():
"""Return a <Config> object representing the global configuration file.
"""
return Config._from_found_config(C.git_config_find_xdg)

class ConfigEntry(object):
"""An entry in a configuation object
"""

@classmethod
def _from_c(cls, ptr):
entry = cls.__new__(cls)
entry._entry = ptr
return entry

def __del__(self):
C.git_config_entry_free(self._entry)

@property
def value(self):
return self._entry.value
Loading