mirror of
https://github.com/NixOS/nix
synced 2025-06-28 17:51:15 +02:00
Fix the parsing of the sourcehut refs file
Since a26be9f3b8
, the same parser is used
to parse the result of sourcehut’s `HEAD` endpoint (coming from [git
dumb protocol]) and the output of `git ls-remote`. However, they are very
slightly different (the former doesn’t specify the current reference
since it’s implied to be `HEAD`).
Unify both, and make the parser a bit more robust and understandable (by
making it more typed and adding tests for it)
[git dumb protocol]: https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols#_the_dumb_protocol
This commit is contained in:
parent
470e27ce80
commit
e68676e6c8
7 changed files with 116 additions and 63 deletions
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
|
||||
// Parses the HEAD ref as reported by `git ls-remote --symref`
|
||||
//
|
||||
// Returns the head branch name as reported by `git ls-remote --symref`, e.g., if
|
||||
// ls-remote returns the output below, "main" is returned based on the ref line.
|
||||
//
|
||||
// ref: refs/heads/main HEAD
|
||||
//
|
||||
// If the repository is in 'detached head' state (HEAD is pointing to a rev
|
||||
// instead of a branch), parseListReferenceForRev("HEAD") may be used instead.
|
||||
std::optional<std::string> parseListReferenceHeadRef(std::string_view line);
|
||||
|
||||
// Parses a reference line from `git ls-remote --symref`, e.g.,
|
||||
// parseListReferenceForRev("refs/heads/master", line) will return 6926...
|
||||
// given the line below.
|
||||
//
|
||||
// 6926beab444c33fb57b21819b6642d032016bb1e refs/heads/master
|
||||
std::optional<std::string> parseListReferenceForRev(std::string_view rev, std::string_view line);
|
Loading…
Add table
Add a link
Reference in a new issue