From eb001f0b9865d038ef904573c45946f7f8298534 Mon Sep 17 00:00:00 2001 From: Arno van Lumig Date: Fri, 25 Jul 2014 08:29:16 +0200 Subject: [PATCH 1/2] Implemented parameters for Diff.find_similar() Diff.find_similar now supports the parameters that are exposed by libgit2's git_diff_find_similar. Parameters supported are rename_threshold, copy_threshold, rename_from_rewrite_threshold, break_rewrite_threshold and rename_limit --- src/diff.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/diff.c b/src/diff.c index 83fcb51..243592b 100644 --- a/src/diff.c +++ b/src/diff.c @@ -438,19 +438,30 @@ Diff_merge(Diff *self, PyObject *args) PyDoc_STRVAR(Diff_find_similar__doc__, - "find_similar([flags])\n" + "find_similar([flags, rename_threshold, copy_threshold, rename_from_rewrite_threshold, break_rewrite_threshold, rename_limit])\n" "\n" "Find renamed files in diff and updates them in-place in the diff itself."); PyObject * -Diff_find_similar(Diff *self, PyObject *args) +Diff_find_similar(Diff *self, PyObject *args, PyObject *kwds) { int err; git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT; - if (!PyArg_ParseTuple(args, "|i", &opts.flags)) + uint16_t rename_threshold, copy_threshold, rename_from_rewrite_threshold, break_rewrite_threshold; + size_t rename_limit; + char *keywords[] = {"flags", "rename_threshold", "copy_threshold", "rename_from_rewrite_threshold", "break_rewrite_threshold", "rename_limit", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iHHHHI", keywords, + &opts.flags, &rename_threshold, ©_threshold, &rename_from_rewrite_threshold, &break_rewrite_threshold, &rename_limit)) return NULL; + opts.rename_threshold = rename_threshold; + opts.copy_threshold = copy_threshold; + opts.rename_from_rewrite_threshold = rename_from_rewrite_threshold; + opts.break_rewrite_threshold = break_rewrite_threshold; + opts.rename_limit = rename_limit; + err = git_diff_find_similar(self->list, &opts); if (err < 0) return Error_set(err); @@ -508,7 +519,7 @@ PyMappingMethods Diff_as_mapping = { static PyMethodDef Diff_methods[] = { METHOD(Diff, merge, METH_VARARGS), - METHOD(Diff, find_similar, METH_VARARGS), + METHOD(Diff, find_similar, METH_VARARGS | METH_KEYWORDS), METHOD(Diff, from_c, METH_STATIC | METH_VARARGS), {NULL} }; From e31f0acf976ced828046d95516ad7b4b1c0cc500 Mon Sep 17 00:00:00 2001 From: Arno van Lumig Date: Fri, 25 Jul 2014 11:40:03 +0200 Subject: [PATCH 2/2] Parsed parameters directly passed into options object --- src/diff.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/diff.c b/src/diff.c index 243592b..0f7bfb3 100644 --- a/src/diff.c +++ b/src/diff.c @@ -448,20 +448,12 @@ Diff_find_similar(Diff *self, PyObject *args, PyObject *kwds) int err; git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT; - uint16_t rename_threshold, copy_threshold, rename_from_rewrite_threshold, break_rewrite_threshold; - size_t rename_limit; char *keywords[] = {"flags", "rename_threshold", "copy_threshold", "rename_from_rewrite_threshold", "break_rewrite_threshold", "rename_limit", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iHHHHI", keywords, - &opts.flags, &rename_threshold, ©_threshold, &rename_from_rewrite_threshold, &break_rewrite_threshold, &rename_limit)) + &opts.flags, &opts.rename_threshold, &opts.copy_threshold, &opts.rename_from_rewrite_threshold, &opts.break_rewrite_threshold, &opts.rename_limit)) return NULL; - opts.rename_threshold = rename_threshold; - opts.copy_threshold = copy_threshold; - opts.rename_from_rewrite_threshold = rename_from_rewrite_threshold; - opts.break_rewrite_threshold = break_rewrite_threshold; - opts.rename_limit = rename_limit; - err = git_diff_find_similar(self->list, &opts); if (err < 0) return Error_set(err);