-
Notifications
You must be signed in to change notification settings - Fork 456
Cannot override "ui.diff.tool" to use builtin diff in repo config #3327
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
Comments
Makes sense. An alternative would be to allow |
So I think that works, though technically an external tool could start with a |
That's the idea. The config key might also be renamed to
There's an escape syntax: |
Oh, does this mean that one will also be able to do |
Yes, but I think it can be implemented separately. |
'ui.diff-viewer' combines 'ui.diff.tool' and 'ui.diff.format' into a single setting, which in turn allows repository level configuration to override global settings (see jj-vcs#3327).
In this patch, I use the number of adds<->removes alternation as a threshold, which approximates the visual complexity of diff hunks. I don't think user can choose the threshold intuitively, but we need a config knob to try out some. I set `max-inline-alternation = 3` locally. 0 and 1 mean "disable inlining" and "inline adds-only/removes-only lines" respectively. I've added "diff.<format>" config namespace assuming "ui.diff" will be reorganized as "ui.diff-formatter" or something. jj-vcs#3327 Some other metrics I've tried: ``` // Per-line alternation. This also works well, but can't measure complexity of // changes across lines. fn count_max_diff_alternation_per_line(diff_lines: &[DiffLine]) -> usize { diff_lines .iter() .map(|line| { let sides = line.hunks.iter().map(|&(side, _)| side); sides .filter(|&side| side != DiffLineHunkSide::Both) .dedup() // omit e.g. left->both->left .count() }) .max() .unwrap_or(0) } // Per-line occupancy of changes. Large diffs don't always look complex. fn max_diff_token_ratio_per_line(diff_lines: &[DiffLine]) -> f32 { diff_lines .iter() .filter_map(|line| { let [both_len, left_len, right_len] = line.hunks.iter().fold([0, 0, 0], |mut acc, (side, data)| { let index = match side { DiffLineHunkSide::Both => 0, DiffLineHunkSide::Left => 1, DiffLineHunkSide::Right => 2, }; acc[index] += data.len(); acc }); // left/right-only change is readable (left_len != 0 && right_len != 0).then(|| { let diff_len = left_len + right_len; let total_len = both_len + left_len + right_len; (diff_len as f32) / (total_len as f32) }) }) .reduce(f32::max) .unwrap_or(0.0) } // Total occupancy of changes. Large diffs don't always look complex. fn total_change_ratio(diff_lines: &[DiffLine]) -> f32 { let (diff_len, total_len) = diff_lines .iter() .flat_map(|line| &line.hunks) .fold((0, 0), |(diff_len, total_len), (side, data)| { let l = data.len(); match side { DiffLineHunkSide::Both => (diff_len, total_len + l), DiffLineHunkSide::Left => (diff_len + l, total_len + l), DiffLineHunkSide::Right => (diff_len + l, total_len + l), } }); (diff_len as f32) / (total_len as f32) } ```
In this patch, I use the number of adds<->removes alternation as a threshold, which approximates the visual complexity of diff hunks. I don't think user can choose the threshold intuitively, but we need a config knob to try out some. I set `max-inline-alternation = 3` locally. 0 and 1 mean "disable inlining" and "inline adds-only/removes-only lines" respectively. I've added "diff.<format>" config namespace assuming "ui.diff" will be reorganized as "ui.diff-formatter" or something. jj-vcs#3327 Some other metrics I've tried: ``` // Per-line alternation. This also works well, but can't measure complexity of // changes across lines. fn count_max_diff_alternation_per_line(diff_lines: &[DiffLine]) -> usize { diff_lines .iter() .map(|line| { let sides = line.hunks.iter().map(|&(side, _)| side); sides .filter(|&side| side != DiffLineHunkSide::Both) .dedup() // omit e.g. left->both->left .count() }) .max() .unwrap_or(0) } // Per-line occupancy of changes. Large diffs don't always look complex. fn max_diff_token_ratio_per_line(diff_lines: &[DiffLine]) -> f32 { diff_lines .iter() .filter_map(|line| { let [both_len, left_len, right_len] = line.hunks.iter().fold([0, 0, 0], |mut acc, (side, data)| { let index = match side { DiffLineHunkSide::Both => 0, DiffLineHunkSide::Left => 1, DiffLineHunkSide::Right => 2, }; acc[index] += data.len(); acc }); // left/right-only change is readable (left_len != 0 && right_len != 0).then(|| { let diff_len = left_len + right_len; let total_len = both_len + left_len + right_len; (diff_len as f32) / (total_len as f32) }) }) .reduce(f32::max) .unwrap_or(0.0) } // Total occupancy of changes. Large diffs don't always look complex. fn total_change_ratio(diff_lines: &[DiffLine]) -> f32 { let (diff_len, total_len) = diff_lines .iter() .flat_map(|line| &line.hunks) .fold((0, 0), |(diff_len, total_len), (side, data)| { let l = data.len(); match side { DiffLineHunkSide::Both => (diff_len, total_len + l), DiffLineHunkSide::Left => (diff_len + l, total_len + l), DiffLineHunkSide::Right => (diff_len + l, total_len + l), } }); (diff_len as f32) / (total_len as f32) } ```
In this patch, I use the number of adds<->removes alternation as a threshold, which approximates the visual complexity of diff hunks. I don't think user can choose the threshold intuitively, but we need a config knob to try out some. I set `max-inline-alternation = 3` locally. 0 and 1 mean "disable inlining" and "inline adds-only/removes-only lines" respectively. I've added "diff.<format>" config namespace assuming "ui.diff" will be reorganized as "ui.diff-formatter" or something. jj-vcs#3327 Some other metrics I've tried: ``` // Per-line alternation. This also works well, but can't measure complexity of // changes across lines. fn count_max_diff_alternation_per_line(diff_lines: &[DiffLine]) -> usize { diff_lines .iter() .map(|line| { let sides = line.hunks.iter().map(|&(side, _)| side); sides .filter(|&side| side != DiffLineHunkSide::Both) .dedup() // omit e.g. left->both->left .count() }) .max() .unwrap_or(0) } // Per-line occupancy of changes. Large diffs don't always look complex. fn max_diff_token_ratio_per_line(diff_lines: &[DiffLine]) -> f32 { diff_lines .iter() .filter_map(|line| { let [both_len, left_len, right_len] = line.hunks.iter().fold([0, 0, 0], |mut acc, (side, data)| { let index = match side { DiffLineHunkSide::Both => 0, DiffLineHunkSide::Left => 1, DiffLineHunkSide::Right => 2, }; acc[index] += data.len(); acc }); // left/right-only change is readable (left_len != 0 && right_len != 0).then(|| { let diff_len = left_len + right_len; let total_len = both_len + left_len + right_len; (diff_len as f32) / (total_len as f32) }) }) .reduce(f32::max) .unwrap_or(0.0) } // Total occupancy of changes. Large diffs don't always look complex. fn total_change_ratio(diff_lines: &[DiffLine]) -> f32 { let (diff_len, total_len) = diff_lines .iter() .flat_map(|line| &line.hunks) .fold((0, 0), |(diff_len, total_len), (side, data)| { let l = data.len(); match side { DiffLineHunkSide::Both => (diff_len, total_len + l), DiffLineHunkSide::Left => (diff_len + l, total_len + l), DiffLineHunkSide::Right => (diff_len + l, total_len + l), } }); (diff_len as f32) / (total_len as f32) } ```
In this patch, I use the number of adds<->removes alternation as a threshold, which approximates the visual complexity of diff hunks. I don't think user can choose the threshold intuitively, but we need a config knob to try out some. I set `max-inline-alternation = 3` locally. 0 and 1 mean "disable inlining" and "inline adds-only/removes-only lines" respectively. I've added "diff.<format>" config namespace assuming "ui.diff" will be reorganized as "ui.diff-formatter" or something. jj-vcs#3327 Some other metrics I've tried: ``` // Per-line alternation. This also works well, but can't measure complexity of // changes across lines. fn count_max_diff_alternation_per_line(diff_lines: &[DiffLine]) -> usize { diff_lines .iter() .map(|line| { let sides = line.hunks.iter().map(|&(side, _)| side); sides .filter(|&side| side != DiffLineHunkSide::Both) .dedup() // omit e.g. left->both->left .count() }) .max() .unwrap_or(0) } // Per-line occupancy of changes. Large diffs don't always look complex. fn max_diff_token_ratio_per_line(diff_lines: &[DiffLine]) -> f32 { diff_lines .iter() .filter_map(|line| { let [both_len, left_len, right_len] = line.hunks.iter().fold([0, 0, 0], |mut acc, (side, data)| { let index = match side { DiffLineHunkSide::Both => 0, DiffLineHunkSide::Left => 1, DiffLineHunkSide::Right => 2, }; acc[index] += data.len(); acc }); // left/right-only change is readable (left_len != 0 && right_len != 0).then(|| { let diff_len = left_len + right_len; let total_len = both_len + left_len + right_len; (diff_len as f32) / (total_len as f32) }) }) .reduce(f32::max) .unwrap_or(0.0) } // Total occupancy of changes. Large diffs don't always look complex. fn total_change_ratio(diff_lines: &[DiffLine]) -> f32 { let (diff_len, total_len) = diff_lines .iter() .flat_map(|line| &line.hunks) .fold((0, 0), |(diff_len, total_len), (side, data)| { let l = data.len(); match side { DiffLineHunkSide::Both => (diff_len, total_len + l), DiffLineHunkSide::Left => (diff_len + l, total_len + l), DiffLineHunkSide::Right => (diff_len + l, total_len + l), } }); (diff_len as f32) / (total_len as f32) } ```
In this patch, I use the number of adds<->removes alternation as a threshold, which approximates the visual complexity of diff hunks. I don't think user can choose the threshold intuitively, but we need a config knob to try out some. I set `max-inline-alternation = 3` locally. 0 and 1 mean "disable inlining" and "inline adds-only/removes-only lines" respectively. I've added "diff.<format>" config namespace assuming "ui.diff" will be reorganized as "ui.diff-formatter" or something. jj-vcs#3327 Some other metrics I've tried: ``` // Per-line alternation. This also works well, but can't measure complexity of // changes across lines. fn count_max_diff_alternation_per_line(diff_lines: &[DiffLine]) -> usize { diff_lines .iter() .map(|line| { let sides = line.hunks.iter().map(|&(side, _)| side); sides .filter(|&side| side != DiffLineHunkSide::Both) .dedup() // omit e.g. left->both->left .count() }) .max() .unwrap_or(0) } // Per-line occupancy of changes. Large diffs don't always look complex. fn max_diff_token_ratio_per_line(diff_lines: &[DiffLine]) -> f32 { diff_lines .iter() .filter_map(|line| { let [both_len, left_len, right_len] = line.hunks.iter().fold([0, 0, 0], |mut acc, (side, data)| { let index = match side { DiffLineHunkSide::Both => 0, DiffLineHunkSide::Left => 1, DiffLineHunkSide::Right => 2, }; acc[index] += data.len(); acc }); // left/right-only change is readable (left_len != 0 && right_len != 0).then(|| { let diff_len = left_len + right_len; let total_len = both_len + left_len + right_len; (diff_len as f32) / (total_len as f32) }) }) .reduce(f32::max) .unwrap_or(0.0) } // Total occupancy of changes. Large diffs don't always look complex. fn total_change_ratio(diff_lines: &[DiffLine]) -> f32 { let (diff_len, total_len) = diff_lines .iter() .flat_map(|line| &line.hunks) .fold((0, 0), |(diff_len, total_len), (side, data)| { let l = data.len(); match side { DiffLineHunkSide::Both => (diff_len, total_len + l), DiffLineHunkSide::Left => (diff_len + l, total_len + l), DiffLineHunkSide::Right => (diff_len + l, total_len + l), } }); (diff_len as f32) / (total_len as f32) } ```
In this patch, I use the number of adds<->removes alternation as a threshold, which approximates the visual complexity of diff hunks. I don't think user can choose the threshold intuitively, but we need a config knob to try out some. I set `max-inline-alternation = 3` locally. 0 and 1 mean "disable inlining" and "inline adds-only/removes-only lines" respectively. I've added "diff.<format>" config namespace assuming "ui.diff" will be reorganized as "ui.diff-formatter" or something. #3327 Some other metrics I've tried: ``` // Per-line alternation. This also works well, but can't measure complexity of // changes across lines. fn count_max_diff_alternation_per_line(diff_lines: &[DiffLine]) -> usize { diff_lines .iter() .map(|line| { let sides = line.hunks.iter().map(|&(side, _)| side); sides .filter(|&side| side != DiffLineHunkSide::Both) .dedup() // omit e.g. left->both->left .count() }) .max() .unwrap_or(0) } // Per-line occupancy of changes. Large diffs don't always look complex. fn max_diff_token_ratio_per_line(diff_lines: &[DiffLine]) -> f32 { diff_lines .iter() .filter_map(|line| { let [both_len, left_len, right_len] = line.hunks.iter().fold([0, 0, 0], |mut acc, (side, data)| { let index = match side { DiffLineHunkSide::Both => 0, DiffLineHunkSide::Left => 1, DiffLineHunkSide::Right => 2, }; acc[index] += data.len(); acc }); // left/right-only change is readable (left_len != 0 && right_len != 0).then(|| { let diff_len = left_len + right_len; let total_len = both_len + left_len + right_len; (diff_len as f32) / (total_len as f32) }) }) .reduce(f32::max) .unwrap_or(0.0) } // Total occupancy of changes. Large diffs don't always look complex. fn total_change_ratio(diff_lines: &[DiffLine]) -> f32 { let (diff_len, total_len) = diff_lines .iter() .flat_map(|line| &line.hunks) .fold((0, 0), |(diff_len, total_len), (side, data)| { let l = data.len(); match side { DiffLineHunkSide::Both => (diff_len, total_len + l), DiffLineHunkSide::Left => (diff_len + l, total_len + l), DiffLineHunkSide::Right => (diff_len + l, total_len + l), } }); (diff_len as f32) / (total_len as f32) } ```
As of v0.27.0, running Relevant config:
|
Yeah, this issue was more for configuration, since I wanted the default to be |
FYI, the |
Description
I want to use Difftastic for most of my repos, so I have
ui.diff.tool = "difft"
in my user config file, but for a specific repo I want to use the builtin "color-words" diff, since Difftastic doesn't give good diffs for it. However, there seems to be no way to override it to use the builtin word diff on a repo level.Steps to Reproduce the Problem
jj config set --user ui.diff.tool "difft"
jj config set --repo ui.diff.tool ":builtin"
jj diff
with some changesExpected Behavior
I expected it to use the builtin diff from
ui.diff.format
(e.g. color-words).Actual Behavior
I get the following error since it actually tries to run it as a program:
A similar error occurs when set to
"null"
or""
.Specifications
The text was updated successfully, but these errors were encountered: