-
Notifications
You must be signed in to change notification settings - Fork 384
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
feat: prioritize paths that need to be processed first during bulk renaming #1801
Conversation
6e36b5c
to
44b830d
Compare
Thanks for the PR! Could you please add tests to the |
Sure! I add a very simple unittest for sort. |
2fa0d6e
to
b8341e2
Compare
Thanks for the change! I added more tests and found that the last two tests are failing. Could you please fix them? Specifically, the second test is producing unstable sorting results. It could be:
or
This might be related to the As for the last test, it hits |
I also had some concerns while writing the code, so thank you for creating tests for that. I have two questions.
So, could I ask you, the author of this project, to clearly define the roles and responsibilities of the sort function? If it doesn't really matter, I'll work on it at my own discretion. |
I haven't fully understood the implementation of
In this case, we have However, we don't need to take responsibility for invalid data; that's the user's responsibility, and the program should only handle valid data, as we already know that
Invalid data remain unchanged and are passed to the upper layer for handling, which in this case is |
So do you mean that we will rename a valid subset of the user's input even if the user's full input set is invalid (duplicate target name or cyclic rename)? For that purpose, the role of sort function is just prioritize some rename that could be executed without any concerns, right? Please let me know if I have misunderstood anything. |
Yes, the sorting function should only elevate those valid renaming items that have no side effects and can be executed early to the front of the execution queue, assisting the user as much as possible (rather than taking over the user's work and responsibilities) in doing all valid operations, while leaving invalid operations for higher-level resolution — here, that means throwing errors to the user for manual intervention. |
One thing I would like to suggest is that the sort function returns a separate rename set containing a cycle. And in the above function, if there is a cycle, how about showing the list to the user on stderr to indicate that the cycle exists and just return (or user interaction to do only valid things or not?). let (valid, cycle) = Self::sort(old, new);
if !cycle.is_empty() {
writeln!(stderr, "cyclic rename detected");
for (old, new) in cycle {
wrintln!(stderr, "{old} -> {new}");
}
return Ok(()); // or user interaction to do or not
} |
Sorry - no. I don't really see the practical significance of "cycle detection" for users, as it's more of an internal implementation detail. The program just needs to ensure that it safely handles the valid data provided by the user, while leaving the invalid data for the user to handle manually. Introducing this detection seems to discard the entire bulk rename operation, rather than just the invalid parts |
I misthought. I thought that if there is a cycle, the rename will be performed and all the files will be messed up, but it will not be performed because it is caught in I make result consistent and just return cyclic rename entries instead of panic. Please check it. Thanks for your comment. |
90bb7c3
to
cb69c74
Compare
contains valid rename and cycle
cb69c74
to
2128293
Compare
ae6c872
to
16881aa
Compare
Thanks! I tested the latest changes, and it seems the ordering issue still exists. For example, this test will fail: #[rustfmt::skip]
cmp(
&[("b", "b_"), ("a", "a_"), ("c", "c_")],
&[("b", "b_"), ("a", "a_"), ("c", "c_")],
); |
I miss reserving user input order. I fix it! |
9ddaba4
to
ef1a31a
Compare
Hey @yw1ee! I did some refactoring to simplify the code, could you please do a final review? If everything looks good I'll merge it 🚀 |
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 have just one simple question. LGTM 👍
Merging now. Thank you so much for contributing this awesome feature @yw1ee, really appreciate it! 🎉 |
…naming (#1801) Co-authored-by: sxyazi <sxyazi@gmail.com>
Resolve #1766 . Sort bulk-renamed files in a similar way to topological sort.