aboutsummaryrefslogtreecommitdiff
path: root/libbpkg
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-04-18 12:35:37 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2018-04-19 12:12:52 +0300
commit7cf0854121525747b438b7f94bf2d050f61fb615 (patch)
treebb68ea236c590f71247bf9652991657e25db2524 /libbpkg
parentf8bee7e57187ae9bd55a95bcac4fa07e41ff4dfb (diff)
Implement git repository handling transition (phase 0)
Diffstat (limited to 'libbpkg')
-rw-r--r--libbpkg/manifest.cxx59
-rw-r--r--libbpkg/manifest.hxx23
2 files changed, 41 insertions, 41 deletions
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<string>& 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<bool (*)(char)> (xdigit)) == s.end ())
- commit = s;
- else
- branch = s;
- }
+ // Resolve the required overload.
+ //
+ static_cast<bool (*)(char)> (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<std::string> branch;
+ butl::optional<std::string> name;
butl::optional<std::string> commit;
public:
- // Parse the [<branch>][@<commit>] repository URL fragment representation.
+ // Parse the [<name>][@<commit>] repository URL fragment representation.
//
explicit
- git_reference (const butl::optional<std::string>&);
+ git_ref_filter (const std::string&);
- git_reference (butl::optional<std::string> b,
- butl::optional<std::string> c)
- : branch (std::move (b)),
+ git_ref_filter (butl::optional<std::string> n,
+ butl::optional<std::string> c)
+ : name (std::move (n)),
commit (std::move (c)) {}
};