Comments (13)
Interesting... this has never come up before. I think most people just roll with the default three lines of context. I made a change on a sample file on line #7, and this is the output from diff
:
With three (-u
) lines of context the hunk header is: @@ -4,7 +4,7 @@
With two (-U2
) lines of context the hunk header is: @@ -5,5 +5,5 @@
With one (-U1
) lines of context the hunk header is: @@ -6,3 +6,3 @@
With zero (-U0
) lines of context the hunk header is: @@ -7 +7 @@
If you can find for me what those numbers mean I might be able to fix this. diff-so-fancy has no way of knowing how many lines of context diff
generated (or even if diff was used), so we can only "guess" based on the input.
from diff-so-fancy.
The code in question is this line. If we can find a way to calculate the correct number of context lines there instead of defaulting to three this will be easy.
I don't see an easy way to calculate the offset based on the hunk header though.
from diff-so-fancy.
as I understand, those numbers mean:
- line number of the first line that will be displayed in the hunk
- (after comma) total number of lines that are displayed in the hunk
so for -U2
the latter would be 2 + 1 + 2 = 5.
however I can't tell you the right algorithm to find the line number for any -U
setting.
from diff-so-fancy.
oh, maybe just count amount of lines that are prefixed neither with +
nor -
?
from diff-so-fancy.
I'm wondering if it might not be easier to just add a new cli param for d-s-f to specify the number of context lines?
from diff-so-fancy.
I'm wondering if it might not be easier to just add a new cli param for d-s-f to specify the number of context lines?
would be fine for the first iteration, but not as convenient to end user :) User would have to invent some sort of helper command like git diffu
that would do something like
contextLines=$1
shift
git diff -U$contextLines -c dsf.newOpt=$contextLines $@
from diff-so-fancy.
@kambala-decapitator I think I have this working. When I went to write a unit test to capture this new (corrected) output I noticed that three unit tests were failing. Upon closer inspection they were all using -U0
and d-s-f has been reporting the wrong line number the entire time! No one noticed until now.
Can you please test the context-lines branch and see if it works for you?
from diff-so-fancy.
@scottchiefbaker from short test this works correctly now! Thanks!
from diff-so-fancy.
@kambala-decapitator kick around for a week, see if anything crops off. If you give me the green light after a week I'll merge it.
from diff-so-fancy.
I was actively using -U0 today and all line numbers were correct. Same with the default 3 lines.
Will update you in a week.
from diff-so-fancy.
@kambala-decapitator it would be helpful if you could test with some other options for -U
. I'm 99% most people will us 0 or 3, but it would be good to test with other values as well.
I believe d-s-f should work up to 18 now.
from diff-so-fancy.
-U2 shows correct info as well
from diff-so-fancy.
I'm gonna merge this branch in to next
and it will go live when we release the next version.
from diff-so-fancy.
Related Issues (20)
- `report-bug.sh` is broken? May need to be modernized HOT 2
- no background color when play in gitlab ci HOT 3
- Can I use it with vim-fugitive? HOT 3
- How to remove color for the common portions of lines that differ? --> Light vs Dark Mode challenges on macOS HOT 14
- diff-highlight settings break whitespace error color in some cases HOT 1
- Colors in "diff -u | d-s-f" stop working with stripLeadingSymbols = false HOT 1
- When viewing diff in a subdirectory paths aren't relative HOT 2
- git diff output doesn't scroll using touchpad HOT 3
- Newer version of git are omitting the 0 (zero) in ANSI reset which breaks `$strip_leading_indicators` HOT 1
- 1.4.4 not available on NPM? HOT 1
- --patch not working on specific diff HOT 6
- Deleted files cause: "error: mismatched output from interactive.diffFilter" HOT 12
- Make interactive filter respect `less -S` to avoid wrapping lines HOT 2
- How do I change the start path of git log output? HOT 1
- git add --patch shows tabs that are 8 spaces wide HOT 4
- Whitespace deletions on empty lines donβt get highlighted correctly HOT 1
- Broken link in ZSH install instructions HOT 1
- Add awesomebot link checks on README.md
- Only-added/only-removed lines aren't highlighted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from diff-so-fancy.