From 7cf0854121525747b438b7f94bf2d050f61fb615 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Apr 2018 12:35:37 +0200 Subject: Implement git repository handling transition (phase 0) --- libbpkg/manifest.cxx | 59 +++++++++++++++++++++++++--------------------------- libbpkg/manifest.hxx | 23 +++++++++++--------- 2 files changed, 41 insertions(+), 41 deletions(-) (limited to 'libbpkg') diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index 951c6a6..e1dfb52 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -2092,7 +2092,9 @@ namespace bpkg { // Verify the URL fragment. // - git_reference r (url_.fragment); + if (url_.fragment) + git_ref_filter r (*url_.fragment); + break; } } @@ -2286,44 +2288,39 @@ namespace bpkg } } - // git_reference + // git_ref_filter // - git_reference:: - git_reference (const optional& frag) + git_ref_filter:: + git_ref_filter (const string& frag) { - if (frag) + size_t p (frag.find ('@')); + if (p != string::npos) { - const string& s (*frag); - - size_t p (s.find ('@')); - if (p != string::npos) - { - if (p != 0) - branch = string (s, 0, p); + if (p != 0) + name = string (frag, 0, p); - if (p + 1 != s.size ()) - commit = string (s, p + 1); - } - else if (!s.empty ()) - { - // A 40-characters fragment that consists of only hexadecimal digits is - // assumed to be a commit id. - // - if (s.size () == 40 && - find_if_not (s.begin (), s.end (), + if (p + 1 != frag.size ()) + commit = string (frag, p + 1); + } + else if (!frag.empty ()) + { + // A 40-characters fragment that consists of only hexadecimal digits is + // assumed to be a commit id. + // + if (frag.size () == 40 && + find_if_not (frag.begin (), frag.end (), - // Resolve the required overload. - // - static_cast (xdigit)) == s.end ()) - commit = s; - else - branch = s; - } + // Resolve the required overload. + // + static_cast (xdigit)) == frag.end ()) + commit = frag; + else + name = frag; } - if (!branch && !commit) + if (!name && !commit) throw invalid_argument ( - "missing branch/tag or commit id for git repository"); + "missing reference name or commit id for git repository"); if (commit && commit->size () != 40) throw invalid_argument ( diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx index a44ffcc..fdec69e 100644 --- a/libbpkg/manifest.hxx +++ b/libbpkg/manifest.hxx @@ -834,25 +834,28 @@ namespace bpkg return os << l.string (); } - // Branch and/or commit. At least one of them must be present. If both of - // them are present then the commit is expected to belong to the branch - // history. Note that the branch member can also denote a tag. + // Git refname and/or commit. At least one of them must be present. If both + // are present then the commit is expected to belong to the history of the + // specified ref (e.g., tag or branch). Note that the name member can also + // be an abbreviated commit id (full, 40-character commit ids should always + // be stored in the commit member since then may refer to an unadvertised + // commit). // - class LIBBPKG_EXPORT git_reference + class LIBBPKG_EXPORT git_ref_filter { public: - butl::optional branch; + butl::optional name; butl::optional commit; public: - // Parse the [][@] repository URL fragment representation. + // Parse the [][@] repository URL fragment representation. // explicit - git_reference (const butl::optional&); + git_ref_filter (const std::string&); - git_reference (butl::optional b, - butl::optional c) - : branch (std::move (b)), + git_ref_filter (butl::optional n, + butl::optional c) + : name (std::move (n)), commit (std::move (c)) {} }; -- cgit v1.1