Skip to content
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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

forivall
Copy link

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 and cut. I might also want to add special behaviour for index to automatically move the entry to the end (see mystor/git-revise#16 )

Review on the quality of my rust code greatly appreciated!

@coveralls
Copy link

coveralls commented Jul 20, 2023

Pull Request Test Coverage Report for Build 6883077488

  • 45 of 72 (62.5%) changed or added relevant lines in 14 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.4%) to 93.248%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/todo_file/src/errors/io.rs 0 1 0.0%
src/core/src/modules/list/mod.rs 2 4 50.0%
src/core/src/modules/list/utils.rs 6 8 75.0%
src/view/src/testutil/render_view_line.rs 0 2 0.0%
src/todo_file/src/lib.rs 5 8 62.5%
src/todo_file/src/line.rs 1 4 25.0%
src/todo_file/src/search.rs 0 3 0.0%
src/todo_file/src/state.rs 12 15 80.0%
src/display/src/lib.rs 8 12 66.67%
src/todo_file/src/action.rs 2 6 33.33%
Files with Coverage Reduction New Missed Lines %
src/git/src/repository.rs 1 87.5%
Totals Coverage Status
Change from base Build 6104199216: -0.4%
Covered Lines: 4792
Relevant Lines: 5139

💛 - Coveralls

Copy link
Owner

@MitMaro MitMaro left a 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.

Comment on lines 11 to 18
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,
}
Copy link
Owner

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.

return Ok(State::Edit);
}
}
return Ok(State::Initial);
Copy link
Owner

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.

Suggested change
return Ok(State::Initial);
Ok(State::Initial)

@@ -231,6 +241,7 @@ impl TodoFile {
})
.collect();
self.set_lines(lines?);
self.set_state(detect_state(&self.filepath)?);
Copy link
Owner

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:

Suggested change
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.)

Copy link
Author

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!

Comment on lines 425 to 479
pub const fn state(&self) -> &State {
&self.state
}
Copy link
Owner

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.

Suggested change
pub const fn state(&self) -> &State {
&self.state
}
pub const fn state(&self) -> State {
self.state
}

You will also need to update the usages.

Revise,
}

pub(crate) fn detect_state(filepath: &Path) -> Result<State, IoError> {
Copy link
Owner

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?

Comment on lines 66 to 68
#[case::edit(State::Initial)]
#[case::edit(State::Edit)]
#[case::edit(State::Revise)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[case::edit(State::Initial)]
#[case::edit(State::Edit)]
#[case::edit(State::Revise)]
#[case::initial(State::Initial)]
#[case::edit(State::Edit)]
#[case::revise(State::Revise)]

/// Set the rebase todo file state.
#[inline]
pub fn set_state(&mut self, state: State) {
self.state = state;
Copy link
Owner

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. 🤔

if filepath.ends_with("git-revise-todo") {
return Ok(State::Revise);
}
if let Some(parent) = filepath.parent() {
Copy link
Owner

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?

use rstest::rstest;

use super::*;
use crate::testutil::{with_todo_revise_file, TodoFileTestDirContext, with_todo_rebase_edit_file, with_todo_rebase_edit_file_stopped};
Copy link
Owner

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 @@
/*
Copy link
Owner

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?

@MitMaro
Copy link
Owner

MitMaro commented Jul 21, 2023

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. thinking

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.

@MitMaro
Copy link
Owner

MitMaro commented Jul 21, 2023

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. thinking

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.

@forivall forivall force-pushed the forivall/edit-and-revise branch from 71cf8ac to ca7f968 Compare July 28, 2023 03:37
@forivall forivall force-pushed the forivall/edit-and-revise branch from ca7f968 to 0ab5166 Compare November 15, 2023 21:23
@forivall forivall force-pushed the forivall/edit-and-revise branch from 0ab5166 to 8731df9 Compare March 15, 2024 22:52
@forivall forivall force-pushed the forivall/edit-and-revise branch from 8731df9 to 648597f Compare June 24, 2024 23:44
@forivall forivall force-pushed the forivall/edit-and-revise branch from 648597f to e1d1a4e Compare July 25, 2024 20:13
@rpavlik
Copy link

rpavlik commented Nov 20, 2024

Any chance for update and merge of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git rebase --edit-todo should not empty the file
4 participants