Get rid of allocfmt() by carlosmn · Pull Request #449 · libgit2/pygit2 · GitHub
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
13 changes: 7 additions & 6 deletions src/diff.c
15 changes: 6 additions & 9 deletions src/note.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,18 @@ Note_remove(Note *self, PyObject* args)
{
char *ref = "refs/notes/commits";
int err = GIT_ERROR;
git_oid annotated_id;
Signature *py_author, *py_committer;
Oid *id;

if (!PyArg_ParseTuple(args, "O!O!|s",
&SignatureType, &py_author,
&SignatureType, &py_committer,
&ref))
return NULL;

err = git_oid_fromstr(&annotated_id, self->annotated_id);
if (err < 0)
return Error_set(err);

id = (Oid *) self->annotated_id;
err = git_note_remove(self->repo->repo, ref, py_author->signature,
py_committer->signature, &annotated_id);
py_committer->signature, &id->oid);
if (err < 0)
return Error_set(err);

Expand Down Expand Up @@ -90,7 +87,7 @@ static void
Note_dealloc(Note *self)
{
Py_CLEAR(self->repo);
free(self->annotated_id);
Py_CLEAR(self->annotated_id);
git_note_free(self->note);
PyObject_Del(self);
}
Expand All @@ -102,7 +99,7 @@ PyMethodDef Note_methods[] = {
};

PyMemberDef Note_members[] = {
MEMBER(Note, annotated_id, T_STRING, "id of the annotated object."),
MEMBER(Note, annotated_id, T_OBJECT, "id of the annotated object."),
{NULL}
};

Expand Down Expand Up @@ -229,7 +226,7 @@ wrap_note(Repository* repo, git_oid* annotated_id, const char* ref)

py_note->repo = repo;
Py_INCREF(repo);
py_note->annotated_id = git_oid_allocfmt(annotated_id);
py_note->annotated_id = git_oid_to_python(annotated_id);

return (PyObject*) py_note;
}
Expand Down
8 changes: 4 additions & 4 deletions src/reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ RefLogIter_iternext(RefLogIter *self)
entry = git_reflog_entry_byindex(self->reflog, self->i);
py_entry = PyObject_New(RefLogEntry, &RefLogEntryType);

py_entry->oid_old = git_oid_allocfmt(git_reflog_entry_id_old(entry));
py_entry->oid_new = git_oid_allocfmt(git_reflog_entry_id_new(entry));
py_entry->oid_old = git_oid_to_python(git_reflog_entry_id_old(entry));
py_entry->oid_new = git_oid_to_python(git_reflog_entry_id_new(entry));
py_entry->message = strdup(git_reflog_entry_message(entry));
err = git_signature_dup(&py_entry->signature,
git_reflog_entry_committer(entry));
Expand Down Expand Up @@ -431,8 +431,8 @@ RefLogEntry_init(RefLogEntry *self, PyObject *args, PyObject *kwds)
static void
RefLogEntry_dealloc(RefLogEntry *self)
{
free(self->oid_old);
free(self->oid_new);
Py_CLEAR(self->oid_old);
Py_CLEAR(self->oid_new);
free(self->message);
git_signature_free(self->signature);
PyObject_Del(self);
Expand Down
10 changes: 5 additions & 5 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef struct {
PyObject_HEAD
Repository *repo;
git_note *note;
char* annotated_id;
PyObject* annotated_id;
} Note;

typedef struct {
Expand All @@ -105,8 +105,8 @@ typedef struct {
PyObject* hunks;
const char * old_file_path;
const char * new_file_path;
char* old_id;
char* new_id;
PyObject* old_id;
PyObject* new_id;
char status;
unsigned similarity;
unsigned additions;
Expand Down Expand Up @@ -164,8 +164,8 @@ typedef Reference Branch;
typedef struct {
PyObject_HEAD
git_signature *signature;
char *oid_old;
char *oid_new;
PyObject *oid_old;
PyObject *oid_new;
char *message;
} RefLogEntry;

Expand Down
4 changes: 2 additions & 2 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ def test_diff_ids(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
patch = commit_a.tree.diff_to_tree(commit_b.tree)[0]
self.assertEqual(patch.old_id,
self.assertEqual(patch.old_id.hex,
'7f129fd57e31e935c6d60a0c794efe4e6927664b')
self.assertEqual(patch.new_id,
self.assertEqual(patch.new_id.hex,
'af431f20fc541ed6d5afede3e2dc7160f6f01f16')

def test_hunk_content(self):
Expand Down
2 changes: 1 addition & 1 deletion test/test_note.py