Skip to content

Commit 2d4c1f5

Browse files
committed
Remove Repository.parse_diff, remove repo check from Diff.merge
1 parent 711e9eb commit 2d4c1f5

File tree

4 files changed

+18
-70
lines changed

4 files changed

+18
-70
lines changed

src/diff.c

-3
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,6 @@ Diff_merge(Diff *self, PyObject *args)
831831
if (!PyArg_ParseTuple(args, "O!", &DiffType, &py_diff))
832832
return NULL;
833833

834-
if (py_diff->repo->repo != self->repo->repo)
835-
return Error_set(GIT_ERROR);
836-
837834
err = git_diff_merge(self->diff, py_diff->diff);
838835
if (err < 0)
839836
return Error_set(err);

src/repository.c

-27
Original file line numberDiff line numberDiff line change
@@ -1465,32 +1465,6 @@ Repository_create_reference_symbolic(Repository *self, PyObject *args,
14651465
return wrap_reference(c_reference, self);
14661466
}
14671467

1468-
PyDoc_STRVAR(Repository_parse_diff__doc__,
1469-
"parse_diff(git_diff: str) -> Diff\n"
1470-
"\n"
1471-
"Parses a git unified diff into a diff object applied to the repository");
1472-
1473-
PyObject *
1474-
Repository_parse_diff(PyObject *self, PyObject *args)
1475-
{
1476-
/* A wrapper around
1477-
* git_diff_from_buffer
1478-
*/
1479-
git_diff *diff;
1480-
const char *content = NULL;
1481-
Py_ssize_t content_len;
1482-
int err;
1483-
1484-
if (!PyArg_ParseTuple(args, "s#", &content, &content_len))
1485-
return NULL;
1486-
1487-
err = git_diff_from_buffer(&diff, content, content_len);
1488-
if (err < 0)
1489-
return Error_set(err);
1490-
1491-
return wrap_diff(diff, (Repository *) self);
1492-
}
1493-
14941468
PyDoc_STRVAR(Repository_status__doc__,
14951469
"status() -> {str: int}\n"
14961470
"\n"
@@ -1839,7 +1813,6 @@ PyMethodDef Repository_methods[] = {
18391813
METHOD(Repository, init_submodules, METH_VARARGS | METH_KEYWORDS),
18401814
METHOD(Repository, lookup_reference, METH_O),
18411815
METHOD(Repository, revparse_single, METH_O),
1842-
METHOD(Repository, parse_diff, METH_VARARGS),
18431816
METHOD(Repository, status, METH_NOARGS),
18441817
METHOD(Repository, status_file, METH_O),
18451818
METHOD(Repository, notes, METH_VARARGS),

test/test_diff.py

+18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from __future__ import absolute_import
3131
from __future__ import unicode_literals
32+
import textwrap
3233
import unittest
3334
import pygit2
3435
from pygit2 import GIT_DIFF_INCLUDE_UNMODIFIED
@@ -354,6 +355,23 @@ def test_diff_parse(self):
354355
deltas = list(diff.deltas)
355356
self.assertEqual(2, len(deltas))
356357

358+
def test_parse_diff_null(self):
359+
with self.assertRaises(Exception):
360+
self.repo.parse_diff(None)
361+
362+
def test_parse_diff_bad(self):
363+
diff = textwrap.dedent(
364+
"""
365+
diff --git a/file1 b/file1
366+
old mode 0644
367+
new mode 0644
368+
@@ -1,1 +1,1 @@
369+
-Hi!
370+
""")
371+
with self.assertRaises(Exception):
372+
self.repo.parse_diff(diff)
373+
374+
357375
class BinaryDiffTest(utils.BinaryFileRepoTestCase):
358376
def test_binary_diff(self):
359377
repo = self.repo

test/test_repository.py

-40
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import binascii
3636
import unittest
3737
import tempfile
38-
import textwrap
3938
import os
4039
from os.path import join, realpath
4140
import sys
@@ -197,45 +196,6 @@ def test_hash(self):
197196
written_sha1 = self.repo.create_blob(data)
198197
self.assertEqual(hashed_sha1, written_sha1)
199198

200-
def test_parse_diff_null(self):
201-
with self.assertRaises(Exception):
202-
self.repo.parse_diff(None)
203-
204-
def test_parse_diff_bad(self):
205-
diff = textwrap.dedent(
206-
"""
207-
diff --git a/file1 b/file1
208-
old mode 0644
209-
new mode 0644
210-
@@ -1,1 +1,1 @@
211-
-Hi!
212-
""")
213-
with self.assertRaises(Exception):
214-
self.repo.parse_diff(diff)
215-
216-
def test_parse_diff(self):
217-
diff = textwrap.dedent(
218-
"""
219-
diff --git a/file1 b/file1
220-
old mode 0644
221-
new mode 0644
222-
@@ -1,1 +1,1 @@
223-
-Hello, world!
224-
+Hola, Mundo!
225-
"""
226-
)
227-
git_diff = self.repo.parse_diff(diff)
228-
stats = git_diff.stats
229-
deltas = list(git_diff.deltas)
230-
231-
self.assertEqual(1, stats.deletions)
232-
self.assertEqual(1, stats.insertions)
233-
self.assertEqual(1, stats.files_changed)
234-
235-
self.assertEqual(1, len(deltas))
236-
self.assertEqual("file1", deltas[0].old_file.path)
237-
self.assertEqual("file1", deltas[0].new_file.path)
238-
239199
def test_hashfile(self):
240200
data = "bazbarfoo"
241201
handle, tempfile_path = tempfile.mkstemp()

0 commit comments

Comments
 (0)