]>
Commit | Line | Data |
---|---|---|
6d4c1523 A |
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 | # <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 | |
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 (<STDIN>) { | |
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 | } |