From c76874c5a1e57b4c3dc8d392f29b679d14a1d305 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 9 Feb 2018 23:57:09 +0300 Subject: Add git_reference class --- libbpkg/manifest.cxx | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'libbpkg/manifest.cxx') diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index a972793..d7cf7cf 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -1770,9 +1770,9 @@ namespace bpkg } case repository_type::git: { - if (!url_.fragment) - throw invalid_argument ("missing branch/tag for git repository"); - + // Verify the URL fragment. + // + git_reference r (url_.fragment); break; } } @@ -1942,6 +1942,37 @@ namespace bpkg canonical_name_ += cp; } + // git_reference + // + git_reference:: + git_reference (const optional& frag) + { + if (frag) + { + const string& s (*frag); + + size_t p (s.find ('@')); + if (p != string::npos) + { + if (p != 0) + branch = string (s, 0, p); + + if (p + 1 != s.size ()) + commit = string (s, p + 1); + } + else if (!s.empty ()) + branch = s; + } + + if (!branch && !commit) + throw invalid_argument ( + "missing branch/tag or commit id for git repository"); + + if (commit && commit->size () != 40) + throw invalid_argument ( + "git repository commit id must be 40 characters long"); + } + // repository_manifest // repository_manifest:: -- cgit v1.1