-
Notifications
You must be signed in to change notification settings - Fork 13
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
Move file mode transitions into SelectedContents #92
Conversation
scm-diff-editor/src/lib.rs
Outdated
println!("Would update text file: {}", file_path.display()); | ||
for line in contents.lines() { | ||
println!(" {line}"); | ||
FileState::Present { contents, mode: _ } => { |
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.
In theory I suppose it would be possible to print something about the mode change now, but I've left it out
scm-diff-editor/src/lib.rs
Outdated
if let Some(parent_dir) = file_path.parent() { | ||
filesystem.create_dir_all(parent_dir)?; | ||
}, | ||
FileState::Present { contents, mode: _ } => { |
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 might be missing something as it doesn't look like changes to the file's mode are handled as part of apply_changes
new_description: Some(description), | ||
} => format!("<binary description={description}>\n"), | ||
SelectedContents::Present { contents } => contents.clone(), | ||
FileState::Absent => "<absent>\n".to_string(), |
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.
Diff renders much nicer with whitespace comparisons disabled
0cbc387
to
4281f4d
Compare
jj-vcs/jj#5481 has the corresponding changes in I'm not sure what's best here. I was thinking it would be possible to reproduce the other PR's behaviour of returning Not sure what the best path forwards is here. |
4281f4d
to
be138a3
Compare
be138a3
to
d46caf9
Compare
I'm not sure what I think of the From what I've understood since writing my original two draft PRs, @arxanas basically intended If To make this actually feel good in use then, we'd have to add some hooks to the selection part of
|
The idea was that you'd want to report the selection of a Either way, on the assumption that you do want the
Perhaps, although you presumably still need some way to signal whether the section for the file mode change was selected or not, particularly for cases where the mode change can be selected independently of contents changes (e.g. exec bit flips).
I definitely like the approach discussed here, especially because the resulting logic in |
I think we should simply also always call scm-record/scm-record/src/types.rs Lines 241 to 244 in c23e319
for each file in I guess to expand on what I mentioned earlier:
... and seemingly also doesn't handle any selected I think we should a) remove For completness sake:
Yes, exactly, I think (though not 100% sure) that's what |
@30350n Got you, thanks for the explanation. The only advantage I can see to maintaining the approach I've taken here is that it's harder to forget to call to handle the file mode changes. For example, while fixing up call sites that handled In a draft of the changes I've got going, the return value of #[derive(Debug)]
pub struct SelectedElements<'a> {
/// A potential change to the file's mode.
pub mode_transition: Option<FileModeTransition>,
/// The file's contents.
pub contents: SelectedContents<'a>,
} Thus if nothing was selected at all for a file, we return If only a mode transition was performed, we return: SelectedElements {
mode_transition: Some(transition),
contents: SelectedContents::Unchanged,
} If a mode transition (e.g. exec bit flip) was performed in combination with a contents change, we return: SelectedElements {
mode_transition: Some(transition),
contents: SelectedContents::Text { ... },
} Once I've got the corresponding |
Closing this in lieu of #93 |
Based on #62 (comment) as an attempt to solve the same issue.
@arxanas - wanted to get this up sooner rather than later to get feedback on whether it looks like I'm going in the same direction you were thinking here. I intentionally have not put a lot of thought, yet, into naming, docs, etc.
The main changes are:
File::file_mode
SelectedChanges
(currently calledFileState
which feels like a terrible name) to capture whether the file in question is absent or present. If it is present, we have the existingSelectedChanges
plus an extra field which records a possible (Optional
) file mode transition, along with the existingSelectedChanges
.set_mode_change
to this struct and use it depending on the selected state of anySection::FileMode
sections. We also needget_mode_change
to ensure that the transition is preserved forSection::Binary