19

I found this question but the referenced options don't say anything about supporting "blame". What I'm looking for is an integrated way to ask "Who edited the line under the cursor last?".

I know most/all SVN clients give this in some form but I'd like something that makes it easy enough that I can do it on a whim: "Humm, who wrote that? [tap tap] Oh him."

Community
  • 1
  • 1
BCS
  • 75,627
  • 68
  • 187
  • 294

5 Answers5

16

The daily builds of AnkhSVN 2.0 have a completely new annotate (blame) implementation inspired by the TFS annotate feature.

AnkhSVN Annotate Preview
(source: qqn.nl)

Not really visible in these screenshots, but it uses the Visual Studio editor for syntax coloring, etc. (You can see the sizeof() in the right bottom of the next image is blue). As you can see in the second picture it also allows several commands on the revision regions in the left bar.

It currently doesn't implement the jump to active line. But you can use the Visual Studio goto line (Ctrl+G) command in it. (You might be able to script this in a macro)

The easiest way to start annotate is right click on the editor ->Subversion->Annotate.

AnkhSVN Annotate Commands
(source: qqn.nl)

[Update 2009-02-03: This feature is now commonly available in the new Stable release]

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Bert Huijben
  • 19,525
  • 4
  • 57
  • 73
  • The thing I don't like about AnkhSVN's blame is that you need to right click on the file in the Solution Explorer instead of being able to do it right from the editor. Maybe the newer builds change this, but until then I'll use Tortoise for blame. – crashmstr Jan 20 '09 at 13:02
  • It is available in the editor context menu in the daily builds. But you can place the command anywhere by using the menu/toolbar customize option from Visual Studio. – Bert Huijben Jan 20 '09 at 15:03
  • 4
    It's nice but doesn't integrate into the editor. Annotate creates a new window that is not editable & search results still end up in the original window & the annotation window doesn't jump to the same line as the edit window when created. Also if the window is closed annotate has to be run again by hand. – danio Jan 22 '10 at 15:26
  • This is very old, but I've found in the latest versions of Ankh (2.7.12815) and VS 2017, the annotate window doesn't line up the commit numbers in the left gutter with the actual code - so it's incredibly difficult to actually use. Also can't show line numbers, which is a huge PITA. Better to switch out and use TortoiseSVNs janky and ugly, but functional blame tool. – EricRRichards Sep 13 '17 at 19:31
8

I wrote a Visual Studio macro to get line number info and pass it to tortoiseproc.exe (which is part of TortoiseSVN)

Take a look at the parameter info: http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html

Here is my macro:


Sub Blame()
  sCurrFileFull = DTE.ActiveDocument.FullName
  Dim activeDoc As Document
  activeDoc = DTE.ActiveDocument
  Dim nLine As Integer
  nLine = activeDoc.Selection.CurrentLine

  sShellCommand = sTorEXE & " /command:blame /startrev:1 /endrev:-1 /path:""" &
                   sCurrFileFull & """ /notempfile /line:" & nLine.ToString()
  Shell(sShellCommand, AppWinStyle.MaximizedFocus, False)
End Sub
crashmstr
  • 28,043
  • 9
  • 61
  • 79
  • 3
    Nice! Here's the rest the steps I needed to take to get this working 1) Open Tools > Macros > Macro IDE 2) Put crashmstr's code in an existing or new module. 3) Defined sTorEXE to point to TortoiseProc.exe, in my case sTorEXE = "C:\\Program Files\\TortoiseSVN\\bin\\TortoiseProc.exe" 4) Had to make sShellCommand all one line (no linebreak like above). If you have any blue underlines in the IDE, fix the error or the macro may silently fail 5) Made it into a button in Visual Studio by right clicking menu bar > Customize > Macros > [Dragged onto menu bar] – Derek Dahmer Nov 30 '09 at 16:54
7

I use a set of external tools wired to TortoiseProc.exe to perform SVN operations like log, diff, blame, revert, commit, update, etc. Then I create toolbar shortcuts to these external tools so that I have all the basic SVN operations accessible within the IDE.

Here are the steps to create a button to do a blame on the current file:

  1. Go to tools -> external tools and click "Add"
  2. Enter whatever title you want (e.g. "Blame")
  3. For the command, enter the following (the path will be different if you installed TortoiseSVN to a different directory): c:\Program Files\TortoiseSVN\bin\TortoiseProc.exe
  4. For the arguments, enter the following: /command:blame /path:"$(ItemPath)" /notempfile
  5. For the initial directory, enter:$(ItemDir)

Now, whenever you have a file open, simply go to tools -> Blame and it should generate the Blame in a popup window. You can also customize the toolbar and create a shortcut for this external tool to make it even easier.

Elliott Beach
  • 10,459
  • 9
  • 28
  • 41
Kevin Pang
  • 41,172
  • 38
  • 121
  • 173
  • Doesn't get the current line bit and that's what I'm really wanting. – BCS Jan 19 '09 at 23:24
  • 2
    @BCS, use these arguments: /command:blame /path:"$(ItemPath)" /notempfile /line:$(CurLine) /startrev:1 /endrev:-1 – Derek Dahmer Nov 30 '09 at 17:01
  • 2
    I found this blog useful: http://tortoisesvn.net/visualstudio.html. Only slight change in VS 2010 is "Add Command" should use "Other Context Menus | Code Window" as opposed to "Other Context Menus | Easy MDI Document Window". – Steve Chambers Aug 06 '13 at 11:03
  • 1
    Derek Dahmer's comment has a typo. The argument should be quoted, as in `/line:"$(CurLine)"`. – Elliott Beach Oct 14 '18 at 16:42
3

In VisualSVN supports blame to some extent - you can right-click on a file and select "Blame". However, it pops up a new window, which may not be as integrated as you want.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • OK. Not near as clean as I'd prefer. (also I, personally, don't want to spend $$) Docs Link? – BCS Jan 19 '09 at 23:06
  • http://visualsvn.com/visualsvn/doc/ but it doesn't mention Blame. I can't say I've ever needed docs for Visual SVN. It just works, basically. – Jon Skeet Jan 19 '09 at 23:10
  • Dude...Visual SVN at $49 is a godsend...How much did Visual Studio Cost? – Restore the Data Dumps Jan 19 '09 at 23:11
  • I don't think you can find better value for money – cgreeno Jan 19 '09 at 23:12
  • @JPunyon $0 ( http://www.microsoft.com/eXPress/download/ ) and using Tortoise isn't that hard. I'm trying to take the cost of getting a blame from low to practically nonexistent – BCS Jan 19 '09 at 23:27
  • @BCS: If you're using Express, add-ons won't work anyway; at least, that was the case with 2005. It's possible it's chnaged with 2008 of course. – Jon Skeet Jan 19 '09 at 23:33
  • I don't think it has. If you are using VS for anything that requires source control, you are likely violating the express license anyway... – GEOCHET Jan 19 '09 at 23:40
  • @Rich B: My homework for English class is in source control, same for all my CS classes. For that mater, all my class work is in source control. – BCS Jan 19 '09 at 23:57
  • @BCS: That is fine, but why use Visual Studio for it? Please tell me you are not using VS to type english homework.... Also, many schools offer low cost VS licenses that might allow addons. You may want to check into this. – GEOCHET Jan 20 '09 at 00:00
  • I might have been a bit obtuse but my point is that things "that requires source control" can be an insanity wide set. IMHO anything that can be done in VS *should* be done under source control. – BCS Jan 20 '09 at 01:57
  • VS.Net 2008 standard only costs $250 (check Amazon). Adding $50 to the cost of a $250 IDE is quite a bit extra if you can get the needed functionality for free. Now if you compare it to team system, that's quite a difference. – Kibbee Jan 20 '09 at 02:10
  • Well you *can* get the added functionality for free with AnkhSVN, which I suspect supports Blame as well, but I can't say for sure as I don't have it. – Jon Skeet Jan 20 '09 at 06:29
1

Here's a working version of crashmstr's and Derek Dahmer's macro code:

Sub Blame()
    Dim sCurrFileFull = DTE.ActiveDocument.FullName
    Dim activeDoc = DTE.ActiveDocument
    Dim nLine = activeDoc.Selection.CurrentLine
    Dim sTorEXE = "TortoiseProc.exe"
    ' Add path if you don't have TortoiseSVN on your PATH
    Dim sShellCommand = sTorEXE & " /command:blame /startrev:1 /endrev:-1 /path:""" & sCurrFileFull & """ /notempfile /line:" & nLine.ToString()
    Shell(sShellCommand, AppWinStyle.MaximizedFocus, False)
End Sub

As per Derek Dahmer's instructions, add it to a new or existing macro module using the Tools > Macros > Macro IDE.

For easy access, I added the macro to my code window context menu:

Customize > Commands > Context menu > Editor Context Menus | Code Window
Add Command > Macros > Find your macro
Modify Selection > Name: Bla&me

Having it in the context menu enables easy keyboard access, but you can, of course, add a keyboard shortcut to it as well. I have it on Ctrl-Shift-M, which is not used by anything useful by default :).

Community
  • 1
  • 1
Bergius
  • 949
  • 6
  • 14