Search code examples
svndocumentationrepositoryjavadoc

Subversion Keyword for Filename


Background

Customer requests that all source files include the following in the header:

File: filename.ext

Problem

As far as I can tell, Subversion offers the following keywords:

  • Id
  • Rev
  • Revision
  • Date
  • LastChangedDate
  • LastChangedRevision
  • Author
  • LastChangedBy
  • HeadURL
  • URL

Of those keywords that contain the filename, they all contain more information than the filename.

Question

Short of writing a script hook, what Subversion keyword contains only the filename and nothing else but the file's name and extension (no path, no URL, no author, no revision, etc.)?

To be clear, if the file was named "MyFile.java", then I'd like to see the following automatically added to the header:

/**
 * File: $File:: MyFile.java$
 * ... other keywords ...
 */

Solution

  • If your SVN is 1.8+, you can define and use custom keywords (see svn help ps). Substitution pattern %b is that you want:

    >svn pl -v data.txt
    Properties on 'data.txt':
      svn:keywords
        File=%b
    

    Content of data.txt in repo, without keyword expansion (hard to get today)

    //$File$
    
    Data
    

    Content of data.txt in Working Copy

    // $File: data.txt $
    
    Data
    

    And full repository tree

    >svn ls -R
    Data/
    Data/Collection/
    Data/Collection/data.txt
    

    HTH