chore: remove unused fileGroup function and related code

This commit is contained in:
Nikita Galaiko 2023-10-04 16:44:30 +02:00 committed by GitButler
parent b2fe090633
commit 1df251baca
5 changed files with 0 additions and 105 deletions

View File

@ -366,13 +366,6 @@ impl App {
Ok(diff)
}
pub fn git_match_paths(&self, project_id: &str, pattern: &str) -> Result<Vec<String>> {
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<Vec<git::RemoteBranchName>> {
let project = self.gb_project(project_id)?;
let project_repository = project_repository::Repository::open(&project)

View File

@ -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<Vec<String>, Error> {
let app = handle.state::<app::App>();
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,

View File

@ -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<Vec<String>> {
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<Vec<git::RemoteBranchName>> {
self.git_repository
.branches(Some(git2::BranchType::Remote))?

View File

@ -1,5 +0,0 @@
import { invoke } from '$lib/ipc';
export function matchFiles(params: { projectId: string; matchPattern: string }) {
return invoke<string[]>('git_match_paths', params);
}

View File

@ -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<Group> =>
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;