Skip to content
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

BlameHunk line numbers are zero-based? #1549

Open
mattjohnsonpint opened this issue Mar 15, 2018 · 1 comment
Open

BlameHunk line numbers are zero-based? #1549

mattjohnsonpint opened this issue Mar 15, 2018 · 1 comment

Comments

@mattjohnsonpint
Copy link

var x = 5;  // just an example
var options = new BlameOptions {MinLine = x, MaxLine = x};
var hunks = repository.Blame(path, options);
var hunk = hunks.HunkForLine(x);  // throws ArgumentOutOfRangeException: 'No hunk for that line'

It seems that though the line numbers in BlameOptions are one-based (according to the code comments), BlameHunkCollection.HunkForLine, BlameHunk.ContainsLine, BlameHunk.FinalStartLineNumber and BlameHunk.InitialStartLineNumber are all zero based.

Is this a bug, or intentional? If intentional, it would be good to add to the comments on all of these which base is to be expected. Thanks.

I can subtract one in the HunkForLine call to work around for now.

@ethomson
Copy link
Member

That's unexpected; libgit2 documents this as beginning at 1. I'd be curious to know where this breaks down. https://github.com/libgit2/libgit2/blob/master/include/git2/blame.h#L109

Feels like the HunkForLine method is using an index into an array. That definitely seems strange given that other things here are 1-based.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants