Skip to content
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
18 changes: 9 additions & 9 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,16 @@

**ゴール**: リポジトリ内の情報を素早く見つけられる

- [ ] ファイル内容検索
- [ ] リポジトリ全体のテキスト検索(git grep)
- [ ] 正規表現対応
- [x] ファイル内容検索
- [x] リポジトリ全体のテキスト検索(git grep)
- [x] 正規表現対応
- [ ] 検索結果からファイルを開く
- [ ] コミット検索
- [ ] コミットメッセージ検索
- [ ] 差分内容から検索(pickaxe / -S オプション相当)
- [ ] ファイル名検索
- [ ] パターンでファイルを検索
- [ ] ファジーマッチ対応
- [x] コミット検索
- [x] コミットメッセージ検索
- [x] 差分内容から検索(pickaxe / -S オプション相当)
- [x] ファイル名検索
- [x] パターンでファイルを検索
- [x] ファジーマッチ対応

**完動品としての価値**: 「あの変更どこだっけ?」を素早く解決できる

Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ pub mod rebase;
pub mod remote;
pub mod reset;
pub mod revert;
pub mod search;
pub mod stash;
pub mod tag;
49 changes: 49 additions & 0 deletions src-tauri/src/commands/search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use tauri::State;

use crate::git::search::{CodeSearchResult, CommitSearchResult, FilenameSearchResult};
use crate::state::AppState;

#[tauri::command]
pub fn search_code(
query: String,
is_regex: bool,
state: State<'_, AppState>,
) -> Result<Vec<CodeSearchResult>, String> {
let repo_lock = state
.repo
.lock()
.map_err(|e| format!("Lock poisoned: {e}"))?;
let backend = repo_lock.as_ref().ok_or("No repository opened")?;
backend
.search_code(&query, is_regex)
.map_err(|e| e.to_string())
}

#[tauri::command]
pub fn search_commits(
query: String,
search_diff: bool,
state: State<'_, AppState>,
) -> Result<Vec<CommitSearchResult>, String> {
let repo_lock = state
.repo
.lock()
.map_err(|e| format!("Lock poisoned: {e}"))?;
let backend = repo_lock.as_ref().ok_or("No repository opened")?;
backend
.search_commits(&query, search_diff)
.map_err(|e| e.to_string())
}

#[tauri::command]
pub fn search_filenames(
query: String,
state: State<'_, AppState>,
) -> Result<Vec<FilenameSearchResult>, String> {
let repo_lock = state
.repo
.lock()
.map_err(|e| format!("Lock poisoned: {e}"))?;
let backend = repo_lock.as_ref().ok_or("No repository opened")?;
backend.search_filenames(&query).map_err(|e| e.to_string())
}
6 changes: 6 additions & 0 deletions src-tauri/src/git/backend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::Path;

use crate::git::error::GitResult;
use crate::git::search::{CodeSearchResult, CommitSearchResult, FilenameSearchResult};
use crate::git::types::{
BlameResult, BranchInfo, CherryPickMode, CherryPickResult, CommitDetail, CommitInfo,
CommitLogResult, CommitResult, ConflictFile, ConflictResolution, DiffOptions, FetchResult,
Expand Down Expand Up @@ -108,4 +109,9 @@ pub trait GitBackend: Send + Sync {

// Reflog operations
fn get_reflog(&self, ref_name: &str, limit: usize) -> GitResult<Vec<ReflogEntry>>;

// Search operations
fn search_code(&self, query: &str, is_regex: bool) -> GitResult<Vec<CodeSearchResult>>;
fn search_commits(&self, query: &str, search_diff: bool) -> GitResult<Vec<CommitSearchResult>>;
fn search_filenames(&self, query: &str) -> GitResult<Vec<FilenameSearchResult>>;
}
3 changes: 3 additions & 0 deletions src-tauri/src/git/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ pub enum GitError {

#[error("failed to read reflog: {0}")]
ReflogFailed(#[source] Box<dyn std::error::Error + Send + Sync>),

#[error("search failed: {0}")]
SearchFailed(#[source] Box<dyn std::error::Error + Send + Sync>),
}

pub type GitResult<T> = Result<T, GitError>;
13 changes: 13 additions & 0 deletions src-tauri/src/git/git2_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use git2::{
use crate::git::auth::create_credentials_callback;
use crate::git::backend::GitBackend;
use crate::git::error::{GitError, GitResult};
use crate::git::search::{self, CodeSearchResult, CommitSearchResult, FilenameSearchResult};
use crate::git::types::{
BlameLine, BlameResult, BranchInfo, CherryPickMode, CherryPickResult, CommitDetail,
CommitFileChange, CommitFileStatus, CommitGraphRow, CommitInfo, CommitLogResult, CommitRef,
Expand Down Expand Up @@ -2028,6 +2029,18 @@ impl GitBackend for Git2Backend {

Ok(entries)
}

fn search_code(&self, query: &str, is_regex: bool) -> GitResult<Vec<CodeSearchResult>> {
search::search_code(&self.workdir, query, is_regex)
}

fn search_commits(&self, query: &str, search_diff: bool) -> GitResult<Vec<CommitSearchResult>> {
search::search_commits(&self.workdir, query, search_diff)
}

fn search_filenames(&self, query: &str) -> GitResult<Vec<FilenameSearchResult>> {
search::search_filenames(&self.workdir, query)
}
}

impl Git2Backend {
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod backend;
pub mod dispatcher;
pub mod error;
pub mod git2_backend;
pub mod search;
pub mod types;
Loading