Permalink
Browse files

Initial version

  • Loading branch information...
0 parents commit 16138bee449499605d0cd680c7a57666314125da @turon committed Apr 12, 2011
Showing with 77 additions and 0 deletions.
  1. +12 −0 .git_filters/rcs-keywords.clean
  2. +44 −0 .git_filters/rcs-keywords.smudge
  3. +10 −0 .gitattributes
  4. +11 −0 .gitconfig
@@ -0,0 +1,12 @@
+#!/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\$/;
@@ -0,0 +1,44 @@
+#!/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;
+
+# 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: $file \$/;
+ s/\$Source[^\$]*\$/\$Source: $path \$/;
+} continue {
+ print or die "-p destination: $!\n";
+}
@@ -0,0 +1,10 @@
+# .gitattributes
+# Map file extensions to git filters
+# $Id$
+
+.gitattributes=rcs-keywords
+*.h filter=rcs-keywords
+*.c filter=rcs-keywords
+*.cc filter=rcs-keywords
+*.m filter=rcs-keywords
+*.mm filter=rcs-keywords
@@ -0,0 +1,11 @@
+
+[alias]
+ co = checkout
+ ci = commit -a
+
+# To add keyword expansion:
+# git init
+# cp ~/.gitconfig, <project>/.gitattributes, and <project>/.git_filters
+[filter "rcs-keywords"]
+ clean = .git_filters/rcs-keywords.clean
+ smudge = .git_filters/rcs-keywords.smudge %f

0 comments on commit 16138be

Please sign in to comment.