Cookies on MGBrown.com

This web site uses some strictly nesessary cookies to make this web site work.

We would also like to set additional cookies to understand how you use MGBrown.com, remember your settings and improve our services.

Visual SourceSafe Keywords $History: $ and $Log: $

After reading a post about them in Korby Parnell's blog I have been playing around with couple of Visual SourceSafe (VSS) keywords $History: $ and $Log: $. These have the potential for being quite useful in documenting the changes to source code files.

If you haven't come across SourceSafe keywords before, they are little pieces of text you stick in your code. When you check the code in, SourceSafe replaces each keyword with version information. There are a whole load of them, but this post will concentrate on $History: $ and $Log: $.

Before keyword expansion can be used, a SourceSafe administrator has to enable it. This can be done either by using SourceSafe Administrator or by editing the srcsafe.ini.

The $History: $ and $Log: $ keywords give you practically the same information it is just the lay out that is different. An example of each in an XML file is given below.

<!--

$History: $

-->

<!--

$Log: $

-->

Expands to

<!--

$History: Keyword.vbs $
***************** Version 2 *****************
User: Mbrown Date: 14/10/03 Time: 14:36
Updated in $/Build Scripts
Check in comment goes here

***************** Version 1 *****************
User: Mbrown Date: 14/10/03 Time: 14:35
Created in $/Build Scripts
Check in comment goes here

-->

<!--

$Log: /Build Scripts/Keyword.vbs $

2 14/10/03 14:36 Mbrown
Check in comment goes here

1 14/10/03 14:35 Mbrown
Check in comment goes here

-->

As you can see SourceSafe adds an entry for each version giving the Version Number, Date, Time, Author and the Comment entered in the check-in dialog. There is one minor difference between the two: the $History: $ keyword gives the path of the file for each change. This can be useful if the file is shared. Personally I prefer the $History: $ as it looks neater.

I can hear you all saying 'that's fine for languages with block comments but what about languages that don't, like VB?'

There is a solution to this, but it is not obvious from the Visual SourceSafe help files as there is a mistake in them. The normal solution to this problem is to stick a comment character in front of the keyword. This, however, doesn't work for $History: $ and $Log: $ as they add whole new lines to your code. The solution to this is to add a [Keyword Comments] section to the SourceSafe Database's srcsafe.ini file. This file can be found in the root directory of the SourceSafe database.

The [Keword Comments] section allows you to associate a comment string with a file extension. Each extension can have two strings one that SourceSafe places before added lines and one that it places after. These strings are contained in quotes and separated by a comma. For example:

[Keyword Comments]
*.vb = "' "
*.cs = "// "
*.sql = "/* ", " */"
*.xml = ""

Comments

Re: Visual SourceSafe Keywords: $History: $ and $Log: $

After you have used $History: $ and $Log: $ keywords for a while you will probably find your source files end up more History than code. If you are using VisualStudio.Net you can get around this by adding a region around the keyword like this:

#Region &quot;SourceSafe Log&quot;

$Log: /Build Scripts/Keyword.vbs $

2 14/10/03 14:36 Mbrown
Check in comment goes here

1 14/10/03 14:35 Mbrown
Check in comment goes here

#End Region

Comment from Martin G. Brown at Thursday, 13 January 2005 11:25PM (GMT+00)

Re: Visual SourceSafe Keywords $History: $ and $Log: $

What would cause the $Log: $ keyword to not work? I have it in several files that I uploaded to SourceSafe and the checkin comments are not added. I checked carefully to make sure the path information was correct. I even verified the case of the file names. No luck, my files are not updated with checkin comments.

Comment from Bob Thompson at Tuesday, 08 November 2005 07:03PM (GMT+00)

Re: Visual SourceSafe Keywords $History: $ and $Log: $

Before VSS Keywords will work you have to enable them. You do this by specifying the file extensions that you want VSS to modify. You can either use the Source Safe Administrator to do this or you can modify the srcsafe.ini file on the server. NOTE: It is important that you don't add keyword expansion onto binary file types. If you switch it on in an exe file these files will end up corrupted.

In the administrator you will find the setting by selecting Tools/Options from the menu and then looking at the General tab in the resulting dialog. The file extensions need to go in the Â?Expand Keywords in Files of TypeÂ? box. If you wanted to expand keywords in C# and SQL files you would put &quot;*.cs, *.sql&quot; (without the quotes).

To make the change to the srcsafe.ini file simply put a Keyword_Masks entry before the first section header. For example:

Keyword_Masks = *.cs, *.sql

In both cases you need to ensure that everyone has restarted their VSS Clients before the change takes effect.

Comment from Martin G. Brown at Wednesday, 09 November 2005 10:27AM (GMT+00)

Re: Visual SourceSafe Keywords $History: $ and $Log: $

thanks, but I made bad experience in an older visual studio, that coudn't stand any '-' characters inside a xml comment area!
The comments will sometimes contain a '-' character...
Visual Studio could not load the xml file with such
comments!

Does this work in newer Visual Studios?

In VSS 6.0
[Keyword_Comments] did not work - oh, you wrote
[Keyword Comments] - I will try this out.
(Default was a ' * ' at each line start)

Comment from Markus Weber at Wednesday, 15 November 2006 10:58AM (GMT+00)

Re: Visual SourceSafe Keywords $History: $ and $Log: $

Just a dumb question, but where the f**k can I find a list of keywords??? I looked through the help file and googled around a bit and all they tell you is how to enable them. Thanks!

Comment from Clemens at Wednesday, 29 November 2006 08:28PM (GMT+00)

Sorry, this post is no longer accepting comments.