diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix/src/open | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix/src/open')
-rw-r--r-- | vendor/gix/src/open/options.rs | 6 | ||||
-rw-r--r-- | vendor/gix/src/open/repository.rs | 44 |
2 files changed, 42 insertions, 8 deletions
diff --git a/vendor/gix/src/open/options.rs b/vendor/gix/src/open/options.rs index b098d55c1..930fb414c 100644 --- a/vendor/gix/src/open/options.rs +++ b/vendor/gix/src/open/options.rs @@ -149,6 +149,12 @@ impl Options { } } +impl Options { + pub(crate) fn current_dir_or_empty(&self) -> &std::path::Path { + self.current_dir.as_deref().unwrap_or(std::path::Path::new("")) + } +} + impl gix_sec::trust::DefaultForLevel for Options { fn default_for_level(level: gix_sec::Trust) -> Self { match level { diff --git a/vendor/gix/src/open/repository.rs b/vendor/gix/src/open/repository.rs index e89fdc430..fde647a4e 100644 --- a/vendor/gix/src/open/repository.rs +++ b/vendor/gix/src/open/repository.rs @@ -2,6 +2,7 @@ use std::{borrow::Cow, path::PathBuf}; use gix_features::threading::OwnShared; +use gix_macros::momo; use super::{Error, Options}; use crate::{ @@ -50,7 +51,17 @@ impl ThreadSafeRepository { /// `options` for fine-grained control. /// /// Note that you should use [`crate::discover()`] if security should be adjusted by ownership. + /// + /// ### Differences to `git2::Repository::open_ext()` + /// + /// Whereas `open_ext()` is the jack-of-all-trades that can do anything depending on its options, `gix` will always differentiate + /// between discovering git repositories by searching, and opening a well-known repository by work tree or `.git` repository. + /// + /// Note that opening a repository for implementing custom hooks is also handle specifically in + /// [`open_with_environment_overrides()`][Self::open_with_environment_overrides()]. + #[momo] pub fn open_opts(path: impl Into<PathBuf>, mut options: Options) -> Result<Self, Error> { + let _span = gix_trace::coarse!("ThreadSafeRepository::open()"); let (path, kind) = { let path = path.into(); let looks_like_git_dir = @@ -96,13 +107,16 @@ impl ThreadSafeRepository { /// Note that this will read various `GIT_*` environment variables to check for overrides, and is probably most useful when implementing /// custom hooks. // TODO: tests, with hooks, GIT_QUARANTINE for ref-log and transaction control (needs gix-sec support to remove write access in gix-ref) - // TODO: The following vars should end up as overrides of the respective configuration values (see gix-config). + // TODO: The following vars should end up as overrides of the respective configuration values (see git-config). // GIT_PROXY_SSL_CERT, GIT_PROXY_SSL_KEY, GIT_PROXY_SSL_CERT_PASSWORD_PROTECTED. // GIT_PROXY_SSL_CAINFO, GIT_SSL_CIPHER_LIST, GIT_HTTP_MAX_REQUESTS, GIT_CURL_FTP_NO_EPSV, + #[doc(alias = "open_from_env", alias = "git2")] + #[momo] pub fn open_with_environment_overrides( fallback_directory: impl Into<PathBuf>, trust_map: gix_sec::trust::Mapping<Options>, ) -> Result<Self, Error> { + let _span = gix_trace::coarse!("ThreadSafeRepository::open_with_environment_overrides()"); let overrides = EnvironmentOverrides::from_env()?; let (path, path_kind): (PathBuf, _) = match overrides.git_dir { Some(git_dir) => gix_discover::is_git(&git_dir) @@ -139,6 +153,7 @@ impl ThreadSafeRepository { mut worktree_dir: Option<PathBuf>, options: Options, ) -> Result<Self, Error> { + let _span = gix_trace::detail!("open_from_paths()"); let Options { git_dir_trust, object_store_slots, @@ -164,7 +179,7 @@ impl ThreadSafeRepository { // This would be something read in later as have to first check for extensions. Also this means // that each worktree, even if accessible through this instance, has to come in its own Repository instance // as it may have its own configuration. That's fine actually. - let common_dir = gix_discover::path::from_plain_file(git_dir.join("commondir")) + let common_dir = gix_discover::path::from_plain_file(git_dir.join("commondir").as_ref()) .transpose()? .map(|cd| git_dir.join(cd)); let common_dir_ref = common_dir.as_deref().unwrap_or(&git_dir); @@ -180,8 +195,10 @@ impl ThreadSafeRepository { let reflog = repo_config.reflog.unwrap_or(gix_ref::store::WriteReflog::Disable); let object_hash = repo_config.object_hash; match &common_dir { - Some(common_dir) => crate::RefStore::for_linked_worktree(&git_dir, common_dir, reflog, object_hash), - None => crate::RefStore::at(&git_dir, reflog, object_hash), + Some(common_dir) => { + crate::RefStore::for_linked_worktree(git_dir.to_owned(), common_dir.into(), reflog, object_hash) + } + None => crate::RefStore::at(git_dir.to_owned(), reflog, object_hash), } }; let head = refs.find("HEAD").ok(); @@ -205,7 +222,13 @@ impl ThreadSafeRepository { )?; if bail_if_untrusted && git_dir_trust != gix_sec::Trust::Full { - check_safe_directories(&git_dir, git_install_dir.as_deref(), home.as_deref(), &config)?; + check_safe_directories( + &git_dir, + git_install_dir.as_deref(), + current_dir, + home.as_deref(), + &config, + )?; } // core.worktree might be used to overwrite the worktree directory @@ -218,7 +241,7 @@ impl ThreadSafeRepository { .interpolate(interpolate_context(git_install_dir.as_deref(), home.as_deref())) .map_err(config::Error::PathInterpolation)?; worktree_dir = { - gix_path::normalize(git_dir.join(wt_path), current_dir) + gix_path::normalize(git_dir.join(wt_path).into(), current_dir) .and_then(|wt| wt.as_ref().is_dir().then(|| wt.into_owned())) } } @@ -238,6 +261,7 @@ impl ThreadSafeRepository { refs.write_reflog = config::cache::util::reflog_or_default(config.reflog, worktree_dir.is_some()); let replacements = replacement_objects_refs_prefix(&config.resolved, lenient_config, filter_config_section)? .and_then(|prefix| { + let _span = gix_trace::detail!("find replacement objects"); let platform = refs.iter().ok()?; let iter = platform.prefixed(&prefix).ok()?; let prefix = prefix.to_str()?; @@ -257,7 +281,7 @@ impl ThreadSafeRepository { Ok(ThreadSafeRepository { objects: OwnShared::new(gix_odb::Store::at_opts( common_dir_ref.join("objects"), - replacements, + &mut replacements.into_iter(), gix_odb::store::init::Options { slots: object_store_slots, object_hash: config.object_hash, @@ -271,8 +295,11 @@ impl ThreadSafeRepository { config, // used when spawning new repositories off this one when following worktrees linked_worktree_options: options, + #[cfg(feature = "index")] index: gix_fs::SharedFileSnapshotMut::new().into(), shallow_commits: gix_fs::SharedFileSnapshotMut::new().into(), + #[cfg(feature = "attributes")] + modules: gix_fs::SharedFileSnapshotMut::new().into(), }) } } @@ -309,11 +336,12 @@ fn replacement_objects_refs_prefix( fn check_safe_directories( git_dir: &std::path::Path, git_install_dir: Option<&std::path::Path>, + current_dir: &std::path::Path, home: Option<&std::path::Path>, config: &config::Cache, ) -> Result<(), Error> { let mut is_safe = false; - let git_dir = match gix_path::realpath(git_dir) { + let git_dir = match gix_path::realpath_opts(git_dir, current_dir, gix_path::realpath::MAX_SYMLINKS) { Ok(p) => p, Err(_) => git_dir.to_owned(), }; |