Skip to content
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

Update to libgit2 0.21 #374

Merged
merged 15 commits into from
Jun 21, 2014
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
4 changes: 2 additions & 2 deletions docs/diff.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Attributes:

.. autoattribute:: pygit2.Patch.old_file_path
.. autoattribute:: pygit2.Patch.new_file_path
.. autoattribute:: pygit2.Patch.old_oid
.. autoattribute:: pygit2.Patch.new_oid
.. autoattribute:: pygit2.Patch.old_id
.. autoattribute:: pygit2.Patch.new_id
.. autoattribute:: pygit2.Patch.status
.. autoattribute:: pygit2.Patch.similarity
.. autoattribute:: pygit2.Patch.hunks
Expand Down
8 changes: 4 additions & 4 deletions docs/merge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ merge with the default ones defined in GIT_MERGE_OPTS_INIT libgit2 constant.
Example::

>>> branch_head_hex = '5ebeeebb320790caf276b9fc8b24546d63316533'
>>> branch_oid = self.repo.get(branch_head_hex).id
>>> merge_result = self.repo.merge(branch_oid)
>>> branch_id = self.repo.get(branch_head_hex).id
>>> merge_result = self.repo.merge(branch_id)

The MergeResult object
======================
Expand All @@ -33,5 +33,5 @@ Represents the result of a merge and contains these fields:
- is_uptodate: bool, if there wasn't any merge because the repo was already
up to date
- is_fastforward: bool, whether the merge was fastforward or not
- fastforward_oid: Oid, in the case it was a fastforward, this is the
forwarded Oid.
- fastforward_id: Oid, in the case it was a fastforward, this is the
forwarded id.
24 changes: 12 additions & 12 deletions docs/objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ type.
Object lookup
=================

In the previous chapter we learnt about Object IDs. With an oid we can ask the
In the previous chapter we learnt about Object IDs. With an Oid we can ask the
repository to get the associated object. To do that the ``Repository`` class
implementes a subset of the mapping interface.

.. automethod:: pygit2.Repository.get

Return the Git object for the given *oid*, returns the *default* value if
there's no object in the repository with that oid. The oid can be an Oid
Return the Git object for the given *id*, returns the *default* value if
there's no object in the repository with that id. The id can be an Oid
object, or an hexadecimal string.

Example::
Expand All @@ -32,16 +32,16 @@ implementes a subset of the mapping interface.
>>> obj
<_pygit2.Commit object at 0x7ff27a6b60f0>

.. method:: Repository.__getitem__(oid)
.. method:: Repository.__getitem__(id)

Return the Git object for the given oid, raise ``KeyError`` if there's no
object in the repository with that oid. The oid can be an Oid object, or
Return the Git object for the given id, raise ``KeyError`` if there's no
object in the repository with that id. The id can be an Oid object, or
an hexadecimal string.

.. method:: Repository.__contains__(oid)
.. method:: Repository.__contains__(id)

Returns True if there is an object in the Repository with that oid, False
if there is not. The oid can be an Oid object, or an hexadecimal string.
Returns True if there is an object in the Repository with that id, False
if there is not. The id can be an Oid object, or an hexadecimal string.


The Object base type
Expand Down Expand Up @@ -125,15 +125,15 @@ them to the Git object database:

Example:

>>> oid = repo.create_blob('foo bar') # Creates blob from bytes string
>>> blob = repo[oid]
>>> id = repo.create_blob('foo bar') # Creates blob from bytes string
>>> blob = repo[id]
>>> blob.data
'foo bar'

.. automethod:: pygit2.Repository.create_blob_fromworkdir
.. automethod:: pygit2.Repository.create_blob_fromdisk

There are also some functions to calculate the oid for a byte string without
There are also some functions to calculate the id for a byte string without
creating the blob object:

.. autofunction:: pygit2.hash
Expand Down
6 changes: 3 additions & 3 deletions docs/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Example::
>>> for entry in head.log():
... print(entry.message)

.. autoattribute:: pygit2.RefLogEntry.oid_new
.. autoattribute:: pygit2.RefLogEntry.oid_old
.. autoattribute:: pygit2.RefLogEntry.id_new
.. autoattribute:: pygit2.RefLogEntry.id_old
.. autoattribute:: pygit2.RefLogEntry.message
.. autoattribute:: pygit2.RefLogEntry.committer

Expand All @@ -109,6 +109,6 @@ The Note type
--------------------

.. autoattribute:: pygit2.Note.annotated_id
.. autoattribute:: pygit2.Note.oid
.. autoattribute:: pygit2.Note.id
.. autoattribute:: pygit2.Note.message
.. automethod:: pygit2.Note.remove
6 changes: 3 additions & 3 deletions docs/working-copy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Index read::

>>> index = repo.index
>>> index.read()
>>> oid = index['path/to/file'].id # from path to object id
>>> blob = repo[oid] # from object id to object
>>> id = index['path/to/file'].id # from path to object id
>>> blob = repo[id] # from object id to object

Iterate over all entries of the index::

Expand Down Expand Up @@ -51,7 +51,7 @@ The Index type
The IndexEntry type
--------------------

.. autoattribute:: pygit2.IndexEntry.oid
.. autoattribute:: pygit2.IndexEntry.id
.. autoattribute:: pygit2.IndexEntry.hex
.. autoattribute:: pygit2.IndexEntry.path
.. autoattribute:: pygit2.IndexEntry.mode
Expand Down
2 changes: 1 addition & 1 deletion pygit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def clone_into(repo, remote, branch=None):
and calling this function.
"""

err = C.git_clone_into(repo._repo, remote._remote, ffi.NULL, to_str(branch))
err = C.git_clone_into(repo._repo, remote._remote, ffi.NULL, to_str(branch), ffi.NULL)

if remote._stored_exception:
raise remote._stored_exception
Expand Down
22 changes: 19 additions & 3 deletions pygit2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ def add_file(self, path, level=0, force=0):
err = C.git_config_add_file_ondisk(self._config, to_str(path), level, force)
check_error(err)

def snapshot(self):
"""Create a snapshot from this Config object

This means that looking up multiple values will use the same version
of the configuration files
"""

ccfg = ffi.new('git_config **')
err = C.git_config_snapshot(cfg, self._config)
check_error(err)

return Config.from_c(self._repo, ccfg[0])

#
# Methods to parse a string according to the git-config rules
#
Expand All @@ -248,10 +261,13 @@ def parse_int(text):

@staticmethod
def _from_found_config(fn):
buf = ffi.new('char []', C.GIT_PATH_MAX)
err = fn(buf, C.GIT_PATH_MAX)
buf = ffi.new('git_buf *', (ffi.NULL, 0))
err = fn(buf)
check_error(err, True)
return Config(ffi.string(buf).decode())
cpath = ffi.string(buf.ptr).decode()
C.git_buf_free(buf)

return Config(cpath)

@staticmethod
def get_system_config():
Expand Down
78 changes: 55 additions & 23 deletions pygit2/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ typedef ... git_push;
typedef ... git_cred;
typedef ... git_diff_file;
typedef ... git_tree;
typedef ... git_signature;

#define GIT_OID_RAWSZ ...
#define GIT_PATH_MAX ...
Expand All @@ -13,6 +14,12 @@ typedef struct git_oid {
unsigned char id[20];
} git_oid;

typedef struct {
char *ptr;
size_t asize, size;
} git_buf;
void git_buf_free(git_buf *buffer);

typedef struct git_strarray {
char **strings;
size_t count;
Expand Down Expand Up @@ -79,15 +86,26 @@ typedef enum {
...
} git_credtype_t;

typedef struct git_remote_callbacks {
typedef int (*git_transport_message_cb)(const char *str, int len, void *data);
typedef int (*git_cred_acquire_cb)(
git_cred **cred,
const char *url,
const char *username_from_url,
unsigned int allowed_types,
void *payload);
typedef int (*git_transfer_progress_cb)(const git_transfer_progress *stats, void *payload);

struct git_remote_callbacks {
unsigned int version;
int (*progress)(const char *str, int len, void *data);
git_transport_message_cb sideband_progress;
int (*completion)(git_remote_completion_type type, void *data);
int (*credentials)(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *data);
int (*transfer_progress)(const git_transfer_progress *stats, void *data);
git_cred_acquire_cb credentials;
git_transfer_progress_cb transfer_progress;
int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
void *payload;
} git_remote_callbacks ;
};

typedef struct git_remote_callbacks git_remote_callbacks;

int git_remote_list(git_strarray *out, git_repository *repo);
int git_remote_load(git_remote **out, git_repository *repo, const char *name);
Expand All @@ -98,16 +116,16 @@ int git_remote_create(
const char *url);

const char * git_remote_name(const git_remote *remote);
typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, void *payload);
int git_remote_rename(git_remote *remote,
const char *new_name,
git_remote_rename_problem_cb callback,
void *payload);

int git_remote_rename(
git_strarray *problems,
git_remote *remote,
const char *new_name);
const char * git_remote_url(const git_remote *remote);
int git_remote_set_url(git_remote *remote, const char* url);
const char * git_remote_pushurl(const git_remote *remote);
int git_remote_set_pushurl(git_remote *remote, const char* url);
int git_remote_fetch(git_remote *remote);
int git_remote_fetch(git_remote *remote, const git_signature *signature, const char *reflog_message);
const git_transfer_progress * git_remote_stats(git_remote *remote);
int git_remote_add_push(git_remote *remote, const char *refspec);
int git_remote_add_fetch(git_remote *remote, const char *refspec);
Expand All @@ -133,7 +151,10 @@ int git_push_status_foreach(
int (*cb)(const char *ref, const char *msg, void *data),
void *data);

int git_push_update_tips(git_push *push);
int git_push_update_tips(
git_push *push,
const git_signature *signature,
const char *reflog_message);
void git_push_free(git_push *push);

const char * git_refspec_src(const git_refspec *refspec);
Expand All @@ -145,8 +166,8 @@ git_direction git_refspec_direction(const git_refspec *spec);
int git_refspec_src_matches(const git_refspec *refspec, const char *refname);
int git_refspec_dst_matches(const git_refspec *refspec, const char *refname);

int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name);
int git_refspec_rtransform(char *out, size_t outlen, const git_refspec *spec, const char *name);
int git_refspec_transform(git_buf *buf, const git_refspec *spec, const char *name);
int git_refspec_rtransform(git_buf *buf, const git_refspec *spec, const char *name);

int git_cred_userpass_plaintext_new(
git_cred **out,
Expand Down Expand Up @@ -179,7 +200,7 @@ typedef void (*git_checkout_progress_cb)(
size_t total_steps,
void *payload);

typedef struct git_checkout_opts {
typedef struct git_checkout_options {
unsigned int version;

unsigned int checkout_strategy;
Expand All @@ -202,10 +223,17 @@ typedef struct git_checkout_opts {

const char *target_directory;

const char *ancestor_label;
const char *our_label;
const char *their_label;
} git_checkout_opts;
} git_checkout_options;

typedef enum {
GIT_CLONE_LOCAL_AUTO,
GIT_CLONE_LOCAL,
GIT_CLONE_NO_LOCAL,
GIT_CLONE_LOCAL_NO_LINKS,
} git_clone_local_t;

/*
* git_clone
Expand All @@ -214,13 +242,15 @@ typedef struct git_checkout_opts {
typedef struct git_clone_options {
unsigned int version;

git_checkout_opts checkout_opts;
git_checkout_options checkout_opts;
git_remote_callbacks remote_callbacks;

int bare;
int ignore_cert_errors;
git_clone_local_t local;
const char *remote_name;
const char* checkout_branch;
git_signature *signature;
} git_clone_options;

int git_clone(git_repository **out,
Expand All @@ -231,8 +261,9 @@ int git_clone(git_repository **out,
int git_clone_into(
git_repository *repo,
git_remote *remote,
const git_checkout_opts *co_opts,
const char *branch);
const git_checkout_options *co_opts,
const char *branch,
const git_signature *signature);

/*
* git_config
Expand All @@ -257,6 +288,7 @@ typedef struct {
} git_config_entry;

int git_repository_config(git_config **out, git_repository *repo);
int git_repository_config_snapshot(git_config **out, git_repository *repo);
void git_config_free(git_config *cfg);

int git_config_get_string(const char **out, const git_config *cfg, const char *name);
Expand Down Expand Up @@ -290,11 +322,11 @@ int git_config_set_multivar(
const char *value);

int git_config_new(git_config **out);
int git_config_snapshot(git_config **out, git_config *config);
int git_config_open_ondisk(git_config **out, const char *path);
int git_config_find_system(char *out, size_t length);
int git_config_find_global(char *out, size_t length);
int git_config_find_xdg(char *out, size_t length);

int git_config_find_system(git_buf *out);
int git_config_find_global(git_buf *out);
int git_config_find_xdg(git_buf *out);

/*
* git_repository_init
Expand Down
Loading