MCPcopy Create free account
hub / github.com/libgit2/pygit2 / discover_repository

Function discover_repository

src/pygit2.c:101–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99 "Look for a git repository and return its path. If not found returns None.");
100
101PyObject *
102discover_repository(PyObject *self, PyObject *args)
103{
104 git_buf repo_path = {NULL};
105 const char *path = NULL;
106 PyBytesObject *py_path = NULL;
107 int across_fs = 0;
108 PyBytesObject *py_ceiling_dirs = NULL;
109 const char *ceiling_dirs = NULL;
110 PyObject *py_repo_path = NULL;
111 int err;
112 PyObject *result = NULL;
113
114 if (!PyArg_ParseTuple(args, "O&|IO&", PyUnicode_FSConverter, &py_path, &across_fs,
115 PyUnicode_FSConverter, &py_ceiling_dirs))
116 return NULL;
117
118 if (py_path != NULL)
119 path = PyBytes_AS_STRING(py_path);
120 if (py_ceiling_dirs != NULL)
121 ceiling_dirs = PyBytes_AS_STRING(py_ceiling_dirs);
122
123 memset(&repo_path, 0, sizeof(git_buf));
124 err = git_repository_discover(&repo_path, path, across_fs, ceiling_dirs);
125
126 if (err == GIT_OK) {
127 py_repo_path = PyUnicode_DecodeFSDefault(repo_path.ptr);
128 git_buf_dispose(&repo_path);
129 result = py_repo_path;
130 } else if (err == GIT_ENOTFOUND) {
131 result = Py_None;
132 } else {
133 result = Error_set_str(err, path);
134 }
135
136 Py_XDECREF(py_ceiling_dirs);
137 Py_XDECREF(py_path);
138
139 return result;
140};
141
142PyDoc_STRVAR(hashfile__doc__,
143 "hashfile(path: str) -> Oid\n"

Callers 3

test_discover_repoFunction · 0.90

Calls 1

Error_set_strFunction · 0.85

Tested by 3

test_discover_repoFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…