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

Commit jumping and line matching fixes #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

nh2
Copy link

@nh2 nh2 commented Jun 30, 2016

This PR fixes a couple of issues that made git-browse unusable for me:

  • Line matching didn't always work correctly
  • Getting stuck on an empty screen when going back too far
  • Not being able to jump to the commit that introduced a line of code (there's anoter PR Ability to jump to the commit under the cursor #3 to address that, but I think j for "jump" might be a more natural key)

nh2 and others added 5 commits June 30, 2016 17:24
When pressing back (`[`) until before the commit that added
the inspected file, the blame contents go blank (makes sense).

When going forward again, until now it was possible that they
stay blank because `highlight_line` could become `-1`, and
once this happened, it would stay `-1` forever.

This commit fixes it by making sure that `max_highlight`
cannot be negative.
Until now, a wrong line mapping would be computed when adding text e.g. to the
end of a line.

This is because in the `git diff --word-diff=porcelain` that was used so far,
such changes appear as a "+" line (which makes sense given that it's a word-
diff), which the code so far interpreted as the addition of a new line when in
fact only words inside the line were changed.

So far, I believe that a correct line mapping cannot be computed using
`--word-diff`, because it inherently ignores whitespace: If you delete
whitespace at the end of the line, and also some following empty lines,
it doesn't even appear in `git diff --word-diff=porcelain`.

This commit uses `diff` instead, which has a feature to tell us the
added, deleted and unchanged lines, from which we can directly
construct the line mapping.
@nh2 nh2 force-pushed the commit-jumping-and-fixes branch from 42e9db8 to 7d834b2 Compare July 5, 2016 19:52
nh2 added 2 commits July 5, 2016 21:54
…fied commit.

This makes `git-browse <rev> <file>` work.
Like all other git invocations, this should separate the revision
from the file name using `--`.
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

Successfully merging this pull request may close these issues.

1 participant