mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-08 19:06:38 +03:00
small events refactor
This commit is contained in:
parent
da76e26d7f
commit
d0a83e97cf
@ -99,7 +99,7 @@ impl App {
|
||||
.unwrap()
|
||||
.get(&project.id)
|
||||
.unwrap()
|
||||
.send(watcher::Event::Reindex)
|
||||
.send(watcher::Event::IndexAll)
|
||||
{
|
||||
log::error!("failed to send session event: {:#}", e);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use crate::{bookmarks, deltas, sessions};
|
||||
pub enum Event {
|
||||
Tick(time::SystemTime),
|
||||
Flush(sessions::Session),
|
||||
SessionFlushed(sessions::Session),
|
||||
Fetch,
|
||||
|
||||
FileChange(path::PathBuf),
|
||||
@ -17,20 +16,20 @@ pub enum Event {
|
||||
|
||||
ProjectFileChange(path::PathBuf),
|
||||
|
||||
Reindex,
|
||||
Session(sessions::Session),
|
||||
SessionFile((String, path::PathBuf, String)),
|
||||
SessionDelta((String, path::PathBuf, deltas::Delta)),
|
||||
Bookmark(bookmarks::Bookmark),
|
||||
File((String, path::PathBuf, String)),
|
||||
Deltas((String, path::PathBuf, Vec<deltas::Delta>)),
|
||||
|
||||
IndexAll,
|
||||
}
|
||||
|
||||
impl Display for Event {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Event::Reindex => write!(f, "Reindex"),
|
||||
Event::IndexAll => write!(f, "IndexAll"),
|
||||
Event::Tick(ts) => write!(f, "Tick({:?})", ts),
|
||||
Event::Flush(session) => write!(f, "Flush({})", session.id),
|
||||
Event::SessionFlushed(session) => write!(f, "SessionFlushed({})", session.id),
|
||||
Event::Fetch => write!(f, "Fetch"),
|
||||
Event::FileChange(_) => write!(f, "FileChange"),
|
||||
Event::GitFileChange(_) => write!(f, "GitFileChange"),
|
||||
@ -40,9 +39,15 @@ impl Display for Event {
|
||||
Event::ProjectFileChange(path) => write!(f, "ProjectFileChange({})", path.display()),
|
||||
Event::Session(session) => write!(f, "Session({})", session.id),
|
||||
Event::Bookmark(_) => write!(f, "Bookmark"),
|
||||
Event::File((sid, path, _)) => write!(f, "File({},{})", sid, path.display()),
|
||||
Event::Deltas((sid, path, deltas)) => {
|
||||
write!(f, "Deltas({},{},{})", sid, path.display(), deltas.len())
|
||||
Event::SessionFile((sid, path, _)) => write!(f, "File({},{})", sid, path.display()),
|
||||
Event::SessionDelta((sid, path, delta)) => {
|
||||
write!(
|
||||
f,
|
||||
"Deltas({},{},{})",
|
||||
sid,
|
||||
path.display(),
|
||||
delta.timestamp_ms
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ pub struct Handler {
|
||||
user_store: users::Storage,
|
||||
}
|
||||
|
||||
impl<'listener> Handler {
|
||||
impl Handler {
|
||||
pub fn new(
|
||||
local_data_dir: path::PathBuf,
|
||||
project_id: String,
|
||||
@ -48,9 +48,6 @@ impl<'listener> Handler {
|
||||
.flush_session(&project_repository::Repository::open(&project)?, session)
|
||||
.context("failed to flush session")?;
|
||||
|
||||
Ok(vec![
|
||||
events::Event::Session(session.clone()),
|
||||
events::Event::SessionFlushed(session),
|
||||
])
|
||||
Ok(vec![events::Event::Session(session)])
|
||||
}
|
||||
}
|
||||
|
@ -150,10 +150,9 @@ impl<'handler> Handler {
|
||||
.flush_session_handler
|
||||
.handle(&session)
|
||||
.context("failed to handle flush session event"),
|
||||
events::Event::SessionFlushed(session) => self.index_handler.index_session(&session),
|
||||
events::Event::Fetch => self.fetch_project_handler.handle(),
|
||||
|
||||
events::Event::File((session_id, file_path, contents)) => {
|
||||
events::Event::SessionFile((session_id, file_path, contents)) => {
|
||||
let file_events = self
|
||||
.index_handler
|
||||
.index_file(&session_id, file_path.to_str().unwrap(), &contents)
|
||||
@ -178,7 +177,8 @@ impl<'handler> Handler {
|
||||
.context("failed to send session event")?;
|
||||
Ok(session_events)
|
||||
}
|
||||
events::Event::Deltas((session_id, path, deltas)) => {
|
||||
events::Event::SessionDelta((session_id, path, delta)) => {
|
||||
let deltas = vec![delta];
|
||||
let delta_events = self
|
||||
.index_handler
|
||||
.index_deltas(&session_id, path.to_str().unwrap(), &deltas)
|
||||
@ -203,7 +203,8 @@ impl<'handler> Handler {
|
||||
.context("failed to send bookmark event")?;
|
||||
Ok(bookmark_events)
|
||||
}
|
||||
events::Event::Reindex => self.index_handler.reindex(),
|
||||
|
||||
events::Event::IndexAll => self.index_handler.reindex(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +171,7 @@ impl Handler {
|
||||
);
|
||||
return Ok(vec![]);
|
||||
}
|
||||
let new_delta = new_delta.as_ref().unwrap();
|
||||
|
||||
let deltas = text_doc.get_deltas();
|
||||
let writer = deltas::Writer::new(&gb_repository);
|
||||
@ -182,13 +183,17 @@ impl Handler {
|
||||
.with_context(|| "failed to write file")?;
|
||||
|
||||
let events = vec![
|
||||
events::Event::File((
|
||||
events::Event::SessionFile((
|
||||
current_session.id.clone(),
|
||||
path.to_path_buf(),
|
||||
latest_file_content.clone(),
|
||||
)),
|
||||
events::Event::Session(current_session.clone()),
|
||||
events::Event::Deltas((current_session.id.clone(), path.to_path_buf(), deltas)),
|
||||
events::Event::SessionDelta((
|
||||
current_session.id.clone(),
|
||||
path.to_path_buf(),
|
||||
new_delta.clone(),
|
||||
)),
|
||||
];
|
||||
|
||||
// read virtual branches
|
||||
@ -253,7 +258,7 @@ impl Handler {
|
||||
};
|
||||
|
||||
let mut new_deltas_by_vbranch: HashMap<String, Vec<deltas::Delta>> = HashMap::new();
|
||||
let mut remaining = new_delta;
|
||||
let mut remaining = Some(new_delta.clone());
|
||||
for vbranch in &virtual_branches {
|
||||
let vb_deltas = if let Some(deltas) = vbranch_deltas.get(&vbranch.id) {
|
||||
deltas
|
||||
|
Loading…
Reference in New Issue
Block a user