Get rid of Reference.append_log()
We do not want this as it is riddled with race conditions.
This commit is contained in:
parent
ae495444a6
commit
f35f58ca45
@ -378,72 +378,6 @@ Reference_log(Reference *self)
|
|||||||
return (PyObject*)iter;
|
return (PyObject*)iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(Reference_log_append__doc__,
|
|
||||||
"log_append(oid, committer, message[, encoding])\n"
|
|
||||||
"\n"
|
|
||||||
"Append a reflog entry to the reference. If the oid is None then keep\n"
|
|
||||||
"the current reference's oid. The message parameter may be None.");
|
|
||||||
|
|
||||||
PyObject *
|
|
||||||
Reference_log_append(Reference *self, PyObject *args)
|
|
||||||
{
|
|
||||||
git_signature *committer;
|
|
||||||
const char *message = NULL;
|
|
||||||
git_reflog *reflog;
|
|
||||||
git_oid oid;
|
|
||||||
const git_oid *ref_oid;
|
|
||||||
int err;
|
|
||||||
PyObject *py_oid = NULL;
|
|
||||||
Signature *py_committer;
|
|
||||||
PyObject *py_message = NULL;
|
|
||||||
char *encoding = NULL;
|
|
||||||
git_repository *repo;
|
|
||||||
|
|
||||||
CHECK_REFERENCE(self);
|
|
||||||
|
|
||||||
/* Input parameters */
|
|
||||||
if (!PyArg_ParseTuple(args, "OO!O|s", &py_oid,
|
|
||||||
&SignatureType, &py_committer,
|
|
||||||
&py_message, &encoding))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (py_oid == Py_None)
|
|
||||||
ref_oid = git_reference_target(self->reference);
|
|
||||||
else {
|
|
||||||
err = py_oid_to_git_oid_expand(self->repo->repo, py_oid, &oid);
|
|
||||||
if (err < 0)
|
|
||||||
return NULL;
|
|
||||||
ref_oid = &oid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (py_message != Py_None) {
|
|
||||||
message = py_str_to_c_str(py_message, encoding);
|
|
||||||
if (message == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Go */
|
|
||||||
repo = git_reference_owner(self->reference);
|
|
||||||
err = git_reflog_read(&reflog, repo, git_reference_name(self->reference));
|
|
||||||
if (err < 0) {
|
|
||||||
free((void *)message);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
committer = (git_signature *)py_committer->signature;
|
|
||||||
err = git_reflog_append(reflog, ref_oid, committer, message);
|
|
||||||
if (!err)
|
|
||||||
err = git_reflog_write(reflog);
|
|
||||||
|
|
||||||
git_reflog_free(reflog);
|
|
||||||
free((void *)message);
|
|
||||||
|
|
||||||
if (err < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Reference_get_object__doc__,
|
PyDoc_STRVAR(Reference_get_object__doc__,
|
||||||
"get_object() -> object\n"
|
"get_object() -> object\n"
|
||||||
"\n"
|
"\n"
|
||||||
@ -557,7 +491,6 @@ PyMethodDef Reference_methods[] = {
|
|||||||
METHOD(Reference, rename, METH_O),
|
METHOD(Reference, rename, METH_O),
|
||||||
METHOD(Reference, resolve, METH_NOARGS),
|
METHOD(Reference, resolve, METH_NOARGS),
|
||||||
METHOD(Reference, log, METH_NOARGS),
|
METHOD(Reference, log, METH_NOARGS),
|
||||||
METHOD(Reference, log_append, METH_VARARGS),
|
|
||||||
METHOD(Reference, get_object, METH_NOARGS),
|
METHOD(Reference, get_object, METH_NOARGS),
|
||||||
METHOD(Reference, set_target, METH_VARARGS | METH_KEYWORDS),
|
METHOD(Reference, set_target, METH_VARARGS | METH_KEYWORDS),
|
||||||
{NULL}
|
{NULL}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
# -*- coding: UTF-8 -*-
|
|
||||||
#
|
|
||||||
# Copyright 2010-2014 The pygit2 contributors
|
|
||||||
#
|
|
||||||
# This file is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License, version 2,
|
|
||||||
# as published by the Free Software Foundation.
|
|
||||||
#
|
|
||||||
# In addition to the permissions in the GNU General Public License,
|
|
||||||
# the authors give you unlimited permission to link the compiled
|
|
||||||
# version of this file into combinations with other programs,
|
|
||||||
# and to distribute those combinations without any restriction
|
|
||||||
# coming from the use of this file. (The General Public License
|
|
||||||
# restrictions do apply in other respects; for example, they cover
|
|
||||||
# modification of the file, and distribution when not linked into
|
|
||||||
# a combined executable.)
|
|
||||||
#
|
|
||||||
# This file is distributed in the hope that it will be useful, but
|
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
# General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
"""Tests for reference log."""
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from pygit2 import Signature
|
|
||||||
from . import utils
|
|
||||||
|
|
||||||
|
|
||||||
class ReflogTest(utils.RepoTestCase):
|
|
||||||
|
|
||||||
def test_log_append(self):
|
|
||||||
repo = self.repo
|
|
||||||
master = repo.lookup_reference("refs/heads/master")
|
|
||||||
signature = Signature('xtao', 'xutao@douban.com')
|
|
||||||
master.log_append(None, signature, 'reflog')
|
|
||||||
self.assertTrue('reflog' in [entry.message for entry in master.log()])
|
|
Loading…
x
Reference in New Issue
Block a user