├── .gitattributes ├── hello.c ├── .gitconfig ├── .git_filters ├── rcs-keywords.clean └── rcs-keywords.smudge └── README /.gitattributes: -------------------------------------------------------------------------------- 1 | # .gitattributes 2 | # Map file extensions to git filters 3 | 4 | *.h filter=rcs-keywords 5 | *.c filter=rcs-keywords 6 | *.cc filter=rcs-keywords 7 | *.m filter=rcs-keywords 8 | *.mm filter=rcs-keywords 9 | -------------------------------------------------------------------------------- /hello.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hello.c 3 | * @author @$Author$ 4 | * @date @$Date$ 5 | * @version @$Revision$ 6 | * 7 | * $Id$ 8 | */ 9 | 10 | #include "stdio.h" 11 | 12 | int main(int argc, char *argv[]) 13 | printf("Hello, world!"); 14 | } 15 | -------------------------------------------------------------------------------- /.gitconfig: -------------------------------------------------------------------------------- 1 | 2 | [alias] 3 | co = checkout 4 | ci = commit -a 5 | 6 | # To add keyword expansion: 7 | # git init 8 | # cp ~/.gitconfig, /.gitattributes, and /.git_filters 9 | [filter "rcs-keywords"] 10 | clean = .git_filters/rcs-keywords.clean 11 | smudge = .git_filters/rcs-keywords.smudge %f 12 | -------------------------------------------------------------------------------- /.git_filters/rcs-keywords.clean: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -p 2 | # 3 | # @brief Git filter to implement rcs keyword expansion as seen in cvs and svn. 4 | # @author Martin Turon 5 | # 6 | # Copyright (c) 2009-2011 Turon Technologies, Inc. All rights reserved. 7 | 8 | s/\$Id[^\$]*\$/\$Id\$/; 9 | s/\$Date[^\$]*\$/\$Date\$/; 10 | s/\$Author[^\$]*\$/\$Author\$/; 11 | s/\$Source[^\$]*\$/\$Source\$/; 12 | s/\$File[^\$]*\$/\$File\$/; 13 | s/\$Revision[^\$]*\$/\$Revision\$/; 14 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | This module provides a means to add keyword expansion of the following 3 | standard RCS tags to your git projects: 4 | 5 | $Id$ 6 | $Date$ 7 | $File$ 8 | $Author$ 9 | $Revision$ 10 | $Source$ 11 | 12 | The mechanism used are filters. The smudge filter is run on checkout, and the 13 | clean filter is run on commit. The tags are only expanded on the local disk, 14 | not in the repository itself. 15 | 16 | To start, you need to add the following to ~/.gitconfig: 17 | 18 | [filter "rcs-keywords"] 19 | clean = .git_filters/rcs-keywords.clean 20 | smudge = .git_filters/rcs-keywords.smudge %f 21 | 22 | Then, to add keyword expansion, simply add these files to your project: 23 | /.gitattributes - *.c filter=rcs-keywords 24 | /.git_filters/rcs-keywords.smudge - copy this file to project 25 | /.git_filters/rcs-keywords.clean - copy companion to project 26 | 27 | Note: This feature is known not to work in git 1.6.2.2 and 1.7.3.*, and 28 | verified to work in git 1.7.4.4 and 1.7.4.msysgit.0 29 | -------------------------------------------------------------------------------- /.git_filters/rcs-keywords.smudge: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # @brief Git filter to implement rcs keyword expansion as seen in cvs and svn. 4 | # @author Martin Turon 5 | # 6 | # Usage: 7 | # .git_filter/rcs-keywords.smudge file_path < file_contents 8 | # 9 | # To add keyword expansion: 10 | # /.gitattributes - *.c filter=rcs-keywords 11 | # /.git_filters/rcs-keywords.smudge - copy this file to project 12 | # /.git_filters/rcs-keywords.clean - copy companion to project 13 | # ~/.gitconfig - add [filter] lines below 14 | # 15 | # [filter "rcs-keywords"] 16 | # clean = .git_filters/rcs-keywords.clean 17 | # smudge = .git_filters/rcs-keywords.smudge %f 18 | # 19 | # Copyright (c) 2009-2011 Turon Technologies, Inc. All rights reserved. 20 | 21 | $path = shift; 22 | $path =~ /.*\/(.*)/; 23 | $filename = $1; 24 | 25 | if (0 == length($filename)) { 26 | $filename = $path; 27 | } 28 | 29 | # Need to grab filename and to use git log for this to be accurate. 30 | $rev = `git log -- $path | head -n 3`; 31 | $rev =~ /^Author:\s*(.*)\s*$/m; 32 | $author = $1; 33 | $author =~ /\s*(.*)\s*<.*/; 34 | $name = $1; 35 | $rev =~ /^Date:\s*(.*)\s*$/m; 36 | $date = $1; 37 | $rev =~ /^commit (.*)$/m; 38 | $ident = $1; 39 | 40 | while () { 41 | s/\$Date[^\$]*\$/\$Date: $date \$/; 42 | s/\$Author[^\$]*\$/\$Author: $author \$/; 43 | s/\$Id[^\$]*\$/\$Id: $filename | $date | $name \$/; 44 | s/\$File[^\$]*\$/\$File: $filename \$/; 45 | s/\$Source[^\$]*\$/\$Source: $path \$/; 46 | s/\$Revision[^\$]*\$/\$Revision: $ident \$/; 47 | } continue { 48 | print or die "-p destination: $!\n"; 49 | } 50 | --------------------------------------------------------------------------------