From c06e10e67e746099b8d454212acc56391199eb31 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Tue, 29 May 2012 17:41:07 +0100 Subject: [PATCH] Support for diff merge operation added --- src/pygit2/diff.c | 30 +++++++++++++++-- .../2a/d1d3456c5c4a1c9e40aeeddb9cd20b409623c8 | Bin 0 -> 99 bytes .../2c/dae28389c059815e951d0bb9eed6533f61a46b | 2 ++ .../39/a3001fcc2b9541fdcf4be2d662618a5d213f47 | 1 + .../6a/270c81bc80b59591e0d2e3abd7d03450c0c395 | Bin 0 -> 29 bytes .../72/abb8755b2cc6c4e40fd9f50f54384d973a2f22 | Bin 0 -> 99 bytes .../97/d615e1bc273c40c94a726814e7b93fdb5a1b36 | Bin 0 -> 29 bytes test/data/testrepo.git/refs/heads/master | 2 +- test/test_diff.py | 31 ++++++++++++++++++ 9 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 test/data/testrepo.git/objects/2a/d1d3456c5c4a1c9e40aeeddb9cd20b409623c8 create mode 100644 test/data/testrepo.git/objects/2c/dae28389c059815e951d0bb9eed6533f61a46b create mode 100644 test/data/testrepo.git/objects/39/a3001fcc2b9541fdcf4be2d662618a5d213f47 create mode 100644 test/data/testrepo.git/objects/6a/270c81bc80b59591e0d2e3abd7d03450c0c395 create mode 100644 test/data/testrepo.git/objects/72/abb8755b2cc6c4e40fd9f50f54384d973a2f22 create mode 100644 test/data/testrepo.git/objects/97/d615e1bc273c40c94a726814e7b93fdb5a1b36 diff --git a/src/pygit2/diff.c b/src/pygit2/diff.c index a1d5e2e..da6c514 100644 --- a/src/pygit2/diff.c +++ b/src/pygit2/diff.c @@ -53,8 +53,8 @@ static int diff_hunk_cb( hunks = PyDict_GetItemString(cb_data, "hunks"); if(hunks == NULL) { - hunks = PyList_New(0); - PyDict_SetItemString(cb_data, "hunks", hunks); + hunks = PyList_New(0); + PyDict_SetItemString(cb_data, "hunks", hunks); } hunk = (Hunk*) PyType_GenericNew(&HunkType, NULL, NULL); @@ -237,6 +237,24 @@ PyTypeObject HunkType = { 0, /* tp_new */ }; +PyObject * +Diff_merge(Diff *self, PyObject *args) +{ + Diff *py_diff; + int err; + + if (!PyArg_ParseTuple(args, "O!", &DiffType, &py_diff)) + return NULL; + if (py_diff->repo->repo != self->repo->repo) + return Error_set(GIT_ERROR); + + err = git_diff_merge(self->diff, py_diff->diff); + if (err < 0) + return Error_set(err); + + Py_RETURN_NONE; +} + static void Diff_dealloc(Diff *self) { @@ -251,6 +269,12 @@ PyGetSetDef Diff_getseters[] = { {NULL} }; +static PyMethodDef Diff_methods[] = { + {"merge", (PyCFunction)Diff_merge, METH_VARARGS, + "Merge one diff into another."}, + {NULL, NULL, 0, NULL} +}; + PyTypeObject DiffType = { PyVarObject_HEAD_INIT(NULL, 0) "pygit2.Diff", /* tp_name */ @@ -279,7 +303,7 @@ PyTypeObject DiffType = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + Diff_methods, /* tp_methods */ 0, /* tp_members */ Diff_getseters, /* tp_getset */ 0, /* tp_base */ diff --git a/test/data/testrepo.git/objects/2a/d1d3456c5c4a1c9e40aeeddb9cd20b409623c8 b/test/data/testrepo.git/objects/2a/d1d3456c5c4a1c9e40aeeddb9cd20b409623c8 new file mode 100644 index 0000000000000000000000000000000000000000..1c1c60d6d1f77a74ec73a0fb89a3d5228ebfd21e GIT binary patch literal 99 zcmV-p0G$7L0V^p=O;xZkV=y!@Ff%bxNMy)T=V{#2uyyLh2bUhNzJ9?Z;K1RjP{|~Q z>DNRb?oqdKIO$cCA@Y2u{p~1eGZOD +䋡 scjquV:/ ; %ĈH#V~4]K ^7=={7|B~{\rMQHz])ۧST+ ?.mEZ}s] \ No newline at end of file diff --git a/test/data/testrepo.git/objects/39/a3001fcc2b9541fdcf4be2d662618a5d213f47 b/test/data/testrepo.git/objects/39/a3001fcc2b9541fdcf4be2d662618a5d213f47 new file mode 100644 index 0000000..aa5e5ff --- /dev/null +++ b/test/data/testrepo.git/objects/39/a3001fcc2b9541fdcf4be2d662618a5d213f47 @@ -0,0 +1 @@ +xO9N1$+:Gz|=B|G{m-s/ RJ6w"p*蝵Q4'CK^b&/NUG1B=4)1)늝g11qBn\AWx9d}[!&FgEϸg` 9p>)cj.4+]̝OW)M]= \ No newline at end of file diff --git a/test/data/testrepo.git/objects/6a/270c81bc80b59591e0d2e3abd7d03450c0c395 b/test/data/testrepo.git/objects/6a/270c81bc80b59591e0d2e3abd7d03450c0c395 new file mode 100644 index 0000000000000000000000000000000000000000..7db6959f002db94ba1c5aed4e6afc421b3f33aa8 GIT binary patch literal 29 lcmb