aboutsummaryrefslogtreecommitdiff
path: root/src/libfetchers/git-utils.cc
blob: b2d6b7893794bb4a147c994da63014487417e081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "git-utils.hh"

#include <regex>

std::optional<std::string> parseListReferenceHeadRef(std::string_view line)
{
    const static std::regex head_ref_regex("^ref: ([^\\s]+)\\t+HEAD$");
    std::match_results<std::string_view::const_iterator> match;
    if (std::regex_match(line.cbegin(), line.cend(), match, head_ref_regex)) {
        return match[1];
    } else {
        return std::nullopt;
    }
}

std::optional<std::string> parseListReferenceForRev(std::string_view rev, std::string_view line)
{
    const static std::regex rev_regex("^([^\\t]+)\\t+(.*)$");
    std::match_results<std::string_view::const_iterator> match;
    if (!std::regex_match(line.cbegin(), line.cend(), match, rev_regex)) {
        return std::nullopt;
    }
    if (rev != match[2].str()) {
        return std::nullopt;
    }
    return match[1];
}