Skip to content
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.24 https://github.com/libgit2/libgit2.git
git clone --depth=1 -b maint/v0.25 https://github.com/libgit2/libgit2.git
cd libgit2/

mkdir build && cd build
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ init:
build_script:
- cmd: |
set LIBGIT2=%APPVEYOR_BUILD_FOLDER%\build\libgit2
git clone --depth=1 -b maint/v0.24 https://github.com/libgit2/libgit2.git libgit2
git clone --depth=1 -b maint/v0.25 https://github.com/libgit2/libgit2.git libgit2
mkdir build

cd build
Expand Down
32 changes: 16 additions & 16 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Requirements
============

- Python 2.7, 3.2+ or PyPy 2.6+ (including the development headers)
- Libgit2 v0.23.x
- Libgit2 v0.25.x
- cffi 1.0+
- six
- tox (optional)
Expand Down Expand Up @@ -43,11 +43,11 @@ while the last number |lq| *.micro* |rq| auto-increments independently.

As illustration see this table of compatible releases:

+-----------+-----------------------+----------------------------------------+
|**libgit2**| 0.24.0, 0.24.1 0.24.2 | 0.23.0, 0.23.1, 0.23.2, 0.23.3, 0.23.4 |
+-----------+-----------------------+----------------------------------------+
|**pygit2** | 0.24.0, 0.24.1 0.24.2 | 0.23.0, 0.23.1, 0.23.2, 0.23.3 |
+-----------+-----------------------+----------------------------------------+
+-----------+--------+--------------+--------+
|**libgit2**| 0.25.0 | 0.24.0, 0.24.1 0.24.2 |
+-----------+--------+--------------+--------+
|**pygit2** | 0.25.0 | 0.24.0, 0.24.1 0.24.2 |
+-----------+--------+--------------+--------+

.. warning::

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

.. code-block:: sh

$ wget https://github.com/libgit2/libgit2/archive/v0.24.2.tar.gz
$ tar xzf v0.24.2.tar.gz
$ cd libgit2-0.24.2/
$ wget https://github.com/libgit2/libgit2/archive/v0.25.0.tar.gz
$ tar xzf v0.25.0.tar.gz
$ cd libgit2-0.25.0/
$ cmake .
$ make
$ sudo make install
Expand Down Expand Up @@ -148,9 +148,9 @@ Install libgit2 (see we define the installation prefix):

.. code-block:: sh

$ wget https://github.com/libgit2/libgit2/archive/v0.23.4.tar.gz
$ tar xzf v0.23.4.tar.gz
$ cd libgit2-0.23.4/
$ wget https://github.com/libgit2/libgit2/archive/v0.25.0.tar.gz
$ tar xzf v0.25.0.tar.gz
$ cd libgit2-0.25.0/
$ cmake . -DCMAKE_INSTALL_PREFIX=$LIBGIT2
$ make
$ make install
Expand Down Expand Up @@ -186,7 +186,7 @@ everytime. Verify yourself if curious:

.. code-block:: sh

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


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

$ export LIBGIT2=C:/Dev/libgit2
$ wget https://github.com/libgit2/libgit2/archive/v0.23.4.tar.gz
$ tar xzf v0.23.4.tar.gz
$ cd libgit2-0.23.4/
$ wget https://github.com/libgit2/libgit2/archive/v0.25.0.tar.gz
$ tar xzf v0.25.0.tar.gz
$ cd libgit2-0.25.0/
$ cmake . -DSTDCALL=OFF -DCMAKE_INSTALL_PREFIX=$LIBGIT2 -G "Visual Studio 9 2008"
$ cmake --build . --config release --target install
$ ctest -v
Expand Down
27 changes: 24 additions & 3 deletions pygit2/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,30 @@ struct git_remote_callbacks {

typedef struct git_remote_callbacks git_remote_callbacks;

typedef enum {
GIT_PROXY_NONE,
GIT_PROXY_AUTO,
GIT_PROXY_SPECIFIED,
} git_proxy_t;

typedef struct {
unsigned int version;
git_proxy_t type;
const char *url;
git_cred_acquire_cb credentials;
git_transport_certificate_check_cb certificate_check;
void *payload;
} git_proxy_options;

#define GIT_PROXY_OPTIONS_VERSION ...
int git_proxy_init_options(git_proxy_options *opts, unsigned int version);

typedef struct {
unsigned int version;
unsigned int pb_parallelism;
git_remote_callbacks callbacks;
git_strarray custom_headers;
git_proxy_options proxy_opts;
git_strarray custom_headers;
} git_push_options;

#define GIT_PUSH_OPTIONS_VERSION ...
Expand All @@ -236,7 +255,8 @@ typedef struct {
git_fetch_prune_t prune;
int update_fetchhead;
git_remote_autotag_option_t download_tags;
git_strarray custom_headers;
git_proxy_options proxy_opts;
git_strarray custom_headers;
} git_fetch_options;

#define GIT_FETCH_OPTIONS_VERSION ...
Expand Down Expand Up @@ -738,7 +758,8 @@ typedef struct {
unsigned int rename_threshold;
unsigned int target_limit;
git_diff_similarity_metric *metric;
unsigned int recursion_limit;
unsigned int recursion_limit;
const char *default_driver;
git_merge_file_favor_t file_favor;
unsigned int file_flags;
} git_merge_options;
Expand Down
70 changes: 44 additions & 26 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,38 +862,17 @@ Repository_create_blob_fromdisk(Repository *self, PyObject *args)
}


#define BUFSIZE 4096

PyDoc_STRVAR(Repository_create_blob_fromiobase__doc__,
"create_blob_fromiobase(io.IOBase) -> Oid\n"
"\n"
"Create a new blob from an IOBase object.");


int read_chunk(char *content, size_t max_length, void *payload)
{
PyObject *py_file;
PyObject *py_bytes;
char *bytes;
Py_ssize_t size;

py_file = (PyObject *)payload;
py_bytes = PyObject_CallMethod(py_file, "read", "i", max_length);
if (!py_bytes)
return -1;

size = 0;
if (py_bytes != Py_None) {
bytes = PyBytes_AsString(py_bytes);
size = PyBytes_Size(py_bytes);
memcpy(content, bytes, size);
}

Py_DECREF(py_bytes);
return size;
}

PyObject *
Repository_create_blob_fromiobase(Repository *self, PyObject *py_file)
{
git_writestream *stream;
git_oid oid;
PyObject *py_is_readable;
int is_readable;
Expand All @@ -915,8 +894,47 @@ Repository_create_blob_fromiobase(Repository *self, PyObject *py_file)
return NULL;
}

err = git_blob_create_fromchunks(&oid, self->repo, NULL, &read_chunk,
py_file);
err = git_blob_create_fromstream(&stream, self->repo, NULL);
if (err < 0)
return Error_set(err);

for (;;) {
PyObject *py_bytes;
char *bytes;
Py_ssize_t size;

py_bytes = PyObject_CallMethod(py_file, "read", "i", 4096);
if (!py_bytes)
return NULL;

if (py_bytes == Py_None) {
Py_DECREF(py_bytes);
goto cleanup;
}

if (PyBytes_AsStringAndSize(py_bytes, &bytes, &size)) {
Py_DECREF(py_bytes);
return NULL;
}

if (size == 0) {
Py_DECREF(py_bytes);
break;
}

err = stream->write(stream, bytes, size);
Py_DECREF(py_bytes);
if (err < 0)
goto cleanup;
}

cleanup:
if (err < 0) {
stream->free(stream);
return Error_set(err);
}

err = git_blob_create_fromstream_commit(&oid, stream);
if (err < 0)
return Error_set(err);

Expand Down
4 changes: 2 additions & 2 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include <Python.h>
#include <git2.h>

#if !(LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR == 24)
#error You need a compatible libgit2 version (v0.24.x)
#if !(LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR == 25)
#error You need a compatible libgit2 version (v0.25.x)
#endif

/*
Expand Down