diff options
| author | Mel <einebeere@gmail.com> | 2021-09-21 13:46:03 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2021-09-21 13:46:03 +0200 |
| commit | b86138b138565178b916b24d1e30d5786fd9d1c5 (patch) | |
| tree | bf4eedb47909bade2b73a0b6d07ef8c26945525a /src/actions | |
| parent | 9e019b462ff05315641c95442faf7f8fc80f76b1 (diff) | |
| download | ka-b86138b138565178b916b24d1e30d5786fd9d1c5.tar.zst ka-b86138b138565178b916b24d1e30d5786fd9d1c5.zip | |
More consistent naming
Diffstat (limited to 'src/actions')
| -rw-r--r-- | src/actions/shift.rs | 22 | ||||
| -rw-r--r-- | src/actions/update.rs | 18 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/actions/shift.rs b/src/actions/shift.rs index 1bd8864..437fcb4 100644 --- a/src/actions/shift.rs +++ b/src/actions/shift.rs @@ -7,7 +7,7 @@ use std::{ use anyhow::Result; use crate::{ - files::{Locations, RepositoryPaths}, + files::{Locations, FileState}, history::FileHistory, }; @@ -16,8 +16,8 @@ use super::ActionOptions; pub fn shift(command_options: ActionOptions, path: &str, new_cursor: usize) -> Result<()> { let locations = Locations::from(&command_options); - match RepositoryPaths::from_tracked(&locations, Path::new(path))? { - RepositoryPaths::Tracked(tracked) => { + match FileState::from_working(&locations, Path::new(path))? { + FileState::Tracked(tracked) => { let mut history_file = tracked.load_history_file()?; let mut file_history = FileHistory::from_file(&mut history_file)?; @@ -27,30 +27,30 @@ pub fn shift(command_options: ActionOptions, path: &str, new_cursor: usize) -> R fs::remove_file(path)?; } else { let new_content = file_history.get_content(); - let mut tracked_file = tracked.create_tracked_file()?; + let mut working_file = tracked.create_working_file()?; - tracked_file.rewind()?; - tracked_file.set_len(0)?; + working_file.rewind()?; + working_file.set_len(0)?; - tracked_file.write_all(new_content.as_bytes())?; + working_file.write_all(new_content.as_bytes())?; } file_history.write_to_file(&mut history_file)?; } - RepositoryPaths::Deleted(deleted) => { + FileState::Deleted(deleted) => { let mut history_file = deleted.load_history_file()?; let mut file_history = FileHistory::from_file(&mut history_file)?; file_history.set_cursor(new_cursor); if !file_history.file_is_deleted() { - let mut new_tracked_file = deleted.create_tracked_file(&locations)?; + let mut new_working_file = deleted.create_working_file(&locations)?; let new_content = file_history.get_content(); - new_tracked_file.write_all(new_content.as_bytes())?; + new_working_file.write_all(new_content.as_bytes())?; } } - RepositoryPaths::Untracked(_) => panic!("File is not tracked with Ka."), + FileState::Untracked(_) => panic!("File is not tracked with Ka."), } Ok(()) diff --git a/src/actions/update.rs b/src/actions/update.rs index a7d1aad..73a9222 100644 --- a/src/actions/update.rs +++ b/src/actions/update.rs @@ -3,7 +3,7 @@ use std::io::Read; use anyhow::{Context, Result}; use crate::{ - files::{Locations, RepositoryPaths}, + files::{Locations, FileState}, history::{FileChange, FileHistory}, text_diff::TextChange, }; @@ -14,7 +14,7 @@ pub fn update(command_options: ActionOptions) -> Result<()> { let locations = Locations::from(&command_options); let entries = locations - .get_repository_paths() + .get_repository_files() .context("Could not traverse files.")?; for element in entries { @@ -24,9 +24,9 @@ pub fn update(command_options: ActionOptions) -> Result<()> { Ok(()) } -fn update_file(paths: RepositoryPaths, locations: &Locations) -> Result<()> { - let new_state = match paths { - RepositoryPaths::Deleted(deleted) => { +fn update_file(file_state: FileState, locations: &Locations) -> Result<()> { + let new_state = match file_state { + FileState::Deleted(deleted) => { let mut history_file = deleted.load_history_file()?; let file_history = FileHistory::from_file(&mut history_file)?; if !file_history.file_is_deleted() { @@ -37,7 +37,7 @@ fn update_file(paths: RepositoryPaths, locations: &Locations) -> Result<()> { None } } - RepositoryPaths::Untracked(untracked) => { + FileState::Untracked(untracked) => { let mut file = untracked.load_file()?; let mut file_content = String::new(); @@ -53,14 +53,14 @@ fn update_file(paths: RepositoryPaths, locations: &Locations) -> Result<()> { Some((untracked.create_history_file(locations)?, new_history)) } - RepositoryPaths::Tracked(tracked) => { + FileState::Tracked(tracked) => { let mut history_file = tracked.load_history_file()?; - let mut tracked_file = tracked.load_tracked_file()?; + let mut working_file = tracked.load_working_file()?; let file_history = FileHistory::from_file(&mut history_file)?; let mut new_content = String::new(); - tracked_file.read_to_string(&mut new_content)?; + working_file.read_to_string(&mut new_content)?; let old_content = file_history.get_content(); |
