- Adding keyword expansion filters
authorAlina <agrigora@cern.ch>
Thu, 5 Dec 2013 09:12:56 +0000 (10:12 +0100)
committerAlina <agrigora@cern.ch>
Thu, 5 Dec 2013 09:14:01 +0000 (10:14 +0100)
- Adding .gitattributes to use the filters

.git_filters/rcs-keywords.clean [new file with mode: 0755]
.git_filters/rcs-keywords.smudge [new file with mode: 0755]
.gitattributes [new file with mode: 0644]

diff --git a/.git_filters/rcs-keywords.clean b/.git_filters/rcs-keywords.clean
new file mode 100755 (executable)
index 0000000..175f972
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -p
+#
+# @brief  Git filter to implement rcs keyword expansion as seen in cvs and svn.
+# @author Martin Turon
+#
+# Copyright (c) 2009-2011 Turon Technologies, Inc.  All rights reserved.
+
+s/\$Id[^\$]*\$/\$Id\$/; 
+s/\$Date[^\$]*\$/\$Date\$/;
+s/\$Author[^\$]*\$/\$Author\$/; 
+s/\$Source[^\$]*\$/\$Source\$/; 
+s/\$File[^\$]*\$/\$File\$/; 
+s/\$Revision[^\$]*\$/\$Revision\$/;
diff --git a/.git_filters/rcs-keywords.smudge b/.git_filters/rcs-keywords.smudge
new file mode 100755 (executable)
index 0000000..e83c166
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+#
+# @brief  Git filter to implement rcs keyword expansion as seen in cvs and svn.
+# @author Martin Turon
+#
+# Usage:
+#    .git_filter/rcs-keywords.smudge file_path < file_contents
+# 
+# To add keyword expansion:
+#    <project>/.gitattributes                    - *.c filter=rcs-keywords
+#    <project>/.git_filters/rcs-keywords.smudge  - copy this file to project
+#    <project>/.git_filters/rcs-keywords.clean   - copy companion to project
+#    ~/.gitconfig                                - add [filter] lines below
+#
+# [filter "rcs-keywords"]
+#      clean  = .git_filters/rcs-keywords.clean
+#      smudge = .git_filters/rcs-keywords.smudge %f
+#
+# Copyright (c) 2009-2011 Turon Technologies, Inc.  All rights reserved.
+
+$path = shift;
+$path =~ /.*\/(.*)/;
+$filename = $1;
+
+if (0 == length($filename)) {
+       $filename = $path;
+}
+
+# Need to grab filename and to use git log for this to be accurate.
+$rev = `git log -- $path | head -n 3`;
+$rev =~ /^Author:\s*(.*)\s*$/m;
+$author = $1;
+$author =~ /\s*(.*)\s*<.*/;
+$name = $1;
+$rev =~ /^Date:\s*(.*)\s*$/m;
+$date = $1;
+$rev =~ /^commit (.*)$/m;
+$ident = $1;
+
+while (<STDIN>) {
+    s/\$Date[^\$]*\$/\$Date:   $date \$/;
+    s/\$Author[^\$]*\$/\$Author: $author \$/;
+    s/\$Id[^\$]*\$/\$Id: $filename | $date | $name \$/;
+    s/\$File[^\$]*\$/\$File:   $filename \$/;
+    s/\$Source[^\$]*\$/\$Source: $path \$/;
+       s/\$Revision[^\$]*\$/\$Revision: $ident \$/;
+} continue {
+    print or die "-p destination: $!\n";
+}
diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..735781d
--- /dev/null
@@ -0,0 +1,2 @@
+*.cxx filter=rcs-keywords
+*.h filter=rcs-keywords
\ No newline at end of file