Skip to content

Commit

Permalink
rf: testing two methods of RCS keyword expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
nschmans committed Feb 6, 2018
1 parent 596647f commit 605c71c
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 11 deletions.
13 changes: 13 additions & 0 deletions .git-rcs-keywords/.git_filters/rcs-keywords.clean
Original file line number Diff line number Diff line change
@@ -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\$/;
49 changes: 49 additions & 0 deletions .git-rcs-keywords/.git_filters/rcs-keywords.smudge
Original file line number Diff line number Diff line change
@@ -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";
}
8 changes: 8 additions & 0 deletions .git-rcs-keywords/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# .gitattributes
# Map file extensions to git filters

*.h filter=rcs-keywords
*.c filter=rcs-keywords
*.cc filter=rcs-keywords
*.m filter=rcs-keywords
*.mm filter=rcs-keywords
11 changes: 11 additions & 0 deletions .git-rcs-keywords/.gitconfig
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions .git-rcs-keywords/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

This module provides a means to add keyword expansion of the following
standard RCS tags to your git projects:

$Id$
$Date$
$File$
$Author$
$Revision$
$Source$

The mechanism used are filters. The smudge filter is run on checkout, and the
clean filter is run on commit. The tags are only expanded on the local disk,
not in the repository itself.

To start, you need to add the following to ~/.gitconfig:

[filter "rcs-keywords"]
clean = .git_filters/rcs-keywords.clean
smudge = .git_filters/rcs-keywords.smudge %f

Then, to add keyword expansion, simply add these files to your project:
<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

Note: This feature is known not to work in git 1.6.2.2 and 1.7.3.*, and
verified to work in git 1.7.4.4 and 1.7.4.msysgit.0
14 changes: 14 additions & 0 deletions .git-rcs-keywords/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file hello.c
* @author @$Author$
* @date @$Date$
* @version @$Revision$
*
* $Id$
*/

#include "stdio.h"

int main(int argc, char *argv[])
printf("Hello, world!");
}
24 changes: 16 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# see man gitattributes

# Map file extensions to git filters
# See .git-keywords directory and .gitconfig

*.h filter=kw
*.hpp filter=kw
*.c filter=kw
*.cpp filter=kw
*.py filter=kw
*.am filter=kw
*.m filter=kw
# See .git-keywords directory for kw filter, and .gitconfig
#*.h filter=kw
#*.hpp filter=kw
#*.c filter=kw
#*.cpp filter=kw
#*.py filter=kw
#*.am filter=kw
#*.m filter=kw

# See .git-rcs-keywords/.git_filters directory for filters, and .gitconfig
*.h filter=rcs-keywords
*.hpp filter=rcs-keywords
*.c filter=rcs-keywords
*.cpp filter=rcs-keywords
*.py filter=rcs-keywords
*.am filter=rcs-keywords
*.m filter=rcs-keywords
12 changes: 9 additions & 3 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# See .git-keywords directory for README
[filter "kw"]
clean = .git-keywords/kwclean
smudge = .git-keywords/kwset
#[filter "kw"]
# clean = .git-keywords/kwclean
# smudge = .git-keywords/kwset

# See .git-rcs-keywords for README
[filter "rcs-keywords"]
clean = .git-rcs-keywords/.git_filters/rcs-keywords.clean
smudge = .git-rcs-keywords/.git_filters/rcs-keywords.smudge %f

3 changes: 3 additions & 0 deletions scripts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ fsgdfPlot.tcl
endif

if SMALL_DIST_INSTALL
tktoolsdir = $(prefix)/tktools
tktools_SCRIPTS= \
tkregister2.tcl
else
tktoolsdir = $(prefix)/tktools
tktools_SCRIPTS= \
Expand Down

0 comments on commit 605c71c

Please sign in to comment.