aboutsummaryrefslogtreecommitdiff
path: root/libbpkg/manifest.cxx
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/manifest.cxx
parentcc2efd2c70b1cdd28c375674c62f9d5f131f6908 (diff)
Add git_reference class
Diffstat (limited to 'libbpkg/manifest.cxx')
-rw-r--r--libbpkg/manifest.cxx37
1 files changed, 34 insertions, 3 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::