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

Expose the line number before a diff as %(lineno_old) #1081

Merged
merged 1 commit into from
Feb 11, 2021

Conversation

krobelus
Copy link
Contributor

I use Tig to write review comments on GitLab (hopefully soon GitHub as well).
To comment on specific lines of a diff, the GitLab API requires both the
line number before the diff, and after the diff. Additionally, it needs
the line type (added, deleted / context line). This patch exposes %(lineno_old)
which is the dual to %(linenno). It could also be useful when viewing
"reverse" diffs.

doc/manual.adoc Outdated
@@ -175,6 +175,7 @@ following variables.
"." if undefined.
|%(file) |The currently selected file.
|%(lineno) |The currently selected line number. Defaults to 0.
|%(lineno_old) |The selected line number in the pre-image of a diff. Defaults to 0.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we can't find a better name for lineno_old. Not that easy though...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe lineno_original, that's what Wikipedia's diff page uses.

When browsing a patch that has not yet been applied to the working tree, this line number can be used to go to the exact line under the cursor. Of course this can only work if the cursor is on a (future) deleted, or context line. If the cursor is in a sequence of added lines, this line number will be on the first of the sequence.

I briefly considered making it symmetrical by adding an alias, so we can have something like lineno_before and lineno_after bur that's probably, not worth it.

Copy link
Collaborator

@koutcher koutcher Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So be it for lineno_old, it's not worth the time, you're right.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc/tigrc.5.adoc should be impacted as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"old" seems alright because git-diff uses this terminology - it has options like --output-indicator-old.

pre-image was bogus though. It implies a function / unique mapping, which doesn't make sense here. I think I got that from the message that rerere prints ("Recorded preimage ...").

I've updated the docs and commit message

Popular Git hostings sites like GitHub and GitLab show two columns with line
numbers next to diffs. The left one is the line number in the "old" version
of a file, and the right one is the line number in the "new" file - the file
after the diff was applied.

I use Tig to write review comments on GitLab.  To comment on specific lines
of a diff, the GitLab API requires both old and new line numbers.
Tig's %(lineno) provides the new line number.  This patch additionally
exposes the old line number as %(lineno_old).

When browsing a diff that has not yet been applied to the working tree,
this line number can be used to go to the selected line.  Naturally, this
is only precise for "deleted" and "context" lines, that are present in the
working tree.
@koutcher koutcher merged commit ca4fe62 into jonas:master Feb 11, 2021
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.

2 participants