3 #=======================================================================
5 # Converts Subversion/RCS/CVS keywords in text files in various ways.
6 # Optimised for use with Subversion at the moment, but also works with
10 # License: GNU General Public License
11 # Author: Øyvind A. Holm <sunny@sunbase.org>
12 # This file is part of the svnutils package — http://svnutils.tigris.org
13 #=======================================================================
19 our ($opt_c, $opt_D, $opt_h, $opt_S, $opt_s, $opt_V) =
21 getopts
('cDhSsV') || die("Option error, use -h for help");
24 my $stripped_rcs_id = $rcs_id;
25 $stripped_rcs_id =~ s/^\$(.*)\s+\S+\s+\$$/$1/;
31 "Author", "LastChangedBy",
32 "Date", "LastChangedDate",
33 "LastChangedRevision", "Revision", "Rev",
43 my $Keyw = join('|', @Keywords); # Used in regexps
47 $opt_s && $opt_S && die("convkeyw: Cannot mix the -s and -S option.\n");
50 print("$stripped_rcs_id\n");
54 my $rand_ext = "$$." . substr(rand, 2, 8);
55 while (defined($ARGV[0])) {
56 # Scan through all file names on the command line {{{
58 my $Dest = "$Curr.$rand_ext.tmp";
59 if (open(FromFP
, $Curr)) {
60 (-e
$Dest) && die("$Dest: What??? File already exists!");
61 if (open(ToFP
, ">$Dest")) {
63 /\$/ && ($_ = process_line
($_));
68 rename($Dest, $Curr) || warn("rename($Dest, $Curr): $!");
70 warn("$Dest: Unable to create file: $!");
73 warn("$Curr: Unable to open file for read: $!");
83 # Compress all keywords
84 $Retval =~ s/(\$)($Keyw): .*? (\$)/$1$2$3/;
88 # Remove the () stuff from the Subversion $Date.
89 $Retval =~ s/(\$Date: .*?)\(..., \d+ ... \d\d\d\d\) (\$)/$1$2/g;
93 # Strip keywords — remove dollars, keyword and colon. This
94 # action is destructive and has to be last.
95 $Retval =~ s/\$($Keyw): (.*?) \$/$2/g;
96 $Retval =~ s/\$($Keyw)\$/$1/g;
98 # Strip keywords — remove dollars only. This action is
99 # destructive and has to be last.
100 $Retval =~ s/\$($Keyw): (.*?) \$/$1: $2/g;
101 $Retval =~ s/\$($Keyw)\$/$1/g;
109 # Send help text to stdout {{{
113 Syntax: convkeyw [options] file [file [...]]
115 Convert RCS/CVS/Subversion keywords in text files in various ways.
119 -c Compress keywords in the file, for example:
120 \$Id: dbk 963 2004-09-29 08:14:15Z sunny \$
123 This can be useful when comparing files against the text-base.
124 -D Remove the long date format from Subversion \$Id\$ strings.
125 \$Date: 2004-05-18 10:44:54 +0200 (Tue, 18 May 2004) \$
127 \$Date: 2004-05-18 10:44:54 +0200 \$
129 -s Strip keywords, i.e. remove the " \$", "\$Id: :" and "\$Date: "
130 from keywords to protect them from changes when importing or
131 adding the file to a new repository.
132 \$Id: file.txt 123 2004-01-21 17:12:16Z fjodor \$
134 file.txt 123 2004-01-21 17:12:16Z fjodor
135 WARNING: After using this option, further processing of keywords
136 in the file is impossible. Meant for use in tarballs and
138 -S Strip dollars from keywords like -s, but leave the keyword
139 itself and the colon intact. I.e.:
140 \$Id: file.txt 123 2004-01-21 17:12:16Z fjodor \$
142 Id: file.txt 123 2004-01-21 17:12:16Z fjodor
143 -V Print version of the script:
153 # vim: set et ts=4 sw=4 sts=4 fo+=w fo+=c fo-=t tw=72 :