Skip to content

Commit

Permalink
config: move ConfigResultExt from settings module
Browse files Browse the repository at this point in the history
As the name suggests, this helper should be in the config module.
  • Loading branch information
yuja committed Dec 6, 2024
1 parent dfa5a6b commit ba739b2
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use jj_lib::backend::TreeValue;
use jj_lib::commit::Commit;
use jj_lib::config::ConfigError;
use jj_lib::config::ConfigNamePathBuf;
use jj_lib::config::ConfigResultExt as _;
use jj_lib::config::StackedConfig;
use jj_lib::conflicts::ConflictMarkerStyle;
use jj_lib::file_util;
Expand Down Expand Up @@ -110,7 +111,6 @@ use jj_lib::revset::RevsetWorkspaceContext;
use jj_lib::revset::SymbolResolverExtension;
use jj_lib::revset::UserRevsetExpression;
use jj_lib::rewrite::restore_tree;
use jj_lib::settings::ConfigResultExt as _;
use jj_lib::settings::UserSettings;
use jj_lib::str_util::StringPattern;
use jj_lib::transaction::Transaction;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/git/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

use clap_complete::ArgValueCandidates;
use itertools::Itertools;
use jj_lib::config::ConfigResultExt as _;
use jj_lib::repo::Repo;
use jj_lib::settings::ConfigResultExt as _;
use jj_lib::settings::UserSettings;
use jj_lib::str_util::StringPattern;

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use clap::ArgGroup;
use clap_complete::ArgValueCandidates;
use itertools::Itertools;
use jj_lib::backend::CommitId;
use jj_lib::config::ConfigResultExt as _;
use jj_lib::git;
use jj_lib::git::GitBranchPushTargets;
use jj_lib::git::GitPushError;
Expand All @@ -32,7 +33,6 @@ use jj_lib::refs::BookmarkPushUpdate;
use jj_lib::refs::LocalAndRemoteRef;
use jj_lib::repo::Repo;
use jj_lib::revset::RevsetExpression;
use jj_lib::settings::ConfigResultExt as _;
use jj_lib::settings::UserSettings;
use jj_lib::str_util::StringPattern;
use jj_lib::view::View;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use clap_complete::ArgValueCandidates;
use jj_lib::backend::CommitId;
use jj_lib::config::ConfigError;
use jj_lib::config::ConfigResultExt as _;
use jj_lib::graph::GraphEdgeType;
use jj_lib::graph::ReverseGraphIterator;
use jj_lib::graph::TopoGroupedGraphIterator;
Expand All @@ -23,7 +24,6 @@ use jj_lib::revset::RevsetEvaluationError;
use jj_lib::revset::RevsetExpression;
use jj_lib::revset::RevsetFilterPredicate;
use jj_lib::revset::RevsetIteratorExt;
use jj_lib::settings::ConfigResultExt as _;
use jj_lib::settings::UserSettings;
use tracing::instrument;

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/operation/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use std::slice;

use itertools::Itertools as _;
use jj_lib::config::ConfigError;
use jj_lib::config::ConfigResultExt as _;
use jj_lib::op_walk;
use jj_lib::operation::Operation;
use jj_lib::repo::RepoLoader;
use jj_lib::settings::ConfigResultExt as _;
use jj_lib::settings::UserSettings;

use super::diff::show_op_diff;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/diff_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use jj_lib::backend::CopyRecord;
use jj_lib::backend::TreeValue;
use jj_lib::commit::Commit;
use jj_lib::config::ConfigError;
use jj_lib::config::ConfigResultExt as _;
use jj_lib::conflicts::materialize_merge_result_to_bytes;
use jj_lib::conflicts::materialized_diff_stream;
use jj_lib::conflicts::ConflictMarkerStyle;
Expand Down Expand Up @@ -61,7 +62,6 @@ use jj_lib::repo_path::InvalidRepoPathError;
use jj_lib::repo_path::RepoPath;
use jj_lib::repo_path::RepoPathUiConverter;
use jj_lib::rewrite::rebase_to_dest_parent;
use jj_lib::settings::ConfigResultExt as _;
use jj_lib::settings::UserSettings;
use jj_lib::store::Store;
use pollster::FutureExt;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/merge_tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::sync::Arc;
use jj_lib::backend::MergedTreeId;
use jj_lib::config::ConfigError;
use jj_lib::config::ConfigNamePathBuf;
use jj_lib::config::ConfigResultExt as _;
use jj_lib::conflicts::extract_as_single_hunk;
use jj_lib::conflicts::ConflictMarkerStyle;
use jj_lib::gitignore::GitIgnoreFile;
Expand All @@ -29,7 +30,6 @@ use jj_lib::merged_tree::MergedTree;
use jj_lib::repo_path::InvalidRepoPathError;
use jj_lib::repo_path::RepoPath;
use jj_lib::repo_path::RepoPathBuf;
use jj_lib::settings::ConfigResultExt as _;
use jj_lib::settings::UserSettings;
use jj_lib::working_copy::SnapshotError;
use pollster::FutureExt;
Expand Down
16 changes: 16 additions & 0 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ pub type ConfigValue = config::Value;
// TODO: will be replaced with our custom error type
pub type ConfigError = config::ConfigError;

/// Extension methods for `Result<T, ConfigError>`.
pub trait ConfigResultExt<T> {
/// Converts `NotFound` error to `Ok(None)`, leaving other errors.
fn optional(self) -> Result<Option<T>, ConfigError>;
}

impl<T> ConfigResultExt<T> for Result<T, ConfigError> {
fn optional(self) -> Result<Option<T>, ConfigError> {
match self {
Ok(value) => Ok(Some(value)),
Err(ConfigError::NotFound(_)) => Ok(None),
Err(err) => Err(err),
}
}
}

/// Dotted config name path.
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ConfigNamePathBuf(Vec<toml_edit::Key>);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fsmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use std::path::PathBuf;

use crate::config::ConfigError;
use crate::settings::ConfigResultExt;
use crate::config::ConfigResultExt as _;
use crate::settings::UserSettings;

/// Config for Watchman filesystem monitor (<https://facebook.github.io/watchman/>).
Expand Down
2 changes: 1 addition & 1 deletion lib/src/gpg_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::str;
use thiserror::Error;

use crate::config::ConfigError;
use crate::settings::ConfigResultExt as _;
use crate::config::ConfigResultExt as _;
use crate::settings::UserSettings;
use crate::signing::SigStatus;
use crate::signing::SignError;
Expand Down
15 changes: 1 addition & 14 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::backend::Commit;
use crate::backend::Signature;
use crate::backend::Timestamp;
use crate::config::ConfigError;
use crate::config::ConfigResultExt as _;
use crate::config::ConfigTable;
use crate::config::ConfigValue;
use crate::config::StackedConfig;
Expand Down Expand Up @@ -326,20 +327,6 @@ impl JJRng {
}
}

pub trait ConfigResultExt<T> {
fn optional(self) -> Result<Option<T>, ConfigError>;
}

impl<T> ConfigResultExt<T> for Result<T, ConfigError> {
fn optional(self) -> Result<Option<T>, ConfigError> {
match self {
Ok(value) => Ok(Some(value)),
Err(ConfigError::NotFound(_)) => Ok(None),
Err(err) => Err(err),
}
}
}

/// A size in bytes optionally formatted/serialized with binary prefixes
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Deserialize)]
#[serde(try_from = "String")]
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ssh_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use either::Either;
use thiserror::Error;

use crate::config::ConfigError;
use crate::settings::ConfigResultExt as _;
use crate::config::ConfigResultExt as _;
use crate::settings::UserSettings;
use crate::signing::SigStatus;
use crate::signing::SignError;
Expand Down

0 comments on commit ba739b2

Please sign in to comment.