summaryrefslogtreecommitdiffstats
path: root/asyncgit/src/sync/patches.rs
diff options
context:
space:
mode:
Diffstat (limited to 'asyncgit/src/sync/patches.rs')
-rw-r--r--asyncgit/src/sync/patches.rs84
1 files changed, 42 insertions, 42 deletions
diff --git a/asyncgit/src/sync/patches.rs b/asyncgit/src/sync/patches.rs
index 8d3db37b..79db2967 100644
--- a/asyncgit/src/sync/patches.rs
+++ b/asyncgit/src/sync/patches.rs
@@ -4,70 +4,70 @@ use git2::{Diff, DiffLine, Patch, Repository};
#[allow(clippy::redundant_pub_crate)]
pub(crate) struct HunkLines<'a> {
- pub hunk: HunkHeader,
- pub lines: Vec<DiffLine<'a>>,
+ pub hunk: HunkHeader,
+ pub lines: Vec<DiffLine<'a>>,
}
#[allow(clippy::redundant_pub_crate)]
pub(crate) fn get_file_diff_patch_and_hunklines<'a>(
- repo: &'a Repository,
- file: &str,
- is_staged: bool,
- reverse: bool,
+ repo: &'a Repository,
+ file: &str,
+ is_staged: bool,
+ reverse: bool,
) -> Result<(Patch<'a>, Vec<HunkLines<'a>>)> {
- let diff = get_diff_raw(repo, file, is_staged, reverse, Some(1))?;
- let patches = get_patches(&diff)?;
- if patches.len() > 1 {
- return Err(Error::Generic(String::from("patch error")));
- }
+ let diff = get_diff_raw(repo, file, is_staged, reverse, Some(1))?;
+ let patches = get_patches(&diff)?;
+ if patches.len() > 1 {
+ return Err(Error::Generic(String::from("patch error")));
+ }
- let patch = patches.into_iter().next().ok_or_else(|| {
- Error::Generic(String::from("no patch found"))
- })?;
+ let patch = patches.into_iter().next().ok_or_else(|| {
+ Error::Generic(String::from("no patch found"))
+ })?;
- let lines = patch_get_hunklines(&patch)?;
+ let lines = patch_get_hunklines(&patch)?;
- Ok((patch, lines))
+ Ok((patch, lines))
}
//
fn patch_get_hunklines<'a>(
- patch: &Patch<'a>,
+ patch: &Patch<'a>,
) -> Result<Vec<HunkLines<'a>>> {
- let count_hunks = patch.num_hunks();
- let mut res = Vec::with_capacity(count_hunks);
- for hunk_idx in 0..count_hunks {
- let (hunk, _) = patch.hunk(hunk_idx)?;
+ let count_hunks = patch.num_hunks();
+ let mut res = Vec::with_capacity(count_hunks);
+ for hunk_idx in 0..count_hunks {
+ let (hunk, _) = patch.hunk(hunk_idx)?;
- let count_lines = patch.num_lines_in_hunk(hunk_idx)?;
+ let count_lines = patch.num_lines_in_hunk(hunk_idx)?;
- let mut hunk = HunkLines {
- hunk: HunkHeader::from(hunk),
- lines: Vec::with_capacity(count_lines),
- };
+ let mut hunk = HunkLines {
+ hunk: HunkHeader::from(hunk),
+ lines: Vec::with_capacity(count_lines),
+ };
- for line_idx in 0..count_lines {
- let line = patch.line_in_hunk(hunk_idx, line_idx)?;
- hunk.lines.push(line);
- }
+ for line_idx in 0..count_lines {
+ let line = patch.line_in_hunk(hunk_idx, line_idx)?;
+ hunk.lines.push(line);
+ }
- res.push(hunk);
- }
+ res.push(hunk);
+ }
- Ok(res)
+ Ok(res)
}
//
fn get_patches<'a>(diff: &Diff<'a>) -> Result<Vec<Patch<'a>>> {
- let count = diff.deltas().len();
+ let count = diff.deltas().len();
- let mut res = Vec::with_capacity(count);
- for idx in 0..count {
- let p = Patch::from_diff(diff, idx)?;
- if let Some(p) = p {
- res.push(p);
- }
- }
+ let mut res = Vec::with_capacity(count);
+ for idx in 0..count {
+ let p = Patch::from_diff(diff, idx)?;
+ if let Some(p) = p {
+ res.push(p);
+ }
+ }
- Ok(res)
+ Ok(res)
}