@@ -54,7 +54,7 @@ wrap_diff(git_diff *diff, Repository *repo)
54
54
55
55
py_diff = PyObject_New (Diff , & DiffType );
56
56
if (py_diff ) {
57
- Py_INCREF (repo );
57
+ Py_XINCREF (repo );
58
58
py_diff -> repo = repo ;
59
59
py_diff -> diff = diff ;
60
60
}
@@ -901,6 +901,32 @@ Diff_stats__get__(Diff *self)
901
901
return wrap_diff_stats (self -> diff );
902
902
}
903
903
904
+ PyDoc_STRVAR (Diff_parse_diff__doc__ ,
905
+ "parse_diff(git_diff: str) -> Diff\n"
906
+ "\n"
907
+ "Parses a git unified diff into a diff object without a repository" );
908
+
909
+ static PyObject *
910
+ Diff_parse_diff (PyObject * self , PyObject * args )
911
+ {
912
+ /* A wrapper around
913
+ * git_diff_from_buffer
914
+ */
915
+ git_diff * diff ;
916
+ const char * content = NULL ;
917
+ Py_ssize_t content_len ;
918
+ int err ;
919
+
920
+ if (!PyArg_ParseTuple (args , "s#" , & content , & content_len ))
921
+ return NULL ;
922
+
923
+ err = git_diff_from_buffer (& diff , content , content_len );
924
+ if (err < 0 )
925
+ return Error_set (err );
926
+
927
+ return wrap_diff (diff , NULL );
928
+ }
929
+
904
930
static void
905
931
Diff_dealloc (Diff * self )
906
932
{
@@ -926,6 +952,8 @@ static PyMethodDef Diff_methods[] = {
926
952
METHOD (Diff , merge , METH_VARARGS ),
927
953
METHOD (Diff , find_similar , METH_VARARGS | METH_KEYWORDS ),
928
954
METHOD (Diff , from_c , METH_STATIC | METH_VARARGS ),
955
+ {"parse_diff" , (PyCFunction ) Diff_parse_diff ,
956
+ METH_VARARGS | METH_STATIC , Diff_parse_diff__doc__ },
929
957
{NULL }
930
958
};
931
959
0 commit comments