Skip to content

Commit 2960b2f

Browse files
authored
Merge pull request #42 from aganzha/rc-0.20.0
Rc 0.20.0
2 parents 8620b3e + b7fc1e8 commit 2960b2f

File tree

13 files changed

+108
-267
lines changed

13 files changed

+108
-267
lines changed

src/commit_view.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,12 @@ pub fn show_commit_window(
378378
if let Some(diff) = &diff {
379379
let (file_path, hunk_header) = match cursor_position {
380380
CursorPosition::CursorDiff(_) => (None, None),
381-
CursorPosition::CursorFile(_, Some(file_idx)) => {
381+
CursorPosition::CursorFile(_, file_idx) => {
382382
let file = &diff.diff.files[file_idx];
383383
(Some(file.path.clone()), None)
384384
}
385-
CursorPosition::CursorHunk(_, Some(file_idx), Some(hunk_idx))
386-
| CursorPosition::CursorLine(
387-
_,
388-
Some(file_idx),
389-
Some(hunk_idx),
390-
_,
391-
) => {
385+
CursorPosition::CursorHunk(_, file_idx, hunk_idx)
386+
| CursorPosition::CursorLine(_, file_idx, hunk_idx, _) => {
392387
let file = &diff.diff.files[file_idx];
393388
let hunk = &file.hunks[hunk_idx];
394389
(Some(file.path.clone()), Some(hunk.header.clone()))

src/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ pub fn get_current_repo_status(
678678
.expect("Could not send through channel");
679679
}
680680
Err(err) => {
681-
error!("cant get Upstream {:?}", err);
681+
debug!("cant get Upstream {:?}", err);
682682
sender
683683
.send_blocking(crate::Event::Upstream(None))
684684
.expect("Could not send through channel");

src/git/commit.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,13 @@ pub fn partial_apply(
322322

323323
let commit = repo.find_commit(oid)?;
324324
let tree = commit.tree()?;
325-
let mut parent_tree: Option<git2::Tree> = None;
326-
if let Ok(parent) = commit.parent(0) {
327-
let tree = parent.tree()?;
328-
parent_tree.replace(tree);
329-
}
325+
326+
let ob = repo.revparse_single("HEAD^{tree}")?;
327+
let head_tree = repo.find_tree(ob.id())?;
328+
330329
let mut diff_opts = make_diff_options();
331330
let git_diff = repo.diff_tree_to_tree(
332-
parent_tree.as_ref(),
331+
Some(&head_tree),
333332
Some(&tree),
334333
Some(if revert {
335334
diff_opts.reverse(true)
@@ -343,6 +342,10 @@ pub fn partial_apply(
343342
if let Some(hunk_header) = &hunk_header {
344343
if let Some(dh) = odh {
345344
let mut header = Hunk::get_header_from(&dh);
345+
println!(
346+
"-----------------------> MINE: {:?} REAL: {:?}",
347+
hunk_header, header
348+
);
346349
if revert {
347350
header = Hunk::reverse_header(&header);
348351
}

src/git/conflict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::git::{Hunk, LineKind, MARKER_OURS, MARKER_THEIRS, MARKER_VS, MINUS, SPACE};
66
use anyhow::{bail, Context, Result};
77
use git2;
8-
use log::{debug, info};
8+
use log::debug;
99
use similar;
1010
use std::io::prelude::*;
1111
use std::{fs, io, path, str};

src/git/remote.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::git::{branch::BranchData, get_upstream, merge, DeferRefresh};
66
use anyhow::{anyhow, Result};
77
use async_channel::Sender;
88
use git2;
9-
use log::{debug, error, trace};
9+
use log::{debug, trace};
1010
use std::cell::RefCell;
1111
use std::collections::HashMap;
1212
use std::fmt;
@@ -340,7 +340,7 @@ pub fn push(
340340
.expect("Could not send through channel");
341341
}
342342
Err(err) => {
343-
error!("cant get Upstream {:?}", err);
343+
debug!("cant get Upstream {:?}", err);
344344
sender
345345
.send_blocking(crate::Event::Upstream(None))
346346
.expect("Could not send through channel");
@@ -431,7 +431,7 @@ pub fn pull(path: PathBuf, sender: Sender<crate::Event>) -> Result<(), RemoteRes
431431
.expect("Could not send through channel");
432432
}
433433
Err(err) => {
434-
error!("cant get Upstream {:?}", err);
434+
debug!("cant get Upstream {:?}", err);
435435
sender
436436
.send_blocking(crate::Event::Upstream(None))
437437
.expect("Could not send through channel");

src/main.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ pub enum Event {
121121
RepoPopup,
122122
Expand(i32, i32),
123123
Cursor(i32, i32),
124-
CopyToClipboard(i32, i32),
125124
Stage(StageOp),
126125
Commit,
127126
Push,
@@ -556,22 +555,14 @@ fn run_app(app: &Application, initial_path: &Option<PathBuf>) {
556555
info!("Unstaged");
557556
status.update_unstaged(odiff, &txt, &mut ctx);
558557
}
559-
// Event::TrackedFile(file_path, diff) => {
560-
// info!("Unstaged");
561-
// status.update_tracked_file(file_path, diff, &txt, &mut ctx);
562-
// }
563558
Event::Expand(offset, line_no) => {
564-
info!("Expand");
559+
trace!("Expand");
565560
status.expand(&txt, line_no, offset, &mut ctx);
566561
}
567562
Event::Cursor(offset, line_no) => {
568563
trace!("Cursor");
569564
status.cursor(&txt, line_no, offset, &mut ctx);
570565
}
571-
Event::CopyToClipboard(start_offset, end_offset) => {
572-
info!("CopyToClipboard");
573-
status.copy_to_clipboard(&txt, start_offset, end_offset, &mut ctx);
574-
}
575566
Event::Stage(stage_op) => {
576567
info!("Stage {:?}", stage_op);
577568
status.stage_op(stage_op, &application_window, &settings);

src/stashes_view.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ impl OidRow {
160160
move || stash::apply(path, stash.num, None, sender)
161161
})
162162
.await
163-
.unwrap_or_else(|e| {
164-
alert(format!("{:?}", e)).present(Some(&window));
165-
Ok(())
166-
})
163+
.unwrap()
167164
.unwrap_or_else(|e| {
168165
alert(e).present(Some(&window));
169166
});

src/status_view.rs

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ impl Label {
9797
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
9898
pub enum CursorPosition {
9999
CursorDiff(DiffKind),
100-
CursorFile(DiffKind, Option<usize>),
101-
CursorHunk(DiffKind, Option<usize>, Option<usize>),
102-
CursorLine(DiffKind, Option<usize>, Option<usize>, Option<usize>),
100+
CursorFile(DiffKind, usize),
101+
CursorHunk(DiffKind, usize, usize),
102+
CursorLine(DiffKind, usize, usize, usize),
103103
None,
104104
}
105105

@@ -108,20 +108,20 @@ impl CursorPosition {
108108
if let Some((_, index)) = context.selected_line {
109109
return CursorPosition::CursorLine(
110110
context.selected_diff.unwrap().kind,
111-
context.selected_file.map(|(_, i)| i),
112-
context.selected_hunk.map(|(_, i)| i),
113-
Some(index),
111+
context.selected_file.unwrap().1,
112+
context.selected_hunk.unwrap().1,
113+
index,
114114
);
115115
}
116116
if let Some((_, index)) = context.selected_hunk {
117117
return CursorPosition::CursorHunk(
118118
context.selected_diff.unwrap().kind,
119-
context.selected_file.map(|(_, i)| i),
120-
Some(index),
119+
context.selected_file.unwrap().1,
120+
index,
121121
);
122122
}
123123
if let Some((_, index)) = context.selected_file {
124-
return CursorPosition::CursorFile(context.selected_diff.unwrap().kind, Some(index));
124+
return CursorPosition::CursorFile(context.selected_diff.unwrap().kind, index);
125125
}
126126
if let Some(diff) = context.selected_diff {
127127
return CursorPosition::CursorDiff(diff.kind);
@@ -793,12 +793,10 @@ impl Status {
793793
let mut iter = buffer.iter_at_offset(0);
794794

795795
if let Some(head) = &self.head {
796-
debug!("got the head {:?}", iter.line());
797796
head.render(&buffer, &mut iter, context);
798797
}
799798

800799
if let Some(upstream) = &self.upstream {
801-
debug!("got the upstream {:?}", iter.line());
802800
upstream.render(&buffer, &mut iter, context);
803801
}
804802

@@ -812,17 +810,14 @@ impl Status {
812810

813811
if let Some(conflicted) = &self.conflicted {
814812
conflicted.render(&buffer, &mut iter, context);
815-
conflicted.set_diff_tags(&buffer, context);
816813
}
817814

818815
if let Some(unstaged) = &self.unstaged {
819816
unstaged.render(&buffer, &mut iter, context);
820-
unstaged.set_diff_tags(&buffer, context);
821817
}
822818

823819
if let Some(staged) = &self.staged {
824820
staged.render(&buffer, &mut iter, context);
825-
staged.set_diff_tags(&buffer, context);
826821
}
827822

828823
// first place is here
@@ -857,66 +852,6 @@ impl Status {
857852
self.head.as_ref().unwrap().oid
858853
}
859854

860-
pub fn copy_to_clipboard<'a>(
861-
&'a self,
862-
txt: &StageView,
863-
start_offset: i32,
864-
end_offset: i32,
865-
context: &mut StatusRenderContext<'a>,
866-
) {
867-
//2
868-
// in fact the content IS already copied to clipboard
869-
// so, here it need to clean it from status_view artefacts
870-
let buffer = txt.buffer();
871-
let start_iter = buffer.iter_at_offset(start_offset);
872-
let end_iter = buffer.iter_at_offset(end_offset);
873-
let line_from = start_iter.line();
874-
let line_from_offset = start_iter.line_offset();
875-
let line_to = end_iter.line();
876-
let line_to_offset = end_iter.line_offset();
877-
let mut clean_content: HashMap<i32, (String, i32)> = HashMap::new();
878-
for diff in [&self.conflicted, &self.unstaged, &self.staged]
879-
.into_iter()
880-
.flatten()
881-
{
882-
diff.collect_clean_content(line_from, line_to, &mut clean_content, context);
883-
}
884-
if !clean_content.is_empty() {
885-
let clipboard = txt.clipboard();
886-
glib::spawn_future_local({
887-
async move {
888-
let mut new_content = String::new();
889-
let mut replace_content = false;
890-
if let Ok(Some(content)) = clipboard.read_text_future().await {
891-
for (i, line) in content.split("\n").enumerate() {
892-
replace_content = true;
893-
let ind = i as i32 + line_from;
894-
if let Some((clean_line, clean_offset)) = clean_content.get(&ind) {
895-
if ind == line_from && &line_from_offset >= clean_offset {
896-
new_content.push_str(
897-
&clean_line[(line_from_offset - clean_offset) as usize..],
898-
);
899-
} else if ind == line_to && &line_to_offset >= clean_offset {
900-
new_content.push_str(
901-
&clean_line[..(line_to_offset - clean_offset) as usize],
902-
);
903-
} else {
904-
new_content.push_str(clean_line);
905-
}
906-
} else {
907-
new_content.push_str(line);
908-
}
909-
new_content.push('\n');
910-
}
911-
}
912-
if replace_content {
913-
clipboard.set_text(&new_content);
914-
}
915-
}
916-
});
917-
};
918-
}
919-
920855
pub fn debug<'a>(&'a mut self, txt: &StageView, _context: &mut StatusRenderContext<'a>) {
921856
let buffer = txt.buffer();
922857
let pos = buffer.cursor_position();

0 commit comments

Comments
 (0)