From f619db022734dff6b988c514e3a292a5c7babaf0 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 22 Feb 2018 15:02:15 +0300 Subject: Invent repository_state() function --- bpkg/manifest-utility.cxx | 18 ++++++++++++++++++ bpkg/manifest-utility.hxx | 13 +++++++++++++ bpkg/pkg-checkout.cxx | 4 +--- bpkg/rep-fetch.cxx | 11 ++++------- 4 files changed, 36 insertions(+), 10 deletions(-) (limited to 'bpkg') 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 +#include + #include 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); + + // 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 -#include - #include #include @@ -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 (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 -#include #include #include // operator<<(ostream, process_path) #include @@ -15,6 +14,7 @@ #include #include #include +#include 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)) { -- cgit v1.1