Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tooling for better copy detection #1529

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ members = [
"gix-revwalk",
"gix-fsck",
"tests/tools",
"tests/it",
"gix-diff/tests",
"gix-pack/tests",
"gix-odb/tests",
Expand Down
1 change: 1 addition & 0 deletions gix-diff/tests/rewrites/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ fn remove_only() -> crate::Result {
Action::Continue
});
assert_eq!(out, Default::default());
assert!(called);
Ok(())
}

Expand Down
1 change: 0 additions & 1 deletion gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ cache-efficiency-debug = ["gix-features/cache-efficiency-debug"]


[dependencies]
gix-macros = { version = "^0.1.5", path = "../gix-macros" }
gix-utils = { version = "^0.1.12", path = "../gix-utils" }
gix-fs = { version = "^0.11.2", path = "../gix-fs" }
gix-ref = { version = "^0.45.0", path = "../gix-ref" }
Expand Down
8 changes: 0 additions & 8 deletions gix/src/config/snapshot/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::borrow::Cow;
use std::ffi::OsStr;

use gix_features::threading::OwnShared;
use gix_macros::momo;

use crate::bstr::ByteSlice;
use crate::{
Expand All @@ -28,7 +27,6 @@ impl<'repo> Snapshot<'repo> {
}

/// Like [`boolean()`][Self::boolean()], but it will report an error if the value couldn't be interpreted as boolean.
#[momo]
pub fn try_boolean<'a>(&self, key: impl Into<&'a BStr>) -> Option<Result<bool, gix_config::value::Error>> {
self.repo.config.resolved.boolean(key.into())
}
Expand All @@ -44,23 +42,20 @@ impl<'repo> Snapshot<'repo> {
}

/// Like [`integer()`][Self::integer()], but it will report an error if the value couldn't be interpreted as boolean.
#[momo]
pub fn try_integer<'a>(&self, key: impl Into<&'a BStr>) -> Option<Result<i64, gix_config::value::Error>> {
self.repo.config.resolved.integer(key.into())
}

/// Return the string at `key`, or `None` if there is no such value.
///
/// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust.
#[momo]
pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'repo, BStr>> {
self.repo.config.resolved.string(key.into())
}

/// Return the trusted and fully interpolated path at `key`, or `None` if there is no such value
/// or if no value was found in a trusted file.
/// An error occurs if the path could not be interpolated to its final value.
#[momo]
pub fn trusted_path<'a>(
&self,
key: impl Into<&'a BStr>,
Expand All @@ -70,7 +65,6 @@ impl<'repo> Snapshot<'repo> {

/// Return the trusted string at `key` for launching using [command::prepare()](gix_command::prepare()),
/// or `None` if there is no such value or if no value was found in a trusted file.
#[momo]
pub fn trusted_program<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'repo, OsStr>> {
let value = self
.repo
Expand Down Expand Up @@ -120,7 +114,6 @@ impl<'repo> SnapshotMut<'repo> {

/// Set the value at `key` to `new_value`, possibly creating the section if it doesn't exist yet, or overriding the most recent existing
/// value, which will be returned.
#[momo]
pub fn set_value<'b>(
&mut self,
key: &'static dyn crate::config::tree::Key,
Expand All @@ -144,7 +137,6 @@ impl<'repo> SnapshotMut<'repo> {

/// Set the value at `key` to `new_value` in the given `subsection`, possibly creating the section and sub-section if it doesn't exist yet,
/// or overriding the most recent existing value, which will be returned.
#[momo]
pub fn set_subsection_value<'a, 'b>(
&mut self,
key: &'static dyn crate::config::tree::Key,
Expand Down
2 changes: 0 additions & 2 deletions gix/src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{

use gix_config::parse::section;
use gix_discover::DOT_GIT_DIR;
use gix_macros::momo;

/// The error used in [`into()`].
#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -125,7 +124,6 @@ pub struct Options {
/// Note that this is a simple template-based initialization routine which should be accompanied with additional corrections
/// to respect git configuration, which is accomplished by [its callers][crate::ThreadSafeRepository::init_opts()]
/// that return a [Repository][crate::Repository].
#[momo]
pub fn into(
directory: impl Into<PathBuf>,
kind: Kind,
Expand Down
3 changes: 0 additions & 3 deletions gix/src/discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::path::Path;

pub use gix_discover::*;
use gix_macros::momo;

use crate::{bstr::BString, ThreadSafeRepository};

Expand Down Expand Up @@ -32,7 +31,6 @@ impl ThreadSafeRepository {
/// if the directory that is discovered can indeed be trusted (or else they'd have to implement the discovery themselves
/// and be sure that no attacker ever gets access to a directory structure. The cost of this is a permission check, which
/// seems acceptable).
#[momo]
pub fn discover_opts(
directory: impl AsRef<Path>,
options: upwards::Options<'_>,
Expand Down Expand Up @@ -70,7 +68,6 @@ impl ThreadSafeRepository {
/// Consider to set [`match_ceiling_dir_or_error = false`](gix_discover::upwards::Options::match_ceiling_dir_or_error)
/// to allow discovery if an outside environment variable sets non-matching ceiling directories for greater
/// compatibility with Git.
#[momo]
pub fn discover_with_environment_overrides_opts(
directory: impl AsRef<Path>,
mut options: upwards::Options<'_>,
Expand Down
3 changes: 0 additions & 3 deletions gix/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(clippy::result_large_err)]
use std::{borrow::Cow, path::Path};

use gix_macros::momo;
use gix_ref::{
store::WriteReflog,
transaction::{PreviousValue, RefEdit},
Expand Down Expand Up @@ -41,7 +40,6 @@ impl ThreadSafeRepository {
///
/// Fails without action if there is already a `.git` repository inside of `directory`, but
/// won't mind if the `directory` otherwise is non-empty.
#[momo]
pub fn init(
directory: impl AsRef<Path>,
kind: crate::create::Kind,
Expand All @@ -58,7 +56,6 @@ impl ThreadSafeRepository {
///
/// Instead of naming the default branch `master`, we name it `main` unless configured explicitly using the `init.defaultBranch`
/// configuration key.
#[momo]
pub fn init_opts(
directory: impl AsRef<Path>,
kind: crate::create::Kind,
Expand Down
3 changes: 0 additions & 3 deletions gix/src/object/tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use gix_hash::ObjectId;
use gix_macros::momo;
pub use gix_object::tree::{EntryKind, EntryMode};
use gix_object::{bstr::BStr, FindExt, TreeRefIter};

Expand Down Expand Up @@ -132,7 +131,6 @@ impl<'repo> Tree<'repo> {
///
/// If any path component contains illformed UTF-8 and thus can't be converted to bytes on platforms which can't do so natively,
/// the returned component will be empty which makes the lookup fail.
#[momo]
pub fn lookup_entry_by_path(
&self,
relative_path: impl AsRef<std::path::Path>,
Expand All @@ -155,7 +153,6 @@ impl<'repo> Tree<'repo> {
///
/// If any path component contains illformed UTF-8 and thus can't be converted to bytes on platforms which can't do so natively,
/// the returned component will be empty which makes the lookup fail.
#[momo]
pub fn peel_to_entry_by_path(
&mut self,
relative_path: impl AsRef<std::path::Path>,
Expand Down
3 changes: 0 additions & 3 deletions gix/src/open/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::{borrow::Cow, path::PathBuf};

use gix_features::threading::OwnShared;
use gix_macros::momo;

use super::{Error, Options};
use crate::{
Expand Down Expand Up @@ -59,7 +58,6 @@ impl ThreadSafeRepository {
///
/// 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) = {
Expand Down Expand Up @@ -113,7 +111,6 @@ impl ThreadSafeRepository {
// 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>,
Expand Down
5 changes: 0 additions & 5 deletions gix/src/pathspec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Pathspec plumbing and abstractions
use gix_macros::momo;
pub use gix_pathspec::*;

use crate::{bstr::BStr, AttributeStack, Pathspec, PathspecDetached, Repository};
Expand Down Expand Up @@ -124,7 +123,6 @@ impl<'repo> Pathspec<'repo> {
alias = "matches_path",
alias = "git2"
)]
#[momo]
pub fn pattern_matching_relative_path<'a>(
&mut self,
relative_path: impl Into<&'a BStr>,
Expand All @@ -145,7 +143,6 @@ impl<'repo> Pathspec<'repo> {

/// The simplified version of [`pattern_matching_relative_path()`](Self::pattern_matching_relative_path()) which returns
/// `true` if `relative_path` is included in the set of positive pathspecs, while not being excluded.
#[momo]
pub fn is_included<'a>(&mut self, relative_path: impl Into<&'a BStr>, is_dir: Option<bool>) -> bool {
self.pattern_matching_relative_path(relative_path, is_dir)
.map_or(false, |m| !m.is_excluded())
Expand Down Expand Up @@ -180,7 +177,6 @@ impl PathspecDetached {
alias = "matches_path",
alias = "git2"
)]
#[momo]
pub fn pattern_matching_relative_path<'a>(
&mut self,
relative_path: impl Into<&'a BStr>,
Expand All @@ -201,7 +197,6 @@ impl PathspecDetached {

/// The simplified version of [`pattern_matching_relative_path()`](Self::pattern_matching_relative_path()) which returns
/// `true` if `relative_path` is included in the set of positive pathspecs, while not being excluded.
#[momo]
pub fn is_included<'a>(&mut self, relative_path: impl Into<&'a BStr>, is_dir: Option<bool>) -> bool {
self.pattern_matching_relative_path(relative_path, is_dir)
.map_or(false, |m| !m.is_excluded())
Expand Down
2 changes: 0 additions & 2 deletions gix/src/reference/edits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
///
#[allow(clippy::empty_docs)]
pub mod set_target_id {
use gix_macros::momo;
use gix_ref::{transaction::PreviousValue, Target};

use crate::{bstr::BString, Reference};
Expand Down Expand Up @@ -30,7 +29,6 @@ pub mod set_target_id {
/// If multiple reference should be changed, use [`Repository::edit_references()`][crate::Repository::edit_references()]
/// or the lower level reference database instead.
#[allow(clippy::result_large_err)]
#[momo]
pub fn set_target_id(
&mut self,
id: impl Into<gix_hash::ObjectId>,
Expand Down
2 changes: 0 additions & 2 deletions gix/src/reference/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(clippy::empty_docs)]
use std::path::Path;

use gix_macros::momo;
use gix_ref::file::ReferenceExt;

/// A platform to create iterators over references.
Expand Down Expand Up @@ -43,7 +42,6 @@ impl<'r> Platform<'r> {
/// These are of the form `refs/heads` or `refs/remotes/origin`, and must not contain relative paths components like `.` or `..`.
// TODO: Create a custom `Path` type that enforces the requirements of git naturally, this type is surprising possibly on windows
// and when not using a trailing '/' to signal directories.
#[momo]
pub fn prefixed(&self, prefix: impl AsRef<Path>) -> Result<Iter<'_>, init::Error> {
Ok(Iter::new(self.repo, self.platform.prefixed(prefix.as_ref())?))
}
Expand Down
3 changes: 0 additions & 3 deletions gix/src/remote/save.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use gix_macros::momo;

use crate::{
bstr::{BStr, BString},
config, remote, Remote,
Expand Down Expand Up @@ -111,7 +109,6 @@ impl Remote<'_> {
/// If this name is different from the current one, the git configuration will still contain the previous name,
/// and the caller should account for that.
#[allow(clippy::result_large_err)]
#[momo]
pub fn save_as_to(
&mut self,
name: impl Into<BString>,
Expand Down
3 changes: 0 additions & 3 deletions gix/src/repository/config/transport.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![allow(clippy::result_large_err)]
use std::any::Any;

use gix_macros::momo;

use crate::bstr::BStr;

impl crate::Repository {
Expand All @@ -23,7 +21,6 @@ impl crate::Repository {
)),
allow(unused_variables)
)]
#[momo]
pub fn transport_options<'a>(
&self,
url: impl Into<&'a BStr>,
Expand Down
Loading
Loading