Giter Club home page Giter Club logo

Comments (13)

scottchiefbaker avatar scottchiefbaker commented on June 9, 2024

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.

scottchiefbaker avatar scottchiefbaker commented on June 9, 2024

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.

kambala-decapitator avatar kambala-decapitator commented on June 9, 2024

as I understand, those numbers mean:

  1. line number of the first line that will be displayed in the hunk
  2. (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.

kambala-decapitator avatar kambala-decapitator commented on June 9, 2024

oh, maybe just count amount of lines that are prefixed neither with + nor -?

from diff-so-fancy.

scottchiefbaker avatar scottchiefbaker commented on June 9, 2024

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.

kambala-decapitator avatar kambala-decapitator commented on June 9, 2024

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.

scottchiefbaker avatar scottchiefbaker commented on June 9, 2024

@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.

kambala-decapitator avatar kambala-decapitator commented on June 9, 2024

@scottchiefbaker from short test this works correctly now! Thanks!

from diff-so-fancy.

scottchiefbaker avatar scottchiefbaker commented on June 9, 2024

@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.

kambala-decapitator avatar kambala-decapitator commented on June 9, 2024

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.

scottchiefbaker avatar scottchiefbaker commented on June 9, 2024

@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.

kambala-decapitator avatar kambala-decapitator commented on June 9, 2024

-U2 shows correct info as well

from diff-so-fancy.

scottchiefbaker avatar scottchiefbaker commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.