Skip to content

Commit aa28d76

Browse files
committed
[TASK] Added config and scripts for keywords
1 parent dc374ca commit aa28d76

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

.git_filters/rcs-keywords.clean

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/perl
2+
3+
# commun sub program to generate keyword content
4+
sub generate_keyword {
5+
# pattern as in the raw source file
6+
$pattern = $_[0];
7+
8+
# extract pattern start
9+
$start = substr($pattern,0,2);
10+
if ($start eq "::") {
11+
# if it start with "::", the pattern length must be preserved
12+
return "::" . (' ' x (length($pattern) - 2));
13+
} else {
14+
# return default content without length concern
15+
return "";
16+
}
17+
}
18+
19+
# main processing loop
20+
21+
while (<STDIN>) {
22+
# replace keyword "Date"
23+
s/\$([Dd][Aa][Tt][Ee])([^\$]*)\$/"\$" . $1 . generate_keyword($2) . "\$"/eg;
24+
25+
# replace keyword "Author"
26+
s/\$([Aa][Uu][Tt][Hh][Oo][Rr])([^\$]*)\$/"\$" . $1 . generate_keyword($2) . "\$"/eg;
27+
28+
# replace keyword "Id"
29+
s/\$([Ii][Dd])([^\$]*)\$/"\$" . $1 . generate_keyword($2) . "\$"/eg;
30+
31+
# replace keyword "Url"
32+
s/\$([Uu][Rr][Ll])([^\$]*)\$/"\$" . $1 . generate_keyword($2) . "\$"/eg;
33+
34+
# replace keyword "File"
35+
s/\$([Ff][Ii][Ll][Ee])([^\$]*)\$/"\$" . $1 . generate_keyword($2) . "\$"/eg;
36+
37+
# replace keywords "Revision" and "Rev"
38+
s/\$([Rr][Ee][Vv][Ii][Ss][Ii][Oo][Nn])([^\$]*)\$/"\$" . $1 . generate_keyword($2) . "\$"/eg;
39+
s/\$([Rr][Ee][Vv])([^Ii][^\$]*|)\$/"\$" . $1 . generate_keyword($2) . "\$"/eg;
40+
} continue {
41+
print
42+
}

.git_filters/rcs-keywords.smudge

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/perl
2+
3+
# commun sub program to generate keyword content
4+
sub generate_keyword {
5+
# pattern as in the raw source file
6+
$pattern = $_[0];
7+
# keyword value from git log
8+
$value = $_[1];
9+
10+
# extract pattern start
11+
$start = substr($pattern,0,2);
12+
if ($start eq "::") {
13+
# if it start with "::", the pattern length must be preserved
14+
return ":: " . $value . (' ' x (length($pattern) - length($value) - 3));
15+
} else {
16+
# return default content without length concern
17+
return ": " . $value . " ";
18+
}
19+
}
20+
21+
# get first argument (full path name)
22+
$path = shift;
23+
24+
if (0 < length($path)) {
25+
# extract file name
26+
$path =~ /.*\/(.*)/;
27+
$filename = $1;
28+
29+
# not a full path, return the entire path as file name
30+
if (0 == length($filename)) {
31+
$filename = $path;
32+
}
33+
34+
# Need to grab filename and to use git log for this to be accurate.
35+
use IPC::Open3;
36+
$pid = open3(0,\*READ,\*ERROR,"git", "log", "-n", "1", "--format=%H%n%an%n%ai%n", "--", "$path");
37+
waitpid( $pid, 0 );
38+
39+
# read error pipe
40+
chomp($error = <ERROR>);
41+
42+
# if there is no error message
43+
if (0 == length($error)) {
44+
# read the 3 output lines of svn log
45+
chomp($revision = <READ>); # 1st line is revision hash
46+
chomp($author = <READ>); # 2nd line is author name
47+
chomp($date = <READ>); # 3rd line is date
48+
49+
# some usefull debug stuff
50+
# print("$revision\n$author\n$date\n");
51+
52+
# main processing loop
53+
54+
# read from stdin
55+
while (<STDIN>) {
56+
# replace keyword "Date"
57+
s/\$([Dd][Aa][Tt][Te])([^\$]*)\$/"\$" . $1 . generate_keyword($2,$date) . "\$"/eg;
58+
59+
# replace keyword "Author"
60+
s/\$([Aa][Uu][Tt][Hh][Oo][Rr])([^\$]*)\$/"\$" . $1 . generate_keyword($2,$author) . "\$"/eg;
61+
62+
# replace keyword "Id"
63+
s/\$([Ii][Dd])([^\$]*)\$(.*)/"\$" . $1 . generate_keyword($2,$path . " " . $author . " " . date) . "\$"/eg;
64+
65+
# replace keyword "Url"
66+
s/\$([Uu][Rr][Ll])([^\$]*)\$/"\$" . $1 . generate_keyword($2,$path) . "\$"/eg;
67+
68+
# replace keyword "File"
69+
s/\$([Ff][Ii][Ll][Ee])([^\$]*)\$/"\$" . $1 . generate_keyword($2,$filename) . "\$"/eg;
70+
71+
# replace keywords "Revision" and "Rev"
72+
s/\$([Rr][Ee][Vv][Ii][Ss][Ii][Oo][Nn])([^\$]*)\$/"\$" . $1 . generate_keyword($2,$revision) . "\$"/eg;
73+
s/\$([Rr][Ee][Vv])([^Ii][^\$]*|)\$/"\$" . $1 . generate_keyword($2,$revision) . "\$"/eg;
74+
75+
} continue {
76+
# output generated text to stdout
77+
print;
78+
}
79+
}
80+
}

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
*.pas filter=rcs-keywords

.gitconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[filter "rcs-keywords"]
2+
clean=.git_filters/rcs-keywords.clean
3+
smudge=.git_filters/rcs-keywords.smudge %f

0 commit comments

Comments
 (0)