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. */
| 329 | * a per-request shutdown could drop the global refcount and tear down that |
| 330 | * allocator binding mid-process. */ |
| 331 | static char *git_origin_remote_url(const char *root_path) { |
| 332 | #if defined(HAVE_LIBGIT2) |
| 333 | git_repository *repo = NULL; |
| 334 | char *out = NULL; |
| 335 | if (git_repository_open(&repo, root_path) == 0) { |
| 336 | git_remote *rem = NULL; |
| 337 | if (git_remote_lookup(&rem, repo, "origin") == 0) { |
| 338 | const char *u = git_remote_url(rem); |
| 339 | if (u) |
| 340 | out = strdup(u); |
| 341 | git_remote_free(rem); |
| 342 | } |
| 343 | git_repository_free(repo); |
| 344 | } |
| 345 | return out; |
| 346 | #else |
| 347 | (void)root_path; |
| 348 | return NULL; |
| 349 | #endif |
| 350 | } |
| 351 | |
| 352 | /* GET /api/repo-info?project=NAME → { root_path, branch, remote_url, web_base, |
| 353 | * blob_base }. blob_base is "<web_base>/blob/<branch>" ready for the frontend to |