MGBrown.com Hunk

MGBlog

Thursday, 23 October 2003

Thu, 23 Oct 2003 - 11:21am (GMT+1)
Comments

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: $

Yo, thanks m8.....this is exactly what i'm looking for!!!

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

Glad to be of service.

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

yes! I also need this info and your page help me out. Thanks!

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 "SourceSafe Log"

$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

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

Hi, I tried it in C# code behind files, but after checking all the settings it still does not work, any one to guide please??

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

Hi, I tried it in C# code behind files, but after checking all the settings it still does not work, any one to guide please??

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

When you say it does not work, what is happening and what were you expecting to happen?

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.

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 "*.cs, *.sql" (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.

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

I followed all the above instructions...no dice. I added the Keyword_Masks entry and restarted Visual Studio 2005. Thoughts?

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

Thanks! This is what I was looking for!

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)

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!

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


Clemens,

You could try looking here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/guides/html/vstskexpand_keywords.asp

Add Your Comment

Your Name:
Harry Potter
Your homepage URL (optional):  
http://www.mgbrown.com
Title:*
Comment:*
Copy code into box:
 
* HTML tags not supported