aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2021-01-14 19:50:31 -0800
committerGitHub <noreply@github.com>2021-01-14 19:50:31 -0800
commita5971344505757e4868e14d112362326610b98e5 (patch)
tree2bfe83c1ff297b4e5335ac90a11e0e9adf72e823 /toolsrc/include
parent2f6537fa2b8928d2329e827f862692112793435d (diff)
downloadvcpkg-a5971344505757e4868e14d112362326610b98e5.tar.gz
vcpkg-a5971344505757e4868e14d112362326610b98e5.zip
[vcpkg registries] Add git registries (#15054)
* [vcpkg registries] Add git registries support * Add git registries support to the registries module of vcpkg. * add e2e tests for git registries * fix vcpkg.cmake for registries * fix CRs, remove a thing * better error messages * Billy CRs * fix Robert's CR comment * I learned about `-c` today * format * fix baseline.json * failing to find baseline is technically not a bug
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/vcpkg/base/files.h57
-rw-r--r--toolsrc/include/vcpkg/base/system.h2
-rw-r--r--toolsrc/include/vcpkg/vcpkgpaths.h10
3 files changed, 69 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg/base/files.h b/toolsrc/include/vcpkg/base/files.h
index e1628eaf0..dd1b3a6c6 100644
--- a/toolsrc/include/vcpkg/base/files.h
+++ b/toolsrc/include/vcpkg/base/files.h
@@ -125,6 +125,12 @@ namespace fs
#endif
+ inline bool operator==(SystemHandle lhs, SystemHandle rhs) noexcept
+ {
+ return lhs.system_handle == rhs.system_handle;
+ }
+ inline bool operator!=(SystemHandle lhs, SystemHandle rhs) noexcept { return !(lhs == rhs); }
+
inline bool is_symlink(file_status s) noexcept
{
#if defined(_WIN32)
@@ -266,4 +272,55 @@ namespace vcpkg::Files
#if defined(_WIN32)
fs::path win32_fix_path_case(const fs::path& source);
#endif // _WIN32
+
+ struct ExclusiveFileLock
+ {
+ enum class Wait
+ {
+ Yes,
+ No,
+ };
+
+ ExclusiveFileLock() = default;
+ ExclusiveFileLock(ExclusiveFileLock&& other)
+ : fs_(other.fs_), handle_(std::exchange(handle_, fs::SystemHandle{}))
+ {
+ }
+ ExclusiveFileLock& operator=(ExclusiveFileLock&& other)
+ {
+ if (this == &other) return *this;
+
+ clear();
+ fs_ = other.fs_;
+ handle_ = std::exchange(other.handle_, fs::SystemHandle{});
+ return *this;
+ }
+
+ ExclusiveFileLock(Wait wait, Filesystem& fs, const fs::path& path_, std::error_code& ec) : fs_(&fs)
+ {
+ switch (wait)
+ {
+ case Wait::Yes: handle_ = fs_->take_exclusive_file_lock(path_, ec); break;
+ case Wait::No: handle_ = fs_->try_take_exclusive_file_lock(path_, ec); break;
+ }
+ }
+ ~ExclusiveFileLock() { clear(); }
+
+ explicit operator bool() const { return handle_.is_valid(); }
+ bool has_lock() const { return handle_.is_valid(); }
+
+ void clear()
+ {
+ if (fs_ && handle_.is_valid())
+ {
+ std::error_code ignore;
+ fs_->unlock_file_lock(std::exchange(handle_, fs::SystemHandle{}), ignore);
+ }
+ }
+
+ private:
+ fs::SystemHandle handle_;
+ Filesystem* fs_;
+ };
+
}
diff --git a/toolsrc/include/vcpkg/base/system.h b/toolsrc/include/vcpkg/base/system.h
index 8e45f6538..da14fa4bb 100644
--- a/toolsrc/include/vcpkg/base/system.h
+++ b/toolsrc/include/vcpkg/base/system.h
@@ -20,6 +20,8 @@ namespace vcpkg::System
Optional<std::string> get_registry_string(void* base_hkey, StringView subkey, StringView valuename);
+ long get_process_id();
+
enum class CPUArchitecture
{
X86,
diff --git a/toolsrc/include/vcpkg/vcpkgpaths.h b/toolsrc/include/vcpkg/vcpkgpaths.h
index a175d51e2..36447b9f3 100644
--- a/toolsrc/include/vcpkg/vcpkgpaths.h
+++ b/toolsrc/include/vcpkg/vcpkgpaths.h
@@ -124,6 +124,16 @@ namespace vcpkg
ExpectedS<std::map<std::string, std::string, std::less<>>> git_get_local_port_treeish_map() const;
+ // Git manipulation for remote registries
+ // runs `git fetch {uri} {treeish}`, and returns the hash of FETCH_HEAD.
+ // If `treeish` is empty, then just runs `git fetch {uri}`
+ ExpectedS<std::string> git_fetch_from_remote_registry(StringView uri, StringView treeish = {}) const;
+ ExpectedS<std::string> git_show_from_remote_registry(StringView hash,
+ const fs::path& relative_path_to_file) const;
+ ExpectedS<std::string> git_find_object_id_for_remote_registry_path(StringView hash,
+ const fs::path& relative_path_to_file) const;
+ ExpectedS<fs::path> git_checkout_object_from_remote_registry(StringView tree) const;
+
Optional<const Json::Object&> get_manifest() const;
Optional<const fs::path&> get_manifest_path() const;
const Configuration& get_configuration() const;