-
Notifications
You must be signed in to change notification settings - Fork 777
jj commands should throw a warning when the fileset does not exist
#7693
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
base: main
Are you sure you want to change the base?
jj commands should throw a warning when the fileset does not exist
#7693
Conversation
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 following commits do not follow our format for subject lines:
Commits should have a subject line following the format <topic>: <description>. Please review the commit guidelines for more information.
jj status should throw an error when the fileset does not existjj status should throw a warning when the fileset does not exist
14e7bbd to
84fb867
Compare
All commits are now correctly formatted. Thank you for your contribution!
84fb867 to
bea6920
Compare
fb17003 to
d6a7b86
Compare
jj status should throw a warning when the fileset does not existjj commands should throw a warning when the fileset does not exist
0eeeaac to
0c2a608
Compare
5e3fd26 to
55ab0d8
Compare
|
IMO, you should merge the revision that changes the command and the revision that adds the test for each command. It would be easier to review. |
I want to make sure that the warning is shown in a consistent manner across all commands. That's why the commands and tests are one after another. I would be happy to split the PR in whatever way is more convenient for the reviewer when ready :)
I didn't have to add tests for all the commands. Some of them already had tests capturing this behaviour, for example, |
|
nit: Could you squash the tests into the commit they're testing? See https://jj-vcs.github.io/jj/latest/contributing/#commit-guidelines |
ccb9689 to
0d8298b
Compare
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!
cli/src/cli_util.rs
Outdated
| // If there are no explicit paths to show then return early. | ||
| if explicit_paths.is_empty() { | ||
| return Ok(()); | ||
| } |
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.
What's the benefit of this check? That should ideally be mentioned in the commit description (if it's not obvious, and it's not obvious to me at least).
Is this just an optimization? But if explicit_paths is empty, then explicit_paths.retain() will be very cheap anyway. So I don't think it's a worthwhile optimization.
Or is it about correctness when explicit_paths is empty and trees is also empty? It makes sense to not print the warning in such cases. Are you going to add callers that may pass an empty list of trees in a later commit? Could you update the commit description to explain that that's the reason if it is?
Actually, if the second thing is what it's about, I would suggest just moving the early return out of the loop. As mentioned above, I don't think it's useful as an optimization anyway. If we move it after the loop, then it will handle the case of an empty list of trees. If you do that, I would suggest actually not making it an early return but instead make the output conditional on the list being non-empty.
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.
It's the latter. Some scenarios when a fileset_expression may evaluate to valid explicit paths but we may not have any trees to compare them against are:
- Squashing a commit into itself.
- Running
jj log -r "none()"
I will add an explanation to the commit message.
ddc8109 to
484bd5f
Compare
| let commit = store.get_commit(&key.0)?; | ||
| let tree = commit.tree()?; | ||
| // TODO: propagate errors | ||
| explicit_paths.retain(|&path| tree.path_value(path).unwrap().is_absent()); |
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.
Hmm, we should also remove paths that are in the parent tree. Otherwise jj log <deleted file> -r <revision where file was deleted> will print the warning. However, it's expensive to calculate the parent tree for merge commits. Perhaps we can remove paths that are in any parent tree instead. That's slightly incorrect because if a file was removed on one of the parent branches of a merge commit then we won't print the warning for the merge commit even though the file wasn't changed or present in the commit. That's probably fine because the point of the warning is to detect typos and such, and if the file did exist at some point, then it's probably not a typo.
It might be good to have tests for these two cases too. To clarify, here's the second case:
$ jj log
D (empty)
|\
C| (empty)
| |
| B delete foo
|/
A add file foo
$ jj log -r D foo
# Since foo isn't present or modified in D, we should ideally print a warning but I don't think we can because it's slow
Btw, jj log is also an exception because the user can do either jj log <fileset> or jj log -r 'files(<fileset>)' (or something more complex). We will only show the warning if the fileset was passed as a positional argument, not if it was part of the revset. Not asking for any changes here, just noting this.
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 think my suggestion is to leave it as is for now. It should be pretty rare to run into it, and the alternatives have their drawbacks too.
484bd5f to
de355eb
Compare
We should not display any warning if `explicit_paths` is empty. Previously, we would by-pass this check if `trees` was empty (which was incorrect behaviour).
We inline `print_unmatched_explicit_paths` when displaying the log as graph for performance reasons.
de355eb to
30fe9ed
Compare
| visit_collapsed_untracked_files( | ||
| snapshot_stats.untracked_paths.keys(), | ||
| tree, | ||
| tree.clone(), |
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.
nit: Is this change necessary? OTOH, perhaps it's better to move print_unmatched_explicit_paths() later? it seems easier to spot the unmatched paths if we print the after the list of matched paths. (Also see my comment about caching on the jj log commit because I think that's also relevant here.)
| let tree = commit.tree()?; | ||
| // TODO: propagate errors | ||
| explicit_paths.retain(|&path| tree.path_value(path).unwrap().is_absent()); |
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.
nit: Could you move these lines after graph.add_node() block? That should be better for caching because diff_renderer is able to read many trees concurrently (if the backend is slow like at Google) but explicit_paths.retain() doesn't process the paths concurrently. So by moving the serial part after the concurrent part, we can take advantage of the trees read by the concurrent code being in the cache so it's fast to read them serially.
| let commit = store.get_commit(&key.0)?; | ||
| let tree = commit.tree()?; | ||
| // TODO: propagate errors | ||
| explicit_paths.retain(|&path| tree.path_value(path).unwrap().is_absent()); |
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 think my suggestion is to leave it as is for now. It should be pretty rare to run into it, and the alternatives have their drawbacks too.
| let _ = work_dir.run_jj(["edit", "right"]); | ||
| work_dir.remove_file("file1"); | ||
| let _ = work_dir.run_jj(["new"]); |
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.
nit: replace let _ = by .success()
| print_unmatched_explicit_paths( | ||
| ui, | ||
| &workspace_command, | ||
| &fileset_expression, | ||
| [&source_commit.tree()?], | ||
| )?; | ||
|
|
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.
nit: maybe better to print the message after later, around line 131?
| .block_on() | ||
| }); | ||
|
|
||
| print_unmatched_explicit_paths(ui, tx.base_workspace_helper(), &fileset_expression, &trees)?; |
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.
nit: maybe better to print this a bit later, after any warning from formatters etc., so between lines 190 and 191?
| print_unmatched_explicit_paths( | ||
| ui, | ||
| &workspace_command, | ||
| &fileset_expression, | ||
| // We check the parent commits to account for deleted files. | ||
| [ | ||
| &from.parent_tree(repo.as_ref())?, | ||
| &from.tree()?, | ||
| &to.parent_tree(repo.as_ref())?, | ||
| &to.tree()?, | ||
| ], | ||
| )?; |
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.
nit: maybe better to print this after the diffs?
|
Thanks again for working on this. We have a release scheduled for Wednesday. I think it's better to get this merged after the release so we get a chance to test it a bit before it's released. I'm not particularly worried about bugs, but I would like to see that there is no significant performance impact (including at Google) and that we feel that we print the warnings at the right time relative to other output so we don't release it on Wednesday and then change the behavior in some way in the very next release. |
Sounds reasonable.
I've ensured the warning about unmatched paths is always displayed first, before any other warning. I've kept this ordering consistent across all the commands. Does this address your concern about the warning placement? |
My guess was actually that it's better to display it quite late (see some of the comments I left). I'm not sure which is better, but the fact that we have different intuition for it seems suggest that we should test it on ourselves before releasing it to users :) |
Closes #6556.
Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)