github: use libgit2 transport for ref resolution#15470
github: use libgit2 transport for ref resolution#15470domenkozar wants to merge 1 commit intoNixOS:masterfrom
Conversation
42e0d86 to
2fa2411
Compare
Upstreamed as NixOS/nix#15470. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0fd340e to
3492d21
Compare
3492d21 to
d61b4f2
Compare
|
I don't see any issues with this, I could be missing something. |
|
@xokdvium let's merge this one as well? Looking forward not to hammer github http api |
1ae0dfa to
c4e92a7
Compare
c4e92a7 to
6919a7d
Compare
Use libgit2's high level remote API (git_remote_create_detached, git_remote_connect, git_remote_ls) instead of manually downloading and parsing the smart HTTP pkt-line format. This delegates protocol handling to libgit2 while keeping auth via custom HTTP headers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6919a7d to
250b1ce
Compare
| git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; | ||
| callbacks.payload = const_cast<void *>(static_cast<const void *>(&token)); | ||
| callbacks.credentials = | ||
| [](git_credential ** out, const char *, const char *, unsigned int allowed_types, void * payload) -> int { |
There was a problem hiding this comment.
nit:
| [](git_credential ** out, const char *, const char *, unsigned int allowed_types, void * payload) -> int { | |
| [](git_credential ** out, const char *, const char *, unsigned int allowedTypes, void * payload) -> int { |
| auto * tok = static_cast<const std::string *>(payload); | ||
| if (tok->empty()) | ||
| return GIT_PASSTHROUGH; | ||
| if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT) |
There was a problem hiding this comment.
| if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT) | |
| if (allowedTypes & GIT_CREDENTIAL_USERPASS_PLAINTEXT) |
| if (git_remote_connect(remote.get(), GIT_DIRECTION_FETCH, &callbacks, nullptr, nullptr)) | ||
| throw GitError("connecting to remote '%s'", url); | ||
|
|
||
| const git_remote_head ** refs; |
There was a problem hiding this comment.
nit:
| const git_remote_head ** refs; | |
| const gitRemoteHead ** refs; |
| store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root)); | ||
| auto owner = getOwner(input); | ||
| auto repo = getRepo(input); | ||
| auto url = fmt("https://%s/%s/%s.git", host, owner, repo); |
There was a problem hiding this comment.
Constructing the URL this way is fine, since github doesn't allow anything that would need percent encoding in the repo/owner name. Just a note to readers.
|
|
||
| Headers headers = makeHeadersWithAuthTokens(settings, host, input); | ||
|
|
||
| auto downloadResult = downloadFile(store, settings, url, "source", headers); |
There was a problem hiding this comment.
One thing to note here is that we lose the caching that downloadFile does. Any way to recover it? Is this a concern at all?
There was a problem hiding this comment.
This is probably the more concerning question I have. Everything else is mostly noise
Resolve branch/tag names to commit SHAs via the git HTTP protocol (/info/refs endpoint) instead of the GitHub REST API. This is the same approach already used by SourceHut and avoids API rate limits.