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

@@ -373,26 +373,26 @@ impl CommitCommand {
} }
} }
// Helper trait for optional builder methods // // Helper trait for optional builder methods
trait CommitBuilderExt { // trait CommitBuilderExt {
fn scope_opt(self, scope: Option<String>) -> Self; // fn scope_opt(self, scope: Option<String>) -> Self;
fn body_opt(self, body: Option<String>) -> Self; // fn body_opt(self, body: Option<String>) -> Self;
} // }
impl CommitBuilderExt for CommitBuilder { // impl CommitBuilderExt for CommitBuilder {
fn scope_opt(self, scope: Option<String>) -> Self { // fn scope_opt(self, scope: Option<String>) -> Self {
if let Some(s) = scope { // if let Some(s) = scope {
self.scope(s) // self.scope(s)
} else { // } else {
self // self
} // }
} // }
fn body_opt(self, body: Option<String>) -> Self { // fn body_opt(self, body: Option<String>) -> Self {
if let Some(b) = body { // if let Some(b) = body {
self.body(b) // self.body(b)
} else { // } else {
self // self
} // }
} // }
} // }

View File

@@ -750,7 +750,7 @@ impl ConfigCommand {
let manager = self.get_manager(config_path)?; let manager = self.get_manager(config_path)?;
let toml = manager.export()?; let toml = manager.export()?;
let export_content = if let Some(path) = output { let export_content = if let Some(_path) = output {
let pwd = if let Some(p) = password { let pwd = if let Some(p) = password {
p.to_string() p.to_string()
} else { } else {

View File

@@ -240,7 +240,7 @@ impl InitCommand {
.or_else(|_| std::env::var(format!("QUICOMMIT_{}_API_KEY", provider.to_uppercase()))) .or_else(|_| std::env::var(format!("QUICOMMIT_{}_API_KEY", provider.to_uppercase())))
.ok(); .ok();
if let Some(key) = env_key { if let Some(_key) = env_key {
println!("\n{} {}", "".green(), "Found API key in environment variable.".green()); println!("\n{} {}", "".green(), "Found API key in environment variable.".green());
None None
} else if keyring_available { } else if keyring_available {

View File

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

View File

@@ -9,7 +9,7 @@ pub mod profile;
pub use profile::{ pub use profile::{
GitProfile, TokenConfig, TokenType, GitProfile, TokenConfig, TokenType,
UsageStats, ProfileComparison ProfileComparison
}; };
/// Application configuration /// Application configuration
@@ -505,18 +505,18 @@ impl AppConfig {
Ok(config_dir.join("quicommit").join("config.toml")) Ok(config_dir.join("quicommit").join("config.toml"))
} }
/// Get profile for a repository // /// Get profile for a repository
pub fn get_profile_for_repo(&self, repo_path: &str) -> Option<&GitProfile> { // pub fn get_profile_for_repo(&self, repo_path: &str) -> Option<&GitProfile> {
let profile_name = self.repo_profiles.get(repo_path)?; // let profile_name = self.repo_profiles.get(repo_path)?;
self.profiles.get(profile_name) // self.profiles.get(profile_name)
} // }
/// Set profile for a repository // /// Set profile for a repository
pub fn set_profile_for_repo(&mut self, repo_path: String, profile_name: String) -> Result<()> { // pub fn set_profile_for_repo(&mut self, repo_path: String, profile_name: String) -> Result<()> {
if !self.profiles.contains_key(&profile_name) { // if !self.profiles.contains_key(&profile_name) {
anyhow::bail!("Profile '{}' does not exist", profile_name); // anyhow::bail!("Profile '{}' does not exist", profile_name);
} // }
self.repo_profiles.insert(repo_path, profile_name); // self.repo_profiles.insert(repo_path, profile_name);
Ok(()) // Ok(())
} // }
} }

View File

@@ -642,12 +642,16 @@ impl GitRepo {
name: name.to_string(), name: name.to_string(),
target: oid.to_string(), target: oid.to_string(),
message: commit.message().unwrap_or("").to_string(), message: commit.message().unwrap_or("").to_string(),
time: commit.time().seconds(),
}); });
} }
true true
})?; })?;
// Sort tags by time (newest first)
tags.sort_by(|a, b| b.time.cmp(&a.time));
Ok(tags) Ok(tags)
} }
@@ -832,6 +836,7 @@ pub struct TagInfo {
pub name: String, pub name: String,
pub target: String, pub target: String,
pub message: String, pub message: String,
pub time: i64,
} }
/// Repository status summary /// Repository status summary