@@ -85,17 +85,28 @@ PyObject *
8585discover_repository (PyObject * self , PyObject * args )
8686{
8787 git_buf repo_path = {NULL };
88- const char * path ;
89- PyObject * py_repo_path ;
88+ const char * path = NULL ;
89+ PyBytesObject * py_path = NULL ;
9090 int across_fs = 0 ;
91+ PyBytesObject * py_ceiling_dirs = NULL ;
9192 const char * ceiling_dirs = NULL ;
93+ PyObject * py_repo_path = NULL ;
9294 int err ;
9395
94- if (!PyArg_ParseTuple (args , "s|Is " , & path , & across_fs , & ceiling_dirs ))
96+ if (!PyArg_ParseTuple (args , "O&|IO& " , PyUnicode_FSConverter , & py_path , & across_fs , PyUnicode_FSConverter , & py_ceiling_dirs ))
9597 return NULL ;
9698
99+ if (py_path != NULL )
100+ path = PyBytes_AS_STRING (py_path );
101+ if (py_ceiling_dirs != NULL )
102+ ceiling_dirs = PyBytes_AS_STRING (py_ceiling_dirs );
103+
97104 memset (& repo_path , 0 , sizeof (git_buf ));
98105 err = git_repository_discover (& repo_path , path , across_fs , ceiling_dirs );
106+
107+ Py_XDECREF (py_path );
108+ Py_XDECREF (py_ceiling_dirs );
109+
99110 if (err == GIT_ENOTFOUND )
100111 Py_RETURN_NONE ;
101112 if (err < 0 )
@@ -116,13 +127,18 @@ PyObject *
116127hashfile (PyObject * self , PyObject * args )
117128{
118129 git_oid oid ;
119- const char * path ;
130+ PyBytesObject * py_path = NULL ;
131+ const char * path = NULL ;
120132 int err ;
121133
122- if (!PyArg_ParseTuple (args , "s " , & path ))
134+ if (!PyArg_ParseTuple (args , "O& " , PyUnicode_FSConverter , & py_path ))
123135 return NULL ;
124136
137+ if (py_path != NULL )
138+ path = PyBytes_AS_STRING (py_path );
139+
125140 err = git_odb_hashfile (& oid , path , GIT_OBJ_BLOB );
141+ Py_XDECREF (py_path );
126142 if (err < 0 )
127143 return Error_set (err );
128144
@@ -161,14 +177,18 @@ PyDoc_STRVAR(init_file_backend__doc__,
161177PyObject *
162178init_file_backend (PyObject * self , PyObject * args )
163179{
180+ PyBytesObject * py_path = NULL ;
164181 const char * path = NULL ;
165182 int err = GIT_OK ;
166183 git_repository * repository = NULL ;
167- if (!PyArg_ParseTuple (args , "s " , & path )) {
184+ if (!PyArg_ParseTuple (args , "O& " , PyUnicode_FSConverter , & py_path )) {
168185 return NULL ;
169186 }
187+ if (py_path != NULL )
188+ path = PyBytes_AS_STRING (py_path );
170189
171190 err = git_repository_open (& repository , path );
191+ Py_XDECREF (py_path );
172192 if (err < 0 ) {
173193 Error_set_str (err , path );
174194 goto cleanup ;
0 commit comments