Open 30350n opened 1 month ago
Going through the sections one-by-one makes it hard to differentiate
I agree that the file mode is treated weirdly and interacts poorly with the rest of the context/data model But rather than extend the logic, as done in this PR, I think we should remove it and simply report a file mode transition (selected Section::FileMode
) to the caller, who can then decide how to handle it:
File::file_mode
.SelectedContents
, and remove any logic that sets SelectedContents::Absent
/SelectedContents::Present
based on the file mode.
FileMode::absent()
when we're done.I feel like the client shouldn't be responsible for manually adding FileMode sections at all. Ideally this part wouldn't be exposed at all, but just be handled by scm-record internally.
There are already some competing designs (such as how to handle partially-committed changes in conjunction with file mode changes), which indicates that scm-record might not be able to establish an authoritative design that works for all callers. Therefore, I think that scm-record should focus on rendering the UI and leave the semantic interpretation to the caller. (In accordance with that, we should also move get_selected_contents
to the helpers
module, as it imposes a semantic interpretation on the UI contents.)
We should just return the file mode transition (if any) directly as a part of SelectedContents
Or we can keep SelectedContents
as it is, and just update get_file_mode
to not check the File::file_mode
, and have the caller continue to handle that separately.
Draft PR to enable the fix for jj #3702 and jj #3846 in jj #4078.
The logic in
get_selected_contents
generally seems really confusing to me and these changes probably don't help mitigating that. From what I can tell, it doesn't break existing tests though, neither in this repo, nor injj
(in combination with jj #4078).The main problems seem to be:
get_selected_contents
Going through the sections one-by-one makes it hard to differentiate betweenAbsent
andUnchanged
SelectedContents
.scm-record
handles (doesn't handle) file mode changes I feel like the client shouldn't be responsible for manually adding FileMode sections at all. Ideally this part wouldn't be exposed at all, but just be handled byscm-record
internally.