mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
parent
988df89e97
commit
53b2c79877
15 changed files with 76 additions and 56 deletions
|
|
@ -28,10 +28,10 @@ pub enum Error {
|
||||||
Git(#[from] git2::Error),
|
Git(#[from] git2::Error),
|
||||||
|
|
||||||
#[error("utf8 error:{0}")]
|
#[error("utf8 error:{0}")]
|
||||||
Utf8Error(#[from] FromUtf8Error),
|
Utf8Conversion(#[from] FromUtf8Error),
|
||||||
|
|
||||||
#[error("TryFromInt error:{0}")]
|
#[error("TryFromInt error:{0}")]
|
||||||
IntError(#[from] TryFromIntError),
|
IntConversion(#[from] TryFromIntError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,33 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
#![deny(unused_imports)]
|
#![deny(unused_imports)]
|
||||||
#![deny(unused_must_use)]
|
#![deny(unused_must_use)]
|
||||||
|
#![deny(dead_code)]
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
|
#![deny(clippy::cargo)]
|
||||||
|
#![deny(clippy::pedantic)]
|
||||||
|
//TODO:
|
||||||
|
// #![deny(clippy::nursery)]
|
||||||
#![deny(clippy::unwrap_used)]
|
#![deny(clippy::unwrap_used)]
|
||||||
#![deny(clippy::panic)]
|
#![deny(clippy::panic)]
|
||||||
#![deny(clippy::perf)]
|
#![deny(clippy::perf)]
|
||||||
|
#![deny(clippy::match_like_matches_macro)]
|
||||||
|
#![deny(clippy::needless_update)]
|
||||||
|
#![allow(clippy::module_name_repetitions)]
|
||||||
//TODO: get this in someday since expect still leads us to crashes sometimes
|
//TODO: get this in someday since expect still leads us to crashes sometimes
|
||||||
// #![deny(clippy::expect_used)]
|
// #![deny(clippy::expect_used)]
|
||||||
|
//TODO:
|
||||||
|
#![allow(clippy::needless_pass_by_value)]
|
||||||
|
#![allow(clippy::must_use_candidate)]
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
|
#![allow(clippy::map_unwrap_or)]
|
||||||
|
#![allow(clippy::option_if_let_else)]
|
||||||
|
#![allow(clippy::manual_ok_or)]
|
||||||
|
#![allow(clippy::doc_markdown)]
|
||||||
|
#![allow(clippy::cast_possible_wrap)]
|
||||||
|
#![allow(clippy::cast_sign_loss)]
|
||||||
|
#![allow(clippy::cast_possible_truncation)]
|
||||||
|
#![allow(clippy::cast_precision_loss)]
|
||||||
|
#![allow(clippy::too_many_lines)]
|
||||||
|
|
||||||
pub mod cached;
|
pub mod cached;
|
||||||
mod commit_files;
|
mod commit_files;
|
||||||
|
|
|
||||||
|
|
@ -156,17 +156,16 @@ impl AsyncLog {
|
||||||
|
|
||||||
if res_is_err || entries.len() <= 1 {
|
if res_is_err || entries.len() <= 1 {
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
Self::notify(&sender);
|
|
||||||
|
|
||||||
let sleep_duration =
|
|
||||||
if arc_background.load(Ordering::Relaxed) {
|
|
||||||
SLEEP_BACKGROUND
|
|
||||||
} else {
|
|
||||||
SLEEP_FOREGROUND
|
|
||||||
};
|
|
||||||
thread::sleep(sleep_duration);
|
|
||||||
}
|
}
|
||||||
|
Self::notify(&sender);
|
||||||
|
|
||||||
|
let sleep_duration =
|
||||||
|
if arc_background.load(Ordering::Relaxed) {
|
||||||
|
SLEEP_BACKGROUND
|
||||||
|
} else {
|
||||||
|
SLEEP_FOREGROUND
|
||||||
|
};
|
||||||
|
thread::sleep(sleep_duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,9 @@ pub fn merge_upstream_commit(
|
||||||
|
|
||||||
repo.merge(&[&annotated_upstream], Some(&mut opt), None)?;
|
repo.merge(&[&annotated_upstream], Some(&mut opt), None)?;
|
||||||
|
|
||||||
assert!(!repo.index()?.has_conflicts());
|
if repo.index()?.has_conflicts() {
|
||||||
|
return Err(Error::Generic("creates conflicts".into()));
|
||||||
|
}
|
||||||
|
|
||||||
let signature =
|
let signature =
|
||||||
crate::sync::commit::signature_allow_undefined_name(&repo)?;
|
crate::sync::commit::signature_allow_undefined_name(&repo)?;
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ pub fn get_branches_info(
|
||||||
.branch_upstream_remote(&reference)
|
.branch_upstream_remote(&reference)
|
||||||
.ok()
|
.ok()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|buf| buf.as_str())
|
.and_then(git2::Buf::as_str)
|
||||||
.map(String::from);
|
.map(String::from);
|
||||||
|
|
||||||
let details = if local {
|
let details = if local {
|
||||||
|
|
@ -318,11 +318,10 @@ pub fn delete_branch(
|
||||||
let repo = utils::repo(repo_path)?;
|
let repo = utils::repo(repo_path)?;
|
||||||
let branch_as_ref = repo.find_reference(branch_ref)?;
|
let branch_as_ref = repo.find_reference(branch_ref)?;
|
||||||
let mut branch = git2::Branch::wrap(branch_as_ref);
|
let mut branch = git2::Branch::wrap(branch_as_ref);
|
||||||
if !branch.is_head() {
|
if branch.is_head() {
|
||||||
branch.delete()?;
|
|
||||||
} else {
|
|
||||||
return Err(Error::Generic("You cannot be on the branch you want to delete, switch branch, then delete this branch".to_string()));
|
return Err(Error::Generic("You cannot be on the branch you want to delete, switch branch, then delete this branch".to_string()));
|
||||||
}
|
}
|
||||||
|
branch.delete()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ impl CommitMessage {
|
||||||
};
|
};
|
||||||
|
|
||||||
let body: Vec<String> =
|
let body: Vec<String> =
|
||||||
lines.map(|line| line.to_string()).collect();
|
lines.map(std::string::ToString::to_string).collect();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
subject,
|
subject,
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ pub fn extract_cred_from_url(url: &str) -> BasicAuthCredential {
|
||||||
} else {
|
} else {
|
||||||
Some(url.username().to_owned())
|
Some(url.username().to_owned())
|
||||||
},
|
},
|
||||||
url.password().map(|pwd| pwd.to_owned()),
|
url.password().map(std::borrow::ToOwned::to_owned),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
BasicAuthCredential::new(None, None)
|
BasicAuthCredential::new(None, None)
|
||||||
|
|
|
||||||
|
|
@ -225,12 +225,13 @@ fn raw_diff_to_file_diff<'a>(
|
||||||
|
|
||||||
match current_hunk {
|
match current_hunk {
|
||||||
None => current_hunk = Some(hunk_header),
|
None => current_hunk = Some(hunk_header),
|
||||||
Some(h) if h != hunk_header => {
|
Some(h) => {
|
||||||
adder(&h, ¤t_lines);
|
if h != hunk_header {
|
||||||
current_lines.clear();
|
adder(&h, ¤t_lines);
|
||||||
current_hunk = Some(hunk_header)
|
current_lines.clear();
|
||||||
|
current_hunk = Some(hunk_header)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let line_type = match line.origin() {
|
let line_type = match line.origin() {
|
||||||
|
|
|
||||||
|
|
@ -75,13 +75,14 @@ pub fn hooks_post_commit(repo_path: &str) -> Result<HookResult> {
|
||||||
|
|
||||||
fn work_dir_as_string(repo_path: &str) -> Result<String> {
|
fn work_dir_as_string(repo_path: &str) -> Result<String> {
|
||||||
let repo = repo(repo_path)?;
|
let repo = repo(repo_path)?;
|
||||||
work_dir(&repo)?.to_str().map(|s| s.to_string()).ok_or_else(
|
work_dir(&repo)?
|
||||||
|| {
|
.to_str()
|
||||||
|
.map(std::string::ToString::to_string)
|
||||||
|
.ok_or_else(|| {
|
||||||
Error::Generic(
|
Error::Generic(
|
||||||
"workdir contains invalid utf8".to_string(),
|
"workdir contains invalid utf8".to_string(),
|
||||||
)
|
)
|
||||||
},
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hook_runable(path: &str, hook: &str) -> bool {
|
fn hook_runable(path: &str, hook: &str) -> bool {
|
||||||
|
|
|
||||||
|
|
@ -74,10 +74,8 @@ impl AsyncProgress for ProgressNotification {
|
||||||
current,
|
current,
|
||||||
total,
|
total,
|
||||||
} => match stage {
|
} => match stage {
|
||||||
PackBuilderStage::AddingObjects => {
|
PackBuilderStage::AddingObjects
|
||||||
ProgressPercent::new(current, total)
|
| PackBuilderStage::Deltafication => {
|
||||||
}
|
|
||||||
PackBuilderStage::Deltafication => {
|
|
||||||
ProgressPercent::new(current, total)
|
ProgressPercent::new(current, total)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ impl NewFromOldContent {
|
||||||
|
|
||||||
fn finish(mut self, old_lines: &[&str]) -> String {
|
fn finish(mut self, old_lines: &[&str]) -> String {
|
||||||
for line in old_lines.iter().skip(self.old_index) {
|
for line in old_lines.iter().skip(self.old_index) {
|
||||||
self.lines.push(line.to_string());
|
self.lines.push((*line).to_string());
|
||||||
}
|
}
|
||||||
let lines = self.lines.join("\n");
|
let lines = self.lines.join("\n");
|
||||||
if lines.ends_with(NEWLINE) {
|
if lines.ends_with(NEWLINE) {
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ pub fn get_status(
|
||||||
Some(diff) => diff
|
Some(diff) => diff
|
||||||
.new_file()
|
.new_file()
|
||||||
.path()
|
.path()
|
||||||
.and_then(|x| x.to_str())
|
.and_then(Path::to_str)
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::Generic(
|
Error::Generic(
|
||||||
|
|
|
||||||
|
|
@ -161,10 +161,10 @@ pub fn get_config_string(
|
||||||
Err(_) => return Ok(None),
|
Err(_) => return Ok(None),
|
||||||
};
|
};
|
||||||
|
|
||||||
if !entry.has_value() {
|
if entry.has_value() {
|
||||||
Ok(None)
|
Ok(entry.value().map(std::string::ToString::to_string))
|
||||||
} else {
|
} else {
|
||||||
Ok(entry.value().map(|s| s.to_string()))
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,25 +252,21 @@ impl DiffComponent {
|
||||||
|
|
||||||
fn copy_selection(&self) {
|
fn copy_selection(&self) {
|
||||||
if let Some(diff) = &self.diff {
|
if let Some(diff) = &self.diff {
|
||||||
let lines_to_copy: Vec<&str> = diff
|
let lines_to_copy: Vec<&str> =
|
||||||
.hunks
|
diff.hunks
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|hunk| hunk.lines.iter())
|
.flat_map(|hunk| hunk.lines.iter())
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, line)| {
|
.filter_map(|(i, line)| {
|
||||||
if self.selection.contains(i) {
|
if self.selection.contains(i) {
|
||||||
Some(
|
Some(line.content.trim_matches(|c| {
|
||||||
line.content
|
c == '\n' || c == '\r'
|
||||||
.trim_matches(|c| {
|
}))
|
||||||
c == '\n' || c == '\r'
|
} else {
|
||||||
})
|
None
|
||||||
.as_ref(),
|
}
|
||||||
)
|
})
|
||||||
} else {
|
.collect();
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
try_or_popup!(
|
try_or_popup!(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![deny(unused_imports)]
|
#![deny(unused_imports)]
|
||||||
#![deny(unused_must_use)]
|
#![deny(unused_must_use)]
|
||||||
|
#![deny(dead_code)]
|
||||||
|
#![deny(clippy::all)]
|
||||||
#![deny(clippy::cargo)]
|
#![deny(clippy::cargo)]
|
||||||
#![deny(clippy::pedantic)]
|
#![deny(clippy::pedantic)]
|
||||||
#![deny(clippy::perf)]
|
#![deny(clippy::perf)]
|
||||||
|
|
@ -8,6 +10,7 @@
|
||||||
#![deny(clippy::unwrap_used)]
|
#![deny(clippy::unwrap_used)]
|
||||||
#![deny(clippy::panic)]
|
#![deny(clippy::panic)]
|
||||||
#![deny(clippy::match_like_matches_macro)]
|
#![deny(clippy::match_like_matches_macro)]
|
||||||
|
#![deny(clippy::needless_update)]
|
||||||
#![allow(clippy::module_name_repetitions)]
|
#![allow(clippy::module_name_repetitions)]
|
||||||
#![allow(clippy::multiple_crate_versions)]
|
#![allow(clippy::multiple_crate_versions)]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue