aboutsummaryrefslogtreecommitdiff
path: root/bpkg
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-02-22 15:02:15 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-02-22 17:27:41 +0300
commitf619db022734dff6b988c514e3a292a5c7babaf0 (patch)
tree73ab481eeb0ed524168e00f89d55dc2d3a91b9bd /bpkg
parent6ec24eebcb42c0db205f9fff3f2716b84c6fcabf (diff)
Invent repository_state() function
Diffstat (limited to 'bpkg')
-rw-r--r--bpkg/manifest-utility.cxx18
-rw-r--r--bpkg/manifest-utility.hxx13
-rw-r--r--bpkg/pkg-checkout.cxx4
-rw-r--r--bpkg/rep-fetch.cxx11
4 files changed, 36 insertions, 10 deletions
diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx
index 27e2553..ed50298 100644
--- a/bpkg/manifest-utility.cxx
+++ b/bpkg/manifest-utility.cxx
@@ -4,6 +4,8 @@
#include <bpkg/manifest-utility.hxx>
+#include <libbutl/sha256.mxx>
+
#include <bpkg/diagnostics.hxx>
using namespace std;
@@ -124,4 +126,20 @@ namespace bpkg
{
fail << "failed to guess repository type for '" << s << "': " << e << endf;
}
+
+ dir_path
+ repository_state (const repository_location& l)
+ {
+ switch (l.type ())
+ {
+ case repository_type::bpkg: return dir_path (); // No state.
+ case repository_type::git:
+ {
+ return dir_path (sha256 (l.canonical_name ()).abbreviated_string (16));
+ }
+ }
+
+ assert (false); // Can't be here.
+ return dir_path ();
+ }
}
diff --git a/bpkg/manifest-utility.hxx b/bpkg/manifest-utility.hxx
index f4dadb4..f672ba7 100644
--- a/bpkg/manifest-utility.hxx
+++ b/bpkg/manifest-utility.hxx
@@ -40,6 +40,19 @@ namespace bpkg
//
repository_location
parse_location (const char*, optional<repository_type>);
+
+ // Return the repository state subdirectory for the specified location as it
+ // appears under .bpkg/repositories/ in the bpkg configuration. Return empty
+ // directory if the repository type doesn't have any state.
+ //
+ // Note that the semantics used to produce this name is repository type-
+ // specific and can base on the repository canonical name or (potentially a
+ // subset of) the location URL. In particular, a state directory could be
+ // shared by multiple repository locations of the same type (@@ TODO: if we
+ // ever do this, then we will need to complicate the removal logic).
+ //
+ dir_path
+ repository_state (const repository_location&);
}
#endif // BPKG_MANIFEST_UTILITY_HXX
diff --git a/bpkg/pkg-checkout.cxx b/bpkg/pkg-checkout.cxx
index 7377b8e..f068b54 100644
--- a/bpkg/pkg-checkout.cxx
+++ b/bpkg/pkg-checkout.cxx
@@ -4,8 +4,6 @@
#include <bpkg/pkg-checkout.hxx>
-#include <libbutl/sha256.mxx>
-
#include <libbpkg/manifest.hxx>
#include <bpkg/package.hxx>
@@ -118,7 +116,7 @@ namespace bpkg
//
dir_path sd (c / repos_dir);
- sd /= dir_path (sha256 (rl.canonical_name ()).abbreviated_string (16));
+ sd /= repository_state (rl);
sd /= dir_path (pl->fragment);
sd /= path_cast<dir_path> (pl->location);
diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx
index fc59ed9..3956c5a 100644
--- a/bpkg/rep-fetch.cxx
+++ b/bpkg/rep-fetch.cxx
@@ -4,7 +4,6 @@
#include <bpkg/rep-fetch.hxx>
-#include <libbutl/sha256.mxx>
#include <libbutl/process.mxx>
#include <libbutl/process-io.mxx> // operator<<(ostream, process_path)
#include <libbutl/manifest-parser.mxx>
@@ -15,6 +14,7 @@
#include <bpkg/package-odb.hxx>
#include <bpkg/database.hxx>
#include <bpkg/diagnostics.hxx>
+#include <bpkg/manifest-utility.hxx>
using namespace std;
using namespace butl;
@@ -152,12 +152,9 @@ namespace bpkg
// Clone or fetch the repository.
//
- // If changing the repository directory naming scheme, then don't forget
- // to also update pkg_checkout().
- //
- dir_path h (sha256 (rl.canonical_name ()).abbreviated_string (16));
+ dir_path sd (repository_state (rl));
- auto_rmdir rm (temp_dir / h);
+ auto_rmdir rm (temp_dir / sd);
dir_path& td (rm.path);
if (exists (td))
@@ -170,7 +167,7 @@ namespace bpkg
bool fetch (false);
if (conf != nullptr)
{
- rd = *conf / repos_dir / h;
+ rd = *conf / repos_dir / sd;
if (exists (rd))
{