aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-02-13 23:12:23 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-02-15 10:21:24 +0300
commit02458785b93094dfc65b31a4ecf2a8e690143b03 (patch)
tree81522d1b1602d82dbe0ee51915f8f8bb32c3b1bf
parent4ea1f6680b6b740220fc25a2c971560fde4d6392 (diff)
Assume git repo URL fragment of 40 hex digits is a commit id
-rw-r--r--libbpkg/manifest.cxx17
-rw-r--r--tests/repository-location/driver.cxx16
2 files changed, 23 insertions, 10 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index 81a9b8c..1c0650e 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -11,7 +11,7 @@
#include <cstring> // strncmp(), strcmp()
#include <utility> // move()
#include <cstdint> // uint16_t, UINT16_MAX
-#include <algorithm> // find(), replace()
+#include <algorithm> // find(), find_if_not(), replace()
#include <stdexcept> // invalid_argument
#include <libbutl/path.mxx>
@@ -1961,7 +1961,20 @@ namespace bpkg
commit = string (s, p + 1);
}
else if (!s.empty ())
- branch = s;
+ {
+ // 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 (),
+
+ // Resolve the required overload.
+ //
+ static_cast<bool (*)(char)> (xdigit)) == s.end ())
+ commit = s;
+ else
+ branch = s;
+ }
}
if (!branch && !commit)
diff --git a/tests/repository-location/driver.cxx b/tests/repository-location/driver.cxx
index e5a818a..ad3b0dd 100644
--- a/tests/repository-location/driver.cxx
+++ b/tests/repository-location/driver.cxx
@@ -754,16 +754,16 @@ namespace bpkg
// Repository URL fragments.
//
{
- loc ("https://www.example.com/test.git#master", repository_type::git);
- loc ("https://www.example.com/test.git#master@", repository_type::git);
+ string branch ("master");
+ string commit ("0a53e9ddeaddad63ad106860237bbf53411d11a7");
- loc ("https://www.example.com/test.git#"
- "@0a53e9ddeaddad63ad106860237bbf53411d11a7",
- repository_type::git);
+ assert (*git_reference (branch).branch == branch);
+ assert (*git_reference (commit + "@").branch == commit);
+ assert (*git_reference (commit).commit == commit);
+ assert (*git_reference ("@" + commit).commit == commit);
- loc ("https://www.example.com/test.git#"
- "master@0a53e9ddeaddad63ad106860237bbf53411d11a7",
- repository_type::git);
+ git_reference r (branch + "@" + commit);
+ assert (*r.branch == branch && *r.commit == commit);
}
// repository_url