refactor: 移除未使用的代码和注释掉的辅助函数

This commit is contained in:
2026-03-20 18:05:33 +08:00
parent 0289dd4684
commit 0c7d2ad518
6 changed files with 123 additions and 118 deletions

View File

@@ -1,7 +1,7 @@
use super::{AppConfig, GitProfile, TokenConfig};
use crate::utils::keyring::{KeyringManager, get_default_base_url, get_default_model, provider_needs_api_key};
use anyhow::{bail, Context, Result};
use std::collections::HashMap;
// use std::collections::HashMap;
use std::path::{Path, PathBuf};
/// Configuration manager
@@ -64,10 +64,10 @@ impl ConfigManager {
Ok(())
}
/// Force save configuration
pub fn force_save(&self) -> Result<()> {
self.config.save(&self.config_path)
}
// /// Force save configuration
// pub fn force_save(&self) -> Result<()> {
// self.config.save(&self.config_path)
// }
/// Get configuration file path
pub fn path(&self) -> &Path {
@@ -118,11 +118,11 @@ impl ConfigManager {
self.config.profiles.get(name)
}
/// Get mutable profile
pub fn get_profile_mut(&mut self, name: &str) -> Option<&mut GitProfile> {
self.modified = true;
self.config.profiles.get_mut(name)
}
// /// Get mutable profile
// pub fn get_profile_mut(&mut self, name: &str) -> Option<&mut GitProfile> {
// self.modified = true;
// self.config.profiles.get_mut(name)
// }
/// List all profile names
pub fn list_profiles(&self) -> Vec<&String> {
@@ -170,10 +170,10 @@ impl ConfigManager {
}
}
/// Get profile usage statistics
pub fn get_profile_usage(&self, name: &str) -> Option<&super::UsageStats> {
self.config.profiles.get(name).map(|p| &p.usage)
}
// /// Get profile usage statistics
// pub fn get_profile_usage(&self, name: &str) -> Option<&super::UsageStats> {
// self.config.profiles.get(name).map(|p| &p.usage)
// }
// Token management
@@ -188,10 +188,10 @@ impl ConfigManager {
}
}
/// Get a token from a profile
pub fn get_token_from_profile(&self, profile_name: &str, service: &str) -> Option<&TokenConfig> {
self.config.profiles.get(profile_name)?.get_token(service)
}
// /// Get a token from a profile
// pub fn get_token_from_profile(&self, profile_name: &str, service: &str) -> Option<&TokenConfig> {
// self.config.profiles.get(profile_name)?.get_token(service)
// }
/// Remove a token from a profile
pub fn remove_token_from_profile(&mut self, profile_name: &str, service: &str) -> Result<()> {
@@ -204,20 +204,20 @@ impl ConfigManager {
}
}
/// List all tokens in a profile
pub fn list_profile_tokens(&self, profile_name: &str) -> Option<Vec<&String>> {
self.config.profiles.get(profile_name).map(|p| p.tokens.keys().collect())
}
// /// List all tokens in a profile
// pub fn list_profile_tokens(&self, profile_name: &str) -> Option<Vec<&String>> {
// self.config.profiles.get(profile_name).map(|p| p.tokens.keys().collect())
// }
// Repository profile management
/// Get profile for repository
pub fn get_repo_profile(&self, repo_path: &str) -> Option<&GitProfile> {
self.config
.repo_profiles
.get(repo_path)
.and_then(|name| self.config.profiles.get(name))
}
// /// Get profile for repository
// pub fn get_repo_profile(&self, repo_path: &str) -> Option<&GitProfile> {
// self.config
// .repo_profiles
// .get(repo_path)
// .and_then(|name| self.config.profiles.get(name))
// }
/// Set profile for repository
pub fn set_repo_profile(&mut self, repo_path: String, profile_name: String) -> Result<()> {
@@ -229,26 +229,26 @@ impl ConfigManager {
Ok(())
}
/// Remove repository profile mapping
pub fn remove_repo_profile(&mut self, repo_path: &str) {
self.config.repo_profiles.remove(repo_path);
self.modified = true;
}
// /// Remove repository profile mapping
// pub fn remove_repo_profile(&mut self, repo_path: &str) {
// self.config.repo_profiles.remove(repo_path);
// self.modified = true;
// }
/// List repository profile mappings
pub fn list_repo_profiles(&self) -> &HashMap<String, String> {
&self.config.repo_profiles
}
// /// List repository profile mappings
// pub fn list_repo_profiles(&self) -> &HashMap<String, String> {
// &self.config.repo_profiles
// }
/// Get effective profile for a repository (repo-specific -> default)
pub fn get_effective_profile(&self, repo_path: Option<&str>) -> Option<&GitProfile> {
if let Some(path) = repo_path {
if let Some(profile) = self.get_repo_profile(path) {
return Some(profile);
}
}
self.default_profile()
}
// /// Get effective profile for a repository (repo-specific -> default)
// pub fn get_effective_profile(&self, repo_path: Option<&str>) -> Option<&GitProfile> {
// if let Some(path) = repo_path {
// if let Some(profile) = self.get_repo_profile(path) {
// return Some(profile);
// }
// }
// self.default_profile()
// }
/// Check and compare profile with git configuration
pub fn check_profile_config(&self, profile_name: &str, repo: &git2::Repository) -> Result<super::ProfileComparison> {
@@ -383,31 +383,31 @@ impl ConfigManager {
&self.keyring
}
/// Configure LLM provider with all settings
pub fn configure_llm(&mut self, provider: String, model: Option<String>, base_url: Option<String>, api_key: Option<&str>) -> Result<()> {
self.set_llm_provider(provider.clone());
// /// Configure LLM provider with all settings
// pub fn configure_llm(&mut self, provider: String, model: Option<String>, base_url: Option<String>, api_key: Option<&str>) -> Result<()> {
// self.set_llm_provider(provider.clone());
if let Some(m) = model {
self.set_llm_model(m);
}
// if let Some(m) = model {
// self.set_llm_model(m);
// }
self.set_llm_base_url(base_url);
// self.set_llm_base_url(base_url);
if let Some(key) = api_key {
if provider_needs_api_key(&provider) {
self.set_api_key(key)?;
}
}
// if let Some(key) = api_key {
// if provider_needs_api_key(&provider) {
// self.set_api_key(key)?;
// }
// }
Ok(())
}
// Ok(())
// }
// Commit configuration
/// Get commit format
pub fn commit_format(&self) -> super::CommitFormat {
self.config.commit.format
}
// /// Get commit format
// pub fn commit_format(&self) -> super::CommitFormat {
// self.config.commit.format
// }
/// Set commit format
pub fn set_commit_format(&mut self, format: super::CommitFormat) {
@@ -415,10 +415,10 @@ impl ConfigManager {
self.modified = true;
}
/// Check if auto-generate is enabled
pub fn auto_generate_commits(&self) -> bool {
self.config.commit.auto_generate
}
// /// Check if auto-generate is enabled
// pub fn auto_generate_commits(&self) -> bool {
// self.config.commit.auto_generate
// }
/// Set auto-generate commits
pub fn set_auto_generate_commits(&mut self, enabled: bool) {
@@ -428,10 +428,10 @@ impl ConfigManager {
// Tag configuration
/// Get version prefix
pub fn version_prefix(&self) -> &str {
&self.config.tag.version_prefix
}
// /// Get version prefix
// pub fn version_prefix(&self) -> &str {
// &self.config.tag.version_prefix
// }
/// Set version prefix
pub fn set_version_prefix(&mut self, prefix: String) {
@@ -441,10 +441,10 @@ impl ConfigManager {
// Changelog configuration
/// Get changelog path
pub fn changelog_path(&self) -> &str {
&self.config.changelog.path
}
// /// Get changelog path
// pub fn changelog_path(&self) -> &str {
// &self.config.changelog.path
// }
/// Set changelog path
pub fn set_changelog_path(&mut self, path: String) {
@@ -454,10 +454,10 @@ impl ConfigManager {
// Language configuration
/// Get output language
pub fn output_language(&self) -> &str {
&self.config.language.output_language
}
// /// Get output language
// pub fn output_language(&self) -> &str {
// &self.config.language.output_language
// }
/// Set output language
pub fn set_output_language(&mut self, language: String) {