Skip to content

Commit fa69da8

Browse files
committed
complete refactor conflicted
1 parent 31c822d commit fa69da8

File tree

6 files changed

+20
-223
lines changed

6 files changed

+20
-223
lines changed

src/git.rs

Lines changed: 3 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -813,40 +813,12 @@ pub fn get_current_repo_status(
813813
let sender = sender.clone();
814814
let path = path.clone();
815815
move || {
816-
let repo = Repository::open(path.clone()).expect("can't open repo");
817-
let state = repo.state();
818-
let mut cleanup = Vec::new();
819-
let conflicted = conflict::get_diff(&repo, &mut Some(&mut cleanup))
820-
.ok()
821-
.flatten()
822-
.map(|git_diff| make_diff(&git_diff, DiffKind::Conflicted));
823-
if !cleanup.is_empty() {
824-
// DANGER: modify index while get conflicted!
825-
let mut index = repo.index().expect("cant get index");
826-
for pth in cleanup {
827-
index.remove_path(&pth).expect("cant remove from index");
828-
}
829-
get_untracked(path, sender.clone());
830-
}
831-
debug!("GET REGULAR CONFLICTED {:?}", conflicted.is_some());
832-
sender.send_blocking(crate::Event::Conflicted(
833-
conflicted,
834-
Some(State::new(state, "".to_string())),
835-
))
816+
merge::try_finalize_conflict(path, sender, true).unwrap();
836817
}
837818
});
838819

839-
// get_unstaged
840820
get_unstaged(&repo, sender.clone());
841-
// let git_diff = repo.diff_index_to_workdir(None, Some(&mut make_diff_options()))?;
842-
// let diff = make_diff(&git_diff, DiffKind::Unstaged);
843-
// sender
844-
// .send_blocking(crate::Event::Unstaged(if diff.is_empty() {
845-
// None
846-
// } else {
847-
// Some(diff)
848-
// }))
849-
// .expect("Could not send through channel");
821+
850822
Ok(())
851823
}
852824

@@ -1225,9 +1197,6 @@ pub fn track_changes(
12251197
break;
12261198
}
12271199
}
1228-
// if has_conflicted {
1229-
// assert!(is_tracked);
1230-
// }
12311200
// conflicts could be resolved right in this file change manually
12321201
// but it need to update conflicted anyways if we had them!
12331202
// see else below!
@@ -1237,97 +1206,18 @@ pub fn track_changes(
12371206
if let Some(our) = conflict.our {
12381207
let conflict_path = String::from_utf8(our.path.clone()).unwrap();
12391208
if file_path == conflict_path {
1240-
merge::try_finalize_conflict(path.clone(), sender.clone()).unwrap();
1241-
// // if conflicts are resolved manually
1242-
// // here will be empty diff! aganzha
1243-
// let git_diff = conflict::get_diff(&repo, &mut None).unwrap().unwrap();
1244-
// let event = crate::Event::TrackedFile(
1245-
// file_path.into(),
1246-
// make_diff(&git_diff, DiffKind::Conflicted),
1247-
// );
1248-
// sender
1249-
// .send_blocking(event)
1250-
// .expect("Could not send through channel");
1251-
// return;
1209+
merge::try_finalize_conflict(path.clone(), sender.clone(), false).unwrap();
12521210
}
12531211
}
12541212
}
12551213
}
12561214
if is_tracked {
12571215
get_unstaged(&repo, sender.clone());
1258-
// if has_conflicted {
1259-
// // this means file was in conflicted but now it is fixed manually!
1260-
// // PERHAPS it is no longer in index conflicts.
1261-
// // it must be in staged or unstaged then
1262-
// // get_current_repo_status(Some(path), sender).expect("cant get status");
1263-
// merge::try_finalize_conflict(path, sender).unwrap();
1264-
// return;
1265-
// }
1266-
// let mut opts = make_diff_options();
1267-
// opts.pathspec(&file_path);
1268-
// let git_diff = repo
1269-
// .diff_index_to_workdir(Some(&index), Some(&mut opts))
1270-
// .expect("cant' get diff index to workdir");
1271-
// let diff = make_diff(&git_diff, DiffKind::Unstaged);
1272-
1273-
// if diff.is_empty() {
1274-
// let git_diff = repo
1275-
// .diff_index_to_workdir(None, Some(&mut make_diff_options()))
1276-
// .expect("cant' get diff index to workdir");
1277-
// let diff = make_diff(&git_diff, DiffKind::Unstaged);
1278-
// sender
1279-
// .send_blocking(crate::Event::Unstaged(if diff.is_empty() {
1280-
// None
1281-
// } else {
1282-
// Some(diff)
1283-
// }))
1284-
// .expect("Could not send through channel");
1285-
// } else {
1286-
// sender
1287-
// .send_blocking(crate::Event::TrackedFile(file_path.into(), diff))
1288-
// .expect("Could not send through channel");
1289-
// }
12901216
} else {
12911217
get_untracked(path, sender);
12921218
}
12931219
}
12941220

1295-
// pub fn checkout_oid(
1296-
// path: PathBuf,
1297-
// sender: Sender<crate::Event>,
1298-
// oid: Oid,
1299-
// ref_log_msg: Option<String>,
1300-
// ) {
1301-
// // DANGEROUS! see in status_view!
1302-
// let _updater = DeferRefresh::new(path.clone(), sender.clone(), true, true);
1303-
// let repo = Repository::open(path.clone()).expect("can't open repo");
1304-
// let commit = repo.find_commit(oid).expect("can't find commit");
1305-
// let head_ref = repo.head().expect("can't get head");
1306-
// assert!(head_ref.is_branch());
1307-
// let branch = Branch::wrap(head_ref);
1308-
// let log_message = match ref_log_msg {
1309-
// None => {
1310-
// format!("HEAD -> {}, {}", branch.name().unwrap().unwrap(), oid)
1311-
// }
1312-
// Some(msg) => msg,
1313-
// };
1314-
// let mut builder = CheckoutBuilder::new();
1315-
// let builder = builder.safe().allow_conflicts(true);
1316-
1317-
// sender
1318-
// .send_blocking(crate::Event::LockMonitors(true))
1319-
// .expect("can send through channel");
1320-
// let result = repo.checkout_tree(commit.as_object(), Some(builder));
1321-
1322-
// if result.is_err() {
1323-
// panic!("{:?}", result);
1324-
// }
1325-
// let mut head_ref = repo.head().expect("can't get head");
1326-
// head_ref
1327-
// .set_target(oid, &log_message)
1328-
// .expect("cant set target");
1329-
// }
1330-
13311221
pub fn abort_rebase(path: PathBuf, sender: Sender<crate::Event>) -> Result<(), Error> {
13321222
let _updater = DeferRefresh::new(path.clone(), sender, true, true);
13331223

src/git/merge.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,14 @@ pub fn choose_conflict_side_of_hunk(
325325
return Err(error.into());
326326
}
327327

328-
try_finalize_conflict(path, sender)?;
328+
try_finalize_conflict(path, sender, false)?;
329329
Ok(())
330330
}
331331

332332
pub fn try_finalize_conflict(
333333
path: PathBuf,
334334
sender: Sender<crate::Event>,
335+
call_from_status: bool,
335336
) -> Result<(), git2::Error> {
336337
debug!("cleanup_last_conflict_for_file");
337338
let repo = git2::Repository::open(path.clone())?;
@@ -346,23 +347,24 @@ pub fn try_finalize_conflict(
346347
let mut update_status = true;
347348
let mut cleanup = Vec::new();
348349
let mut index = repo.index()?;
349-
if let Some(git_diff) = conflict::get_diff(&repo, &mut Some(&mut cleanup)).unwrap() {
350-
let diff = make_diff(&git_diff, DiffKind::Conflicted);
351-
debug!("for sure conflicted IS SOME");
352-
sender
353-
.send_blocking(crate::Event::Conflicted(
354-
Some(diff),
355-
Some(State::new(repo.state(), "".to_string())),
356-
))
357-
.expect("Could not send through channel");
358-
update_status = !cleanup.is_empty();
359-
}
350+
let conflicted = conflict::get_diff(&repo, &mut Some(&mut cleanup))
351+
.ok()
352+
.flatten()
353+
.map(|git_diff| make_diff(&git_diff, DiffKind::Conflicted));
354+
sender
355+
.send_blocking(crate::Event::Conflicted(
356+
conflicted,
357+
Some(State::new(repo.state(), "".to_string())),
358+
))
359+
.expect("Could not send through channel");
360+
360361
for path in cleanup {
362+
update_status = true;
361363
index.remove_path(Path::new(&path))?;
362364
index.add_path(Path::new(&path))?;
363365
index.write()?;
364366
}
365-
if update_status {
367+
if update_status && !call_from_status {
366368
gio::spawn_blocking({
367369
move || {
368370
get_current_repo_status(Some(path), sender).expect("cant get status");

src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ pub enum Event {
138138
Conflicted(Option<Diff>, Option<State>),
139139
Unstaged(Option<Diff>),
140140
Untracked(Option<Diff>),
141-
//TrackedFile(PathBuf, Diff),
142141
Staged(Option<Diff>),
143142
Head(Option<Head>),
144143
Upstream(Option<Head>),
@@ -173,7 +172,6 @@ pub enum Event {
173172
StoreSettings(String, String),
174173
OpenEditor,
175174
Tags(Option<Oid>),
176-
//TrackChanges(PathBuf),
177175
CherryPick(Oid, bool, Option<PathBuf>, Option<String>),
178176
Focus,
179177
}

src/status_view.rs

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -624,22 +624,6 @@ impl Status {
624624
}
625625
}
626626

627-
// pub fn track_changes(&self, file_path: PathBuf, sender: Sender<Event>) {
628-
// gio::spawn_blocking({
629-
// let path = self.path.clone().unwrap();
630-
// let sender = sender.clone();
631-
// let mut has_conflicted = false;
632-
// if let Some(diff) = &self.conflicted {
633-
// for file in &diff.files {
634-
// if file.path == file_path {
635-
// has_conflicted = true;
636-
// }
637-
// }
638-
// }
639-
// move || track_changes(path, file_path, has_conflicted, sender)
640-
// });
641-
// }
642-
643627
pub fn update_conflicted<'a>(
644628
&'a mut self,
645629
diff: Option<Diff>,
@@ -822,78 +806,6 @@ impl Status {
822806
}
823807
}
824808

825-
// pub fn update_tracked_file<'a>(
826-
// &'a mut self,
827-
// file_path: PathBuf,
828-
// diff: Diff,
829-
// txt: &StageView,
830-
// context: &mut StatusRenderContext<'a>,
831-
// ) {
832-
// // this method is called only if there is something to
833-
// // update in unstaged/conflicted and they will remain after!
834-
// // if tracked file is returning to original state
835-
// // and it must be removed from unstaged/conflicted and this is
836-
// // ONLY file in unstaged/conflicted, then another event will raise and diff
837-
// // will be removed completelly
838-
// let mine = if diff.kind == DiffKind::Conflicted {
839-
// &mut self.conflicted
840-
// } else {
841-
// &mut self.unstaged
842-
// };
843-
// if let Some(rendered) = mine {
844-
// // so. it need to find file in rendered.
845-
// // if it is there - enrich new one by it and replace
846-
// // if it is not there - insert
847-
// // if it is there and new is empty - erase it
848-
849-
// let updated_file = diff.files.into_iter().find(|f| f.path == file_path);
850-
// let buffer = &txt.buffer();
851-
// let mut ind = 0;
852-
// let mut insert_ind: Option<usize> = None;
853-
// debug!(
854-
// "track 1 file. rendered files are {:}",
855-
// &rendered.files.len()
856-
// );
857-
// rendered.files.retain_mut(|f| {
858-
// ind += 1;
859-
// if f.path == file_path {
860-
// insert_ind = Some(ind);
861-
// if let Some(file) = &updated_file {
862-
// file.enrich_view(f, buffer, context);
863-
// } else {
864-
// debug!("ERASE rendered file!!!!!!!!!");
865-
// f.erase(buffer, context);
866-
// }
867-
// false
868-
// } else {
869-
// true
870-
// }
871-
// });
872-
873-
// if let Some(file) = updated_file {
874-
// if let Some(ind) = insert_ind {
875-
// rendered.files.insert(ind - 1, file);
876-
// } else {
877-
// // insert alphabetically
878-
// let mut ind = 0;
879-
// for rendered_file in &rendered.files {
880-
// if file.path.to_str().unwrap() < rendered_file.path.to_str().unwrap() {
881-
// break;
882-
// }
883-
// ind += 1
884-
// }
885-
// rendered.files.insert(ind, file);
886-
// }
887-
// debug!("just inserted new file...........");
888-
// }
889-
// } else if diff.kind == DiffKind::Conflicted {
890-
// self.conflicted = Some(diff);
891-
// } else {
892-
// self.unstaged = Some(diff);
893-
// }
894-
// self.render(txt, Some(DiffKind::Unstaged), context);
895-
// }
896-
897809
// TODO! is it still used?
898810
pub fn resize_highlights<'a>(
899811
&'a mut self,
@@ -1019,11 +931,6 @@ impl Status {
1019931
}
1020932

1021933
if let Some(conflicted) = &self.conflicted {
1022-
debug!(
1023-
"rrrrrrrrrrrrrrrrrrrrrrrrrender {:?} {:?}",
1024-
conflicted.files.len(),
1025-
diff_kind
1026-
);
1027934
conflicted.render(&buffer, &mut iter, context);
1028935
}
1029936

src/status_view/monitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

5-
use crate::{get_directories, git::track_changes, Event, Status};
5+
use crate::{get_directories, git::track_changes, Status};
66
use core::time::Duration;
77
use gio::{Cancellable, File, FileMonitor, FileMonitorEvent, FileMonitorFlags};
88
use gtk4::prelude::*;

src/status_view/stage_op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl Status {
306306
// conflicts are resolved in branch above
307307
info!("cleanup_last_conflict_for_file");
308308
gio::spawn_blocking({
309-
move || merge::try_finalize_conflict(path, sender)
309+
move || merge::try_finalize_conflict(path, sender, false)
310310
})
311311
.await
312312
.unwrap_or_else(|e| {

0 commit comments

Comments
 (0)