mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58: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),
|
||||
|
||||
#[error("utf8 error:{0}")]
|
||||
Utf8Error(#[from] FromUtf8Error),
|
||||
Utf8Conversion(#[from] FromUtf8Error),
|
||||
|
||||
#[error("TryFromInt error:{0}")]
|
||||
IntError(#[from] TryFromIntError),
|
||||
IntConversion(#[from] TryFromIntError),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,33 @@
|
|||
#![deny(unsafe_code)]
|
||||
#![deny(unused_imports)]
|
||||
#![deny(unused_must_use)]
|
||||
#![deny(dead_code)]
|
||||
#![deny(clippy::all)]
|
||||
#![deny(clippy::cargo)]
|
||||
#![deny(clippy::pedantic)]
|
||||
//TODO:
|
||||
// #![deny(clippy::nursery)]
|
||||
#![deny(clippy::unwrap_used)]
|
||||
#![deny(clippy::panic)]
|
||||
#![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
|
||||
// #![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;
|
||||
mod commit_files;
|
||||
|
|
|
|||
|
|
@ -156,17 +156,16 @@ impl AsyncLog {
|
|||
|
||||
if res_is_err || entries.len() <= 1 {
|
||||
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(())
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ pub fn merge_upstream_commit(
|
|||
|
||||
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 =
|
||||
crate::sync::commit::signature_allow_undefined_name(&repo)?;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ pub fn get_branches_info(
|
|||
.branch_upstream_remote(&reference)
|
||||
.ok()
|
||||
.as_ref()
|
||||
.and_then(|buf| buf.as_str())
|
||||
.and_then(git2::Buf::as_str)
|
||||
.map(String::from);
|
||||
|
||||
let details = if local {
|
||||
|
|
@ -318,11 +318,10 @@ pub fn delete_branch(
|
|||
let repo = utils::repo(repo_path)?;
|
||||
let branch_as_ref = repo.find_reference(branch_ref)?;
|
||||
let mut branch = git2::Branch::wrap(branch_as_ref);
|
||||
if !branch.is_head() {
|
||||
branch.delete()?;
|
||||
} else {
|
||||
if branch.is_head() {
|
||||
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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ impl CommitMessage {
|
|||
};
|
||||
|
||||
let body: Vec<String> =
|
||||
lines.map(|line| line.to_string()).collect();
|
||||
lines.map(std::string::ToString::to_string).collect();
|
||||
|
||||
Self {
|
||||
subject,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ pub fn extract_cred_from_url(url: &str) -> BasicAuthCredential {
|
|||
} else {
|
||||
Some(url.username().to_owned())
|
||||
},
|
||||
url.password().map(|pwd| pwd.to_owned()),
|
||||
url.password().map(std::borrow::ToOwned::to_owned),
|
||||
)
|
||||
} else {
|
||||
BasicAuthCredential::new(None, None)
|
||||
|
|
|
|||
|
|
@ -225,12 +225,13 @@ fn raw_diff_to_file_diff<'a>(
|
|||
|
||||
match current_hunk {
|
||||
None => current_hunk = Some(hunk_header),
|
||||
Some(h) if h != hunk_header => {
|
||||
adder(&h, ¤t_lines);
|
||||
current_lines.clear();
|
||||
current_hunk = Some(hunk_header)
|
||||
Some(h) => {
|
||||
if h != hunk_header {
|
||||
adder(&h, ¤t_lines);
|
||||
current_lines.clear();
|
||||
current_hunk = Some(hunk_header)
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
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> {
|
||||
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(
|
||||
"workdir contains invalid utf8".to_string(),
|
||||
)
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn hook_runable(path: &str, hook: &str) -> bool {
|
||||
|
|
|
|||
|
|
@ -74,10 +74,8 @@ impl AsyncProgress for ProgressNotification {
|
|||
current,
|
||||
total,
|
||||
} => match stage {
|
||||
PackBuilderStage::AddingObjects => {
|
||||
ProgressPercent::new(current, total)
|
||||
}
|
||||
PackBuilderStage::Deltafication => {
|
||||
PackBuilderStage::AddingObjects
|
||||
| PackBuilderStage::Deltafication => {
|
||||
ProgressPercent::new(current, total)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ impl NewFromOldContent {
|
|||
|
||||
fn finish(mut self, old_lines: &[&str]) -> String {
|
||||
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");
|
||||
if lines.ends_with(NEWLINE) {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ pub fn get_status(
|
|||
Some(diff) => diff
|
||||
.new_file()
|
||||
.path()
|
||||
.and_then(|x| x.to_str())
|
||||
.and_then(Path::to_str)
|
||||
.map(String::from)
|
||||
.ok_or_else(|| {
|
||||
Error::Generic(
|
||||
|
|
|
|||
|
|
@ -161,10 +161,10 @@ pub fn get_config_string(
|
|||
Err(_) => return Ok(None),
|
||||
};
|
||||
|
||||
if !entry.has_value() {
|
||||
Ok(None)
|
||||
if entry.has_value() {
|
||||
Ok(entry.value().map(std::string::ToString::to_string))
|
||||
} else {
|
||||
Ok(entry.value().map(|s| s.to_string()))
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -252,25 +252,21 @@ impl DiffComponent {
|
|||
|
||||
fn copy_selection(&self) {
|
||||
if let Some(diff) = &self.diff {
|
||||
let lines_to_copy: Vec<&str> = diff
|
||||
.hunks
|
||||
.iter()
|
||||
.flat_map(|hunk| hunk.lines.iter())
|
||||
.enumerate()
|
||||
.filter_map(|(i, line)| {
|
||||
if self.selection.contains(i) {
|
||||
Some(
|
||||
line.content
|
||||
.trim_matches(|c| {
|
||||
c == '\n' || c == '\r'
|
||||
})
|
||||
.as_ref(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let lines_to_copy: Vec<&str> =
|
||||
diff.hunks
|
||||
.iter()
|
||||
.flat_map(|hunk| hunk.lines.iter())
|
||||
.enumerate()
|
||||
.filter_map(|(i, line)| {
|
||||
if self.selection.contains(i) {
|
||||
Some(line.content.trim_matches(|c| {
|
||||
c == '\n' || c == '\r'
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
try_or_popup!(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#![forbid(unsafe_code)]
|
||||
#![deny(unused_imports)]
|
||||
#![deny(unused_must_use)]
|
||||
#![deny(dead_code)]
|
||||
#![deny(clippy::all)]
|
||||
#![deny(clippy::cargo)]
|
||||
#![deny(clippy::pedantic)]
|
||||
#![deny(clippy::perf)]
|
||||
|
|
@ -8,6 +10,7 @@
|
|||
#![deny(clippy::unwrap_used)]
|
||||
#![deny(clippy::panic)]
|
||||
#![deny(clippy::match_like_matches_macro)]
|
||||
#![deny(clippy::needless_update)]
|
||||
#![allow(clippy::module_name_repetitions)]
|
||||
#![allow(clippy::multiple_crate_versions)]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue