reduckted / GitWebLinksVS2019

Copy links to files in their online Git repositories from inside Visual Studio 2017 and 2019.
https://marketplace.visualstudio.com/items?itemName=reduckted.GitWebLinks
MIT License
3 stars 4 forks source link

Feature request: Allow getting URLs to the 'blame' version of lines of code #3

Open zlamma opened 6 years ago

zlamma commented 6 years ago

Hi. This is elaborating on my suggestion from the Q&A page, which you have amazingly implemented so quickly šŸ‘.

I know I am being an ungrateful bastard, but I just wanted to leave for your consideration this extra improvement.

Namely, in the original suggestion I was justifying that the reason I would prefer SHAs is because I would like something that will work for as long as possible (so, close to a permalink).

But, for the likes of me, who don't shy away from rewriting my commits to try to achieve the most readable pull request and the most helpful history, using the SHA of last commit is still going to have a problem. That is, when I reorganize the history of my branch, the SHAs will be removed from Github and links will stop working. Same problem will also happen to people who use the coarse-grained history edits during a pull (provided both by GitHub and Bitbucket).

Hence my suggestion was to allow to use the SHA from the 'blame' command of the line of code (or Annotate in VisualStudio's lingo). Effectively, that will provide 'the oldest SHA that had this line', which should guarantee the most stable URL that is available.

Now, I know this might not be something that everyone would want all the time, especially if they are interested in discussing more than one line, each of which can come from a different commit, so perhaps both options could be provided.

I know it might not be trivial to implement this, but perhaps it's not that hard either. Maybe VS's Annotate or commandline's "git blame" already offer the underlying 'meat'?

reduckted commented 6 years ago

I'm not 100% sure I understand what you're after. Would you be able to give me an example of the URL that you would want this to produce?

If we take this file, as an example: https://github.com/reduckted/GitWebLinks/blob/master/source/GitWebLinks/Links/Handlers/GitHubHandler.vb#L10

The extension can create the link to a specific commit: https://github.com/reduckted/GitWebLinks/blob/8764e0f3f3cba872835b43a782e8493a599ae054/source/GitWebLinks/Links/Handlers/GitHubHandler.vb#10 (I've escaped it because GitHub now renders the code instead of the URL šŸ˜®)

Here's the blame URL for the file: https://github.com/reduckted/GitWebLinks/blame/master/source/GitWebLinks/Links/Handlers/GitHubHandler.vb#L10

Are you wanting the blame URL for a specific commit? https://github.com/reduckted/GitWebLinks/blame/8764e0f3f3cba872835b43a782e8493a599ae054/source/GitWebLinks/Links/Handlers/GitHubHandler.vb#L10

zlamma commented 6 years ago

Ah! The confusion is about the blame! Thanks for inquiring!

This is not a request for links to blame-pages, but rather to the same URLs as the original functionality, just using different SHAs. Namely, for right click on line of code, it would be an extra option akin to 'Copy link to this line, at file version where the line was introduced'. For your file, if I used it on this line, it should produce this link, which essentially uses the SHA of the commit 'Used options for the server URLs.', as visible in this blame of that line, (equivalent of command git blame source/GitWebLinks/Links/Handlers/GitHubHandler.vb).

A similar option could be introduced for the whole file, where it would use the SHA of the latest commit that actually modified that file, rather than just any latest commit.

I find such links most useful, because both 'latest commit SHA' and 'branch' often end up getting wiped out from the history (examples in my original comment near 'But, for the likes of me...').

reduckted commented 6 years ago

Ah, OK, I think I understand what you're after now. This would only really work well if you haven't changed the code that you're creating the link to. If you have changed that code, then the SHA would still change when you rewrite the history. Wouldn't that be a problem?

zlamma commented 6 years ago

Yes indeed. They would be just 'the most stable URLs available'. In cases of linking to lines only just added by your own private commit, you would end up surprised. But this is rather just an absent-minded thing to do, not the common use. Currently you end up surprised every time you even have any private commit in your repo.

slawomir-brzezinski-at-interxion commented 6 years ago

After a thought, I feel that getting the SHA of the last commit on the given file would deliver most of the value, so can be considered a first quick win, in that this would no longer be the case:

"@zlamma: Currently you end up surprised every time you even have any private commit in your repo."