3 # @brief Git filter to implement rcs keyword expansion as seen in cvs and svn.
7 # .git_filter/rcs-keywords.smudge file_path < file_contents
9 # To add keyword expansion:
10 # <project>/.gitattributes - *.c filter=rcs-keywords
11 # <project>/.git_filters/rcs-keywords.smudge - copy this file to project
12 # <project>/.git_filters/rcs-keywords.clean - copy companion to project
13 # ~/.gitconfig - add [filter] lines below
15 # [filter "rcs-keywords"]
16 # clean = .git_filters/rcs-keywords.clean
17 # smudge = .git_filters/rcs-keywords.smudge %f
19 # Copyright (c) 2009-2011 Turon Technologies, Inc. All rights reserved.
25 if (0 == length($filename)) {
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;
33 $author =~ /\s*(.*)\s*<.*/;
35 $rev =~ /^Date:\s*(.*)\s*$/m;
37 $rev =~ /^commit (.*)$/m;
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 \$/;
48 print or die "-p destination: $!\n";