aboutsummaryrefslogtreecommitdiff
path: root/libbpkg
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-02-09 23:57:09 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-02-12 17:23:38 +0300
commitc76874c5a1e57b4c3dc8d392f29b679d14a1d305 (patch)
treeac5226264355d73c74a1dc2e374b5369f81da02f /libbpkg
parentcc2efd2c70b1cdd28c375674c62f9d5f131f6908 (diff)
Add git_reference class
Diffstat (limited to 'libbpkg')
-rw-r--r--libbpkg/manifest.cxx37
-rw-r--r--libbpkg/manifest.hxx50
2 files changed, 71 insertions, 16 deletions
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<string>& 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::
diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx
index 8c20e76..9d19b2c 100644
--- a/libbpkg/manifest.hxx
+++ b/libbpkg/manifest.hxx
@@ -510,22 +510,24 @@ namespace bpkg
// the URL matches the repository type. Throw std::invalid_argument if the
// URL object is a relative local path.
//
- // @@ Note that the repository location string representation may differ
- // from the original URL in the presence of the trailing slash. This
- // may cause problems with some WEB servers that are sensitive to the
- // trailing slash presence/absence. For example:
+ // Note that the repository location string representation may differ from
+ // the original URL in the presence of the trailing slash. This may cause
+ // problems with some WEB servers that are sensitive to the trailing slash
+ // presence/absence. For example:
//
- // $ git clone http://git.sv.gnu.org/r/config.git
- // warning: redirecting to http://git.savannah.gnu.org/r/config.git/
+ // $ git clone http://git.sv.gnu.org/r/config.git
+ // warning: redirecting to http://git.savannah.gnu.org/r/config.git/
//
- // Also note that we disregard the slash presence/absence on multiple
- // levels:
+ // Also note that we disregard the slash presence/absence on multiple
+ // levels:
//
- // - reduce absent path to an empty one in
- // repository_url_traits::translate_scheme() (so a.com/ becomes a.com)
- // - use path::*string() rather than path::*representation() functions
- // in repository_url_traits::translate_*() functions
- // - may append slash in repository_location ctor
+ // - reduce absent path to an empty one in
+ // repository_url_traits::translate_scheme() (so a.com/ becomes a.com)
+ //
+ // - use path::*string() rather than path::*representation() functions
+ // in repository_url_traits::translate_*() functions
+ //
+ // - may append slash in repository_location ctor
//
explicit
repository_location (repository_url, repository_type);
@@ -685,6 +687,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.
+ //
+ class LIBBPKG_EXPORT git_reference
+ {
+ public:
+ butl::optional<std::string> branch;
+ butl::optional<std::string> commit;
+
+ public:
+ // Parse the [<branch>][@<commit>] repository URL fragment representation.
+ //
+ explicit
+ git_reference (const butl::optional<std::string>&);
+
+ git_reference (butl::optional<std::string> b,
+ butl::optional<std::string> c)
+ : branch (std::move (b)),
+ commit (std::move (c)) {}
+ };
+
enum class repository_role
{
base,