Support for diff merge operation added

This commit is contained in:
Petr Hosek
2012-05-29 17:41:07 +01:00
parent 0b82cf0146
commit c06e10e67e
9 changed files with 62 additions and 4 deletions

View File

@@ -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 */

View File

@@ -0,0 +1,2 @@
x<01>OIj1<10>Y<EFBFBD><59><EFBFBD>A<EFBFBD>֑ <20>}<7D>!д<><1E>̂<EFBFBD>
~~<7E>I^<5E>[<15>PE<50><7<01><>E:3<>RMu>D

View File

@@ -0,0 +1 @@
x<01>O9N1$<24>+:G<>z|<7C>=B<><42>|<7C>G{m-s<><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/ <20>R<1D>J<EFBFBD><4A>6<06><>w"p*<2A>蝵Q<E89DB5>4'CK^<5E><>b<EFBFBD><62>&/NU<>G<><47>1<EFBFBD>B=<3D><><EFBFBD>4)<29><><EFBFBD>1)늝g<EB8A9D>1<>1qBn\<5C><1F><1D><>AWx9d}<7D><><EFBFBD><1E>[<5B><>!<21><><EFBFBD>&<26><>F<EFBFBD><46><EFBFBD>g<EFBFBD>E<><19><>ϸ<EFBFBD><CFB8><EFBFBD>g` 9p<39><70>>)<1E><>c<EFBFBD>j<EFBFBD>.4<EFBFBD>+<01><><EFBFBD><EFBFBD>]<5D>̝O<CC9D><4F><EFBFBD>W)<29><01>M]=

View File

@@ -1 +1 @@
5fe808e8953c12735680c257f56600cb0de44b10
2cdae28389c059815e951d0bb9eed6533f61a46b

View File

@@ -39,6 +39,7 @@ __author__ = 'Nico.Geyso@FU-Berlin.de (Nico von Geyso)'
COMMIT_SHA1_1 = '5fe808e8953c12735680c257f56600cb0de44b10'
COMMIT_SHA1_2 = 'c2792cfa289ae6321ecf2cd5806c2194b0fd070c'
COMMIT_SHA1_3 = '2cdae28389c059815e951d0bb9eed6533f61a46b'
PATCH = b"""diff --git a/a b/a
index 7f129fd..af431f2 100644
--- a/a
@@ -85,6 +86,36 @@ class DiffTest(utils.BareRepoTestCase):
self.assertEqual(hunk.old_data, b'a contents 2\n')
self.assertEqual(hunk.new_data, b'a contents\n')
def test_diff_merge(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
commit_c = self.repo[COMMIT_SHA1_3]
diff_b = commit_a.tree.diff(commit_b.tree)
self.assertIsNotNone(diff_b)
diff_c = commit_b.tree.diff(commit_c.tree)
self.assertIsNotNone(diff_c)
self.assertNotIn(('b','b', 3), diff_b.changes['files'])
self.assertIn(('b','b', 3), diff_c.changes['files'])
diff_b.merge(diff_c)
self.assertIn(('b','b', 3), diff_b.changes['files'])
hunk = diff_b.changes['hunks'][1]
self.assertEqual(hunk.old_start, 1)
self.assertEqual(hunk.old_lines, 0)
self.assertEqual(hunk.new_start, 1)
self.assertEqual(hunk.new_lines, 0)
self.assertEqual(hunk.old_file, 'b')
self.assertEqual(hunk.new_file, 'b')
self.assertEqual(hunk.old_data, b'b contents\n')
self.assertEqual(hunk.new_data, b'b contents 2\n')
def test_diff_patch(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]