From 1df251baca6a5e48eddd31849a65ee56d6ce7f63 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Wed, 4 Oct 2023 16:44:30 +0200 Subject: [PATCH] chore: remove unused fileGroup function and related code --- packages/tauri/src/app.rs | 7 --- packages/tauri/src/main.rs | 20 -------- .../src/project_repository/repository.rs | 46 ------------------- packages/ui/src/lib/api/git/index.ts | 5 -- .../lib/components/CommandPalette/commands.ts | 27 ----------- 5 files changed, 105 deletions(-) delete mode 100644 packages/ui/src/lib/api/git/index.ts diff --git a/packages/tauri/src/app.rs b/packages/tauri/src/app.rs index 3c37d7c9c..39b7f9978 100644 --- a/packages/tauri/src/app.rs +++ b/packages/tauri/src/app.rs @@ -366,13 +366,6 @@ impl App { Ok(diff) } - pub fn git_match_paths(&self, project_id: &str, pattern: &str) -> Result> { - let project = self.gb_project(project_id)?; - let project_repository = project_repository::Repository::open(&project) - .context("failed to open project repository")?; - project_repository.git_match_paths(pattern) - } - pub fn git_remote_branches(&self, project_id: &str) -> Result> { let project = self.gb_project(project_id)?; let project_repository = project_repository::Repository::open(&project) diff --git a/packages/tauri/src/main.rs b/packages/tauri/src/main.rs index 0155e8d49..6e56f68fd 100644 --- a/packages/tauri/src/main.rs +++ b/packages/tauri/src/main.rs @@ -260,25 +260,6 @@ async fn git_wd_diff( Ok(diff) } -#[tauri::command(async)] -#[instrument(skip(handle))] -async fn git_match_paths( - handle: tauri::AppHandle, - project_id: &str, - match_pattern: &str, -) -> Result, Error> { - let app = handle.state::(); - let paths = app - .git_match_paths(project_id, match_pattern) - .with_context(|| { - format!( - "failed to get git match paths for project {} and pattern {}", - project_id, match_pattern - ) - })?; - Ok(paths) -} - #[tauri::command(async)] #[instrument(skip(handle))] async fn git_remote_branches( @@ -602,7 +583,6 @@ fn main() { delete_user, get_user, search, - git_match_paths, git_remote_branches, git_remote_branches_data, git_head, diff --git a/packages/tauri/src/project_repository/repository.rs b/packages/tauri/src/project_repository/repository.rs index 84117231f..0b937e630 100644 --- a/packages/tauri/src/project_repository/repository.rs +++ b/packages/tauri/src/project_repository/repository.rs @@ -1,7 +1,6 @@ use std::path; use anyhow::{Context, Result}; -use walkdir::WalkDir; use crate::{git, keys, projects, reader, users}; @@ -71,51 +70,6 @@ impl Repository { self.git_repository.path().parent().unwrap() } - pub fn git_match_paths(&self, pattern: &str) -> Result> { - let workdir = self - .git_repository - .workdir() - .with_context(|| "failed to get working directory")?; - - let pattern = pattern.to_lowercase(); - let mut files = vec![]; - for entry in WalkDir::new(workdir) - .into_iter() - .filter_entry(|entry| { - // need to remove workdir so we're not matching it - let relative_path = entry - .path() - .strip_prefix(workdir) - .unwrap() - .to_str() - .unwrap(); - // this is to make it faster, so we dont have to traverse every directory if it is ignored by git - entry.path().to_str() == workdir.to_str() // but we need to traverse the first one - || ((entry.file_type().is_dir() // traverse all directories if they are not ignored by git - || relative_path.to_lowercase().contains(&pattern)) // but only pass on files that match the regex - && !self.git_repository.is_path_ignored(entry.path()).unwrap_or(true)) - }) - .filter_map(Result::ok) - { - if entry.file_type().is_file() { - // only save the matching files, not the directories - let path = entry.path(); - let path = path - .strip_prefix::<&std::path::Path>(workdir.as_ref()) - .with_context(|| { - format!( - "failed to strip prefix from path {}", - path.to_str().unwrap() - ) - })?; - let path = path.to_str().unwrap().to_string(); - files.push(path); - } - } - files.sort(); - Ok(files) - } - pub fn git_remote_branches(&self) -> Result> { self.git_repository .branches(Some(git2::BranchType::Remote))? diff --git a/packages/ui/src/lib/api/git/index.ts b/packages/ui/src/lib/api/git/index.ts deleted file mode 100644 index 87208cfcd..000000000 --- a/packages/ui/src/lib/api/git/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { invoke } from '$lib/ipc'; - -export function matchFiles(params: { projectId: string; matchPattern: string }) { - return invoke('git_match_paths', params); -} diff --git a/packages/ui/src/lib/components/CommandPalette/commands.ts b/packages/ui/src/lib/components/CommandPalette/commands.ts index 82a33973d..0c401f18d 100644 --- a/packages/ui/src/lib/components/CommandPalette/commands.ts +++ b/packages/ui/src/lib/components/CommandPalette/commands.ts @@ -1,5 +1,4 @@ import type { Project } from '$lib/api/ipc/projects'; -import { matchFiles } from '$lib/api/git'; import * as events from '$lib/events'; import { IconFile, @@ -144,31 +143,6 @@ const navigateGroup = ({ project, input }: { project?: Project; input: string }) ].filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase())) }); -const fileGroup = ({ - project, - input -}: { - project: Project; - input: string; -}): Group | Promise => - input.length === 0 - ? { - title: 'Files', - description: 'type part of a file name', - commands: [] - } - : matchFiles({ projectId: project.id, matchPattern: input }).then((files) => ({ - title: 'Files', - description: files.length === 0 ? `no files containing '${input}'` : '', - commands: files.map((file) => ({ - title: file, - action: { - href: '/' - }, - icon: IconFile - })) - })); - const supportGroup = ({ input }: { input: string }): Group => ({ title: 'Help & Support', commands: [ @@ -203,7 +177,6 @@ export default (params: { projects: Project[]; project?: Project; input: string groups.push(commandsGroup({ project, input })); groups.push(navigateGroup({ project, input })); !project && groups.push(projectsGroup({ projects, input })); - project && groups.push(fileGroup({ project, input })); groups.push(supportGroup({ input })); return groups;