move normalize_branch_name to core

This commit is contained in:
Kiril Videlov 2024-07-07 16:04:01 +02:00
parent 948c89e8be
commit ce130dcf12
No known key found for this signature in database
GPG Key ID: A4C733025427C471
3 changed files with 10 additions and 8 deletions

View File

@ -16,14 +16,15 @@ use git2::build::TreeUpdateBuilder;
use git2::ErrorCode;
use git2_hooks::HookResult;
use hex::ToHex;
use regex::Regex;
use serde::{Deserialize, Serialize};
use gitbutler_core::error::Code;
use gitbutler_core::error::Marker;
use gitbutler_core::git::diff::GitHunk;
use gitbutler_core::git::diff::{diff_files_into_hunks, trees, FileDiff};
use gitbutler_core::git::{CommitExt, CommitHeadersV2, HasCommitHeaders, RepositoryExt};
use gitbutler_core::git::{
normalize_branch_name, CommitExt, CommitHeadersV2, HasCommitHeaders, RepositoryExt,
};
use gitbutler_core::rebase::{cherry_rebase, cherry_rebase_group};
use gitbutler_core::time::now_since_unix_epoch_ms;
use gitbutler_core::virtual_branches::branch::HunkHash;
@ -230,11 +231,6 @@ pub enum NameConflitResolution {
Overwrite,
}
pub fn normalize_branch_name(name: &str) -> String {
let pattern = Regex::new("[^A-Za-z0-9_/.#]+").unwrap();
pattern.replace_all(name, "-").to_string()
}
pub fn unapply_ownership(
project_repository: &project_repository::Repository,
ownership: &BranchOwnershipClaims,

View File

@ -1,2 +1,8 @@
mod refname;
pub use refname::{LocalRefname, Refname, RemoteRefname, VirtualRefname};
use regex::Regex;
pub fn normalize_branch_name(name: &str) -> String {
let pattern = Regex::new("[^A-Za-z0-9_/.#]+").unwrap();
pattern.replace_all(name, "-").to_string()
}

View File

@ -3,7 +3,7 @@ use std::{fmt, str::FromStr};
use serde::{Deserialize, Serialize};
use super::error::Error;
use crate::virtual_branches::{normalize_branch_name, Branch};
use crate::{git::normalize_branch_name, virtual_branches::Branch};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Refname {