diff options
author | Théophane Hufschmitt <theophane.hufschmitt@tweag.io> | 2022-05-04 14:32:21 +0200 |
---|---|---|
committer | Théophane Hufschmitt <theophane.hufschmitt@tweag.io> | 2022-05-04 14:38:59 +0200 |
commit | e68676e6c859815f40079b6340399d82cc1913b6 (patch) | |
tree | 830a0e12317ce9e467556c79d9926e7c693bad5b /src/libutil/git.hh | |
parent | 470e27ce8008ba952225b9f9f7f61a9627376f33 (diff) |
Fix the parsing of the sourcehut refs file
Since a26be9f3b89be2ee90c6358250b9889b37f95cf8, 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
Diffstat (limited to 'src/libutil/git.hh')
-rw-r--r-- | src/libutil/git.hh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libutil/git.hh b/src/libutil/git.hh new file mode 100644 index 000000000..cb13ef0e5 --- /dev/null +++ b/src/libutil/git.hh @@ -0,0 +1,40 @@ +#pragma once + +#include <string> +#include <string_view> +#include <optional> + +namespace nix { + +namespace git { + +// A line from the output of `git ls-remote --symref`. +// +// These can be of two kinds: +// +// - Symbolic references of the form +// +// ref: {target} {reference} +// +// where {target} is itself a reference and {reference} is optional +// +// - Object references of the form +// +// {target} {reference} +// +// where {target} is a commit id and {reference} is mandatory +struct LsRemoteRefLine { + enum struct Kind { + Symbolic, + Object + }; + Kind kind; + std::string target; + std::optional<std::string> reference; +}; + +std::optional<LsRemoteRefLine> parseLsRemoteLine(std::string_view line); + +} + +} |