-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
evolog: Implement --reversed flag when showing the graph
While this appears functional, I'm considering this a draft change because of how clunky the reversal logic is. Ultimately, all I want is the logic in `ReverseGraphIterator::new` for reversing the DAG, but the `Iterator` impl posed a problem to me. I first convert the list of `Commits` into a `Vec` of `GraphNodes` so that I can use the `ReverseGraphIterator` (RGE) constructor to reverse the DAG. RGE requires each element to be wrapped in a Result, but there didn't seem to be a meaningful error type so I set the error type to `()`. I then added a generic type to the `new` method, so that RGE can tolerate my usage of `()` while still continuing to work elsewhere. This is where I run into a problem. The `Iterator` implementation for RGE hardcodes the Item type to `Result<GraphNode<N>, RevsetEvaluationError>`, but the normal forward iterator has its error type set to `()`. And even if it wasn't set to `()` it would be something other than `RevsetEvaluationError`. This makes the types of the forward and backward iterators mismatched since they return different kinds of Results for each Item. Really, the `Iterator` implementation for RGE doesn't even care what the error type is, so it ought to be able to be "generified". But, I got very stuck trying to reorganize the types without affecting existing code too much. In the interest of getting something working, this change unwraps all the results. This handles the mistmatched error types and unifies the type signature of the iterator regardless of whether we're reversed or not. I don't think this is a super great approach, but I figured I'd get some code in front of maintainers to get some guidance / fix it during review.
- Loading branch information
Showing
3 changed files
with
97 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,3 +370,48 @@ fn test_evolog_reversed_no_graph() { | |
(empty) c | ||
"); | ||
} | ||
|
||
#[test] | ||
fn test_evolog_reverse_with_graph() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "a"]); | ||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "b"]); | ||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "c"]); | ||
test_env.jj_cmd_ok(&repo_path, &["new", "-r", "description(c)", "-m", "d"]); | ||
test_env.jj_cmd_ok(&repo_path, &["new", "-r", "description(c)", "-m", "e"]); | ||
test_env.jj_cmd_ok( | ||
&repo_path, | ||
&[ | ||
"squash", | ||
"--from", | ||
"description(d)|description(e)", | ||
"--to", | ||
"description(c)", | ||
"-m", | ||
"c+d+e", | ||
], | ||
); | ||
let stdout = test_env.jj_cmd_success( | ||
&repo_path, | ||
&["evolog", "-r", "description(c+d+e)", "--reversed"], | ||
); | ||
insta::assert_snapshot!(stdout, @r" | ||
○ qpvuntsm hidden [email protected] 2001-02-03 08:05:07 230dd059 | ||
│ (empty) (no description set) | ||
○ qpvuntsm hidden [email protected] 2001-02-03 08:05:08 d8d5f980 | ||
│ (empty) a | ||
○ qpvuntsm hidden [email protected] 2001-02-03 08:05:09 b4584f54 | ||
│ (empty) b | ||
○ qpvuntsm hidden [email protected] 2001-02-03 08:05:10 5cb22a87 | ||
│ (empty) c | ||
│ ○ mzvwutvl hidden [email protected] 2001-02-03 08:05:11 280cbb6e | ||
├─╯ (empty) d | ||
│ ○ royxmykx hidden [email protected] 2001-02-03 08:05:12 031df638 | ||
├─╯ (empty) e | ||
○ qpvuntsm [email protected] 2001-02-03 08:05:13 a177c2f2 | ||
(empty) c+d+e | ||
"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters