Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ redundant_closure_for_method_calls = "allow"
redundant_pub_crate = "allow"
ref_patterns = "allow"
self_named_module_files = "allow"
semicolon_outside_block = "allow"
single_call_fn = "allow"
std_instead_of_alloc = "allow"
std_instead_of_core = "allow"
Expand Down
32 changes: 26 additions & 6 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ pub(crate) use crate::application::app_data::AppData;
use crate::{
Args,
Exit,
config::{Config, ConfigLoader},
config::{Config, ConfigLoader, DiffIgnoreWhitespaceSetting},
diff::{self, CommitDiffLoader, CommitDiffLoaderOptions},
display::Display,
git::{Repository, open_repository_from_env},
git::open_repository_from_env,
help::build_help,
input::{Event, EventHandler, EventReaderFn, KeyBindings, StandardEvent},
module::{self, ExitStatus, ModuleHandler, State},
Expand Down Expand Up @@ -73,20 +74,35 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
let search_state = search_threads.state();
threads.push(Box::new(search_threads));

let commit_diff_loader_options = CommitDiffLoaderOptions::new()
.context_lines(config.git.diff_context)
.copies(config.git.diff_copies)
.ignore_whitespace(config.diff_ignore_whitespace == DiffIgnoreWhitespaceSetting::All)
.ignore_whitespace_change(config.diff_ignore_whitespace == DiffIgnoreWhitespaceSetting::Change)
.ignore_blank_lines(config.diff_ignore_blank_lines)
.interhunk_context(config.git.diff_interhunk_lines)
.renames(config.git.diff_renames, config.git.diff_rename_limit);
let commit_diff_loader = CommitDiffLoader::new(config_loader.eject_repository(), commit_diff_loader_options);

let diff_update_handler = Self::create_diff_update_handler(input_state.clone());
let diff_thread = diff::thread::Thread::new(commit_diff_loader, diff_update_handler);
let diff_state = diff_thread.state();
threads.push(Box::new(diff_thread));

let keybindings = KeyBindings::new(&config.key_bindings);

let app_data = AppData::new(
config,
State::WindowSizeError,
Arc::clone(&todo_file),
diff_state.clone(),
view_state.clone(),
input_state.clone(),
search_state.clone(),
);

let module_handler = ModuleHandler::new(
EventHandler::new(keybindings),
ModuleProvider::new(Repository::from(config_loader.eject_repository()), &app_data),
);
let module_handler = ModuleHandler::new(EventHandler::new(keybindings), ModuleProvider::new(&app_data));

let process = Process::new(&app_data, initial_display_size, module_handler, thread_statuses.clone());
let process_threads = process::Thread::new(process.clone());
threads.push(Box::new(process_threads));
Expand Down Expand Up @@ -184,6 +200,10 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
fn create_search_update_handler(input_state: crate::input::State) -> impl Fn() + Send + Sync {
move || input_state.push_event(Event::Standard(StandardEvent::SearchUpdate))
}

fn create_diff_update_handler(input_state: crate::input::State) -> impl Fn() + Send + Sync {
move || input_state.push_event(Event::Standard(StandardEvent::DiffUpdate))
}
}

#[cfg(all(unix, test))]
Expand Down
9 changes: 8 additions & 1 deletion src/application/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use std::sync::Arc;

use parking_lot::Mutex;

use crate::{config::Config, input, module, search, todo_file::TodoFile, view};
use crate::{config::Config, diff, input, module, search, todo_file::TodoFile, view};

#[derive(Clone, Debug)]
pub(crate) struct AppData {
config: Arc<Config>,
active_module: Arc<Mutex<module::State>>,
todo_file: Arc<Mutex<TodoFile>>,
diff_state: diff::thread::State,
view_state: view::State,
input_state: input::State,
search_state: search::State,
Expand All @@ -19,6 +20,7 @@ impl AppData {
config: Config,
active_module: module::State,
todo_file: Arc<Mutex<TodoFile>>,
diff_state: diff::thread::State,
view_state: view::State,
input_state: input::State,
search_state: search::State,
Expand All @@ -27,6 +29,7 @@ impl AppData {
config: Arc::new(config),
active_module: Arc::new(Mutex::new(active_module)),
todo_file,
diff_state,
view_state,
input_state,
search_state,
Expand All @@ -45,6 +48,10 @@ impl AppData {
Arc::clone(&self.todo_file)
}

pub(crate) fn diff_state(&self) -> diff::thread::State {
self.diff_state.clone()
}

pub(crate) fn view_state(&self) -> view::State {
self.view_state.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Config {
impl TryFrom<&ConfigLoader> for Config {
type Error = ConfigError;

/// Creates a new Config instance loading the Git Config using [`crate::git::Repository`].
/// Creates a new Config instance loading the Git Config.
///
/// # Errors
///
Expand Down
2 changes: 2 additions & 0 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ mod reference_kind;
mod status;
mod user;

pub(crate) mod thread;

pub(crate) use self::{
commit::Commit,
commit_diff::CommitDiff,
Expand Down
66 changes: 53 additions & 13 deletions src/diff/commit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::UNIX_EPOCH;

use chrono::{DateTime, Local, TimeZone as _};

use crate::{
Expand All @@ -6,7 +8,7 @@ use crate::{
};

/// Represents a commit.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct Commit {
pub(crate) hash: String,
pub(crate) reference: Option<Reference>,
Expand All @@ -19,6 +21,20 @@ pub(crate) struct Commit {
}

impl Commit {
#[must_use]
pub(crate) fn empty() -> Self {
Self {
hash: String::from("0000000000000000000000000000000000000000"),
reference: None,
author: User::new(None, None),
authored_date: None,
message: None,
committer: None,
committed_date: DateTime::from(UNIX_EPOCH),
summary: None,
}
}

/// Get the hash of the commit
#[must_use]
pub(crate) fn hash(&self) -> &str {
Expand Down Expand Up @@ -131,6 +147,34 @@ mod tests {
with_temp_repository,
};

impl Commit {
pub(crate) fn new_with_hash(hash: &str) -> Self {
Self {
hash: String::from(hash),
reference: None,
author: User::new(None, None),
authored_date: None,
message: None,
committer: None,
committed_date: DateTime::from(UNIX_EPOCH),
summary: None,
}
}
}

#[test]
fn empty() {
let commit = Commit::empty();
assert_eq!(commit.hash(), "0000000000000000000000000000000000000000");
assert_none!(commit.reference());
assert_eq!(commit.author(), &User::new(None, None));
assert_none!(commit.authored_date());
assert_none!(commit.message());
assert_none!(commit.committer());
assert_eq!(commit.committed_date().timestamp(), 0);
assert_none!(commit.summary());
}

#[test]
fn hash() {
let commit = CommitBuilder::new("0123456789ABCDEF").build();
Expand Down Expand Up @@ -180,26 +224,25 @@ mod tests {
#[test]
fn new_authored_date_same_committed_date() {
with_temp_repository(|repository| {
let repo = crate::git::Repository::from(repository);
create_commit(&repo, Some(CreateCommitOptions::new().author_time(JAN_2021_EPOCH)));
let commit = repo.find_commit("refs/heads/main").unwrap();
let commit = create_commit(
&repository,
Some(CreateCommitOptions::new().author_time(JAN_2021_EPOCH)),
);
assert_none!(commit.authored_date());
});
}

#[test]
fn new_authored_date_different_than_committed() {
with_temp_repository(|repository| {
let repo = crate::git::Repository::from(repository);
create_commit(
&repo,
let commit = create_commit(
&repository,
Some(
CreateCommitOptions::new()
.commit_time(JAN_2021_EPOCH)
.author_time(JAN_2021_EPOCH + 1),
),
);
let commit = repo.find_commit("refs/heads/main").unwrap();
assert_some_eq!(
commit.authored_date(),
&DateTime::parse_from_rfc3339("2021-01-01T00:00:01Z").unwrap()
Expand All @@ -210,9 +253,7 @@ mod tests {
#[test]
fn new_committer_different_than_author() {
with_temp_repository(|repository| {
let repo = crate::git::Repository::from(repository);
create_commit(&repo, Some(CreateCommitOptions::new().committer("Committer")));
let commit = repo.find_commit("refs/heads/main").unwrap();
let commit = create_commit(&repository, Some(CreateCommitOptions::new().committer("Committer")));
assert_some_eq!(
commit.committer(),
&User::new(Some("Committer"), Some("committer@example.com"))
Expand All @@ -223,8 +264,7 @@ mod tests {
#[test]
fn new_committer_same_as_author() {
with_temp_repository(|repository| {
let repo = crate::git::Repository::from(repository);
let commit = repo.find_commit("refs/heads/main").unwrap();
let commit = create_commit(&repository, None);
assert_none!(commit.committer());
});
}
Expand Down
Loading
Loading