-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When editing in the middle of a rebase, dont clear on quit #873
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 6883077488
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! I did an initial pass, and overall everything looks great!
I left some comments on a few things I noticed. I think the only real thing to solve presently is ensuring that the undo/redo logic is handled, otherwise I believe we can get into an inconsistent state by making a change, and undoing that change.
I also ran the CI pipeline, to see what it would flag. You can run almost everything that the CI pipeline runs by using the cargo make dev
command.
src/todo_file/src/state.rs
Outdated
pub enum State { | ||
/// Editing todo at start of a rebase. | ||
Initial, | ||
/// Editing todo in the middle of a rebase with --edit. | ||
Edit, | ||
/// Editing the todo file for git-revise | ||
Revise, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had drafts of a similar enum to track the state of the todofile in the past. 👍🏼
It's been half on my personal list of improvements for a bit, but I never had a great reason to add this.
src/todo_file/src/state.rs
Outdated
return Ok(State::Edit); | ||
} | ||
} | ||
return Ok(State::Initial); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment here, and I believe Clippy will catch this during linting, but you shouldn't need the return
here.
return Ok(State::Initial); | |
Ok(State::Initial) |
src/todo_file/src/lib.rs
Outdated
@@ -231,6 +241,7 @@ impl TodoFile { | |||
}) | |||
.collect(); | |||
self.set_lines(lines?); | |||
self.set_state(detect_state(&self.filepath)?); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more "Rust" way to get the reference here is to use self.filepath.to_path()
. They are technically the same thing. In this case, since get_filepath
exists, perhaps this:
self.set_state(detect_state(&self.filepath)?); | |
self.set_state(detect_state(self.get_filepath())?); |
Random note: It's generally bad practice to call "getters" get_*
in Rust. There existence in this Struct are due to my inexperience when I originally wrote this Struct. This is something that needs to be cleaned up. (Could be a separate PR later, if you are interested.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, i'm also inexperienced with rust, so that's good to know!
src/todo_file/src/lib.rs
Outdated
pub const fn state(&self) -> &State { | ||
&self.state | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since State
is a cheap "Copy", you can instead just return it directly, without the reference.
Essentially, since the State
enum is small in memory, it's just as expensive to create the reference than it is to create a copy of the reference.
pub const fn state(&self) -> &State { | |
&self.state | |
} | |
pub const fn state(&self) -> State { | |
self.state | |
} |
You will also need to update the usages.
src/todo_file/src/state.rs
Outdated
Revise, | ||
} | ||
|
||
pub(crate) fn detect_state(filepath: &Path) -> Result<State, IoError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind moving this function in to src/todo_file/src/utils.rs
?
src/todo_file/src/state.rs
Outdated
#[case::edit(State::Initial)] | ||
#[case::edit(State::Edit)] | ||
#[case::edit(State::Revise)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[case::edit(State::Initial)] | |
#[case::edit(State::Edit)] | |
#[case::edit(State::Revise)] | |
#[case::initial(State::Initial)] | |
#[case::edit(State::Edit)] | |
#[case::revise(State::Revise)] |
src/todo_file/src/lib.rs
Outdated
/// Set the rebase todo file state. | ||
#[inline] | ||
pub fn set_state(&mut self, state: State) { | ||
self.state = state; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will want/need to track this in History
(self.history
), so that undo/redo respects the state change.
The complication here, is that state
is a side effect, so it will need to be handled a little differently than the existing history. 🤔
src/todo_file/src/state.rs
Outdated
if filepath.ends_with("git-revise-todo") { | ||
return Ok(State::Revise); | ||
} | ||
if let Some(parent) = filepath.parent() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want/mean to use NoParentDir
here, if this doesn't exist?
src/todo_file/src/state.rs
Outdated
use rstest::rstest; | ||
|
||
use super::*; | ||
use crate::testutil::{with_todo_revise_file, TodoFileTestDirContext, with_todo_rebase_edit_file, with_todo_rebase_edit_file_stopped}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few formatting issues that can be auto fixed, this line is a good example.
It seems like you are using VSCode, and there is an official plugin for it, that can run format on save.
The other option, is to run cargo make format-apply
, and it will fix any formatting issues.
@@ -0,0 +1 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding .vscode
to the .gitignore
file?
I have an idea here, that can be implemented independently of this PR, and integrated. Let me work on the history, should have something up soonish. |
I've put up #877 that should enable handling history. |
71cf8ac
to
ca7f968
Compare
ca7f968
to
0ab5166
Compare
0ab5166
to
8731df9
Compare
8731df9
to
648597f
Compare
648597f
to
e1d1a4e
Compare
Any chance for update and merge of this? |
Fixes #739
Also, sets up the fix for #685 by detecting when we're using git-revise, still need to finish that up and conditionally add the git-revise commands of
index
andcut
. I might also want to add special behaviour forindex
to automatically move the entry to the end (see mystor/git-revise#16 )Review on the quality of my rust code greatly appreciated!