Read the "origin" remote URL for the repo at root_path. malloc'd or NULL. * libgit2 is initialized once at process start by cbm_alloc_init() (which also * binds its allocator to mimalloc) — do NOT git_libgit2_init()/shutdown() here: * a per-request shutdown could drop the global refcount and tear down that * allocator binding mid-process. */
| 306 | * a per-request shutdown could drop the global refcount and tear down that |
| 307 | * allocator binding mid-process. */ |
| 308 | static char *git_origin_remote_url(const char *root_path) { |
| 309 | #if defined(HAVE_LIBGIT2) |
| 310 | git_repository *repo = NULL; |
| 311 | char *out = NULL; |
| 312 | if (git_repository_open(&repo, root_path) == 0) { |
| 313 | git_remote *rem = NULL; |
| 314 | if (git_remote_lookup(&rem, repo, "origin") == 0) { |
| 315 | const char *u = git_remote_url(rem); |
| 316 | if (u) |
| 317 | out = strdup(u); |
| 318 | git_remote_free(rem); |
| 319 | } |
| 320 | git_repository_free(repo); |
| 321 | } |
| 322 | return out; |
| 323 | #else |
| 324 | (void)root_path; |
| 325 | return NULL; |
| 326 | #endif |
| 327 | } |
| 328 | |
| 329 | /* GET /api/repo-info?project=NAME → { root_path, branch, remote_url, web_base, |
| 330 | * blob_base }. blob_base is "<web_base>/blob/<branch>" ready for the frontend to |