Annotation of /scripts/svn_fix_properties.pl
Parent Directory
|
Revision Log
Revision 67 - (view) (download) (as text)
| 1 : | mjm | 57 | #!/usr/bin/perl |
| 2 : | |||
| 3 : | mjm | 67 | die "usage: svn_fix_properties <dir>\nsvn_fix_properties <file>\n" |
| 4 : | mjm | 57 | unless (@ARGV == 1); |
| 5 : | my $target = $ARGV[0]; | ||
| 6 : | |||
| 7 : | ######################################################################## | ||
| 8 : | |||
| 9 : | %gExtExecutable = | ||
| 10 : | ( | ||
| 11 : | "exe" => 1, | ||
| 12 : | "sh" => 1, | ||
| 13 : | "pl" => 1, | ||
| 14 : | "py" => 1, | ||
| 15 : | ); | ||
| 16 : | |||
| 17 : | mjm | 67 | |
| 18 : | mjm | 57 | %gExtText = |
| 19 : | ( | ||
| 20 : | "bat" => 1, | ||
| 21 : | "cmake" => 1, | ||
| 22 : | "c" => 1, | ||
| 23 : | "cpp" => 1, | ||
| 24 : | "cs" => 1, | ||
| 25 : | "csproj" => 1, | ||
| 26 : | "exp" => 1, | ||
| 27 : | "glsl" => 1, | ||
| 28 : | "h" => 1, | ||
| 29 : | "html" => 1, | ||
| 30 : | "inc" => 1, | ||
| 31 : | "ini" => 1, | ||
| 32 : | "inl" => 1, | ||
| 33 : | "l" => 1, | ||
| 34 : | "mm" => 1, | ||
| 35 : | "msg" => 1, | ||
| 36 : | "nsi" => 1, | ||
| 37 : | "nib" => 1, | ||
| 38 : | "pem" => 1, | ||
| 39 : | "pl" => 1, | ||
| 40 : | "plist" => 1, | ||
| 41 : | "py" => 1, | ||
| 42 : | "r" => 1, | ||
| 43 : | "rc" => 1, | ||
| 44 : | "sln" => 1, | ||
| 45 : | "strings" => 1, | ||
| 46 : | "supp" => 1, | ||
| 47 : | "txt" => 1, | ||
| 48 : | "xib" => 1, | ||
| 49 : | "xml" => 1, | ||
| 50 : | "y" => 1, | ||
| 51 : | ); | ||
| 52 : | |||
| 53 : | mjm | 67 | %gExtTextLF = |
| 54 : | ( | ||
| 55 : | "sh" => 1, | ||
| 56 : | ); | ||
| 57 : | |||
| 58 : | mjm | 57 | %gExtIgnore = |
| 59 : | ( | ||
| 60 : | "" => 1, | ||
| 61 : | "bin" => 1, | ||
| 62 : | "BMP" => 1, | ||
| 63 : | "bmp" => 1, | ||
| 64 : | "bz2" => 1, | ||
| 65 : | "cur" => 1, | ||
| 66 : | "db2" => 1, | ||
| 67 : | "gif" => 1, | ||
| 68 : | "ico" => 1, | ||
| 69 : | "icns" => 1, | ||
| 70 : | "j2c" => 1, | ||
| 71 : | "jpg" => 1, | ||
| 72 : | "llm" => 1, | ||
| 73 : | "png" => 1, | ||
| 74 : | "tga" => 1, | ||
| 75 : | "ttf" => 1, | ||
| 76 : | "zip" => 1, | ||
| 77 : | ); | ||
| 78 : | |||
| 79 : | ######################################################################## | ||
| 80 : | |||
| 81 : | if (-d $target) { | ||
| 82 : | &checkDir($target); | ||
| 83 : | } elsif (-f $target) { | ||
| 84 : | &checkFile($target); | ||
| 85 : | } else { | ||
| 86 : | print STDERR "'$target' does not exist.\n"; | ||
| 87 : | } | ||
| 88 : | |||
| 89 : | ######################################################################## | ||
| 90 : | |||
| 91 : | sub checkDir | ||
| 92 : | { | ||
| 93 : | my ($dir) = @_; | ||
| 94 : | |||
| 95 : | chdir $dir or | ||
| 96 : | die "Failed to change to directory '$d'\n"; | ||
| 97 : | |||
| 98 : | print STDERR "Updating from SVN.\n"; | ||
| 99 : | system("svn update"); | ||
| 100 : | |||
| 101 : | print STDERR "Checking files.\n"; | ||
| 102 : | open(SVN_DIR, "svn list -R . |") or | ||
| 103 : | die "Failed to run svn.\n"; | ||
| 104 : | while (my $file = <SVN_DIR>) { | ||
| 105 : | chomp($file); | ||
| 106 : | &checkFile($file); | ||
| 107 : | } | ||
| 108 : | close SVN_DIR or | ||
| 109 : | die "Error running svn.\n"; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | ######################################################################## | ||
| 113 : | |||
| 114 : | sub checkFile | ||
| 115 : | { | ||
| 116 : | my ($file) = @_; | ||
| 117 : | my $known = 0; | ||
| 118 : | |||
| 119 : | my @props = &getSvnProperties($file); | ||
| 120 : | |||
| 121 : | $file =~ /\.(\w+)$/; | ||
| 122 : | my $ext = $1; | ||
| 123 : | |||
| 124 : | # check executable | ||
| 125 : | if (defined($gExtExecutable{$ext})) { | ||
| 126 : | &addProperty($file, "svn:executable", "") | ||
| 127 : | unless grep($_ eq "svn:executable", @props); | ||
| 128 : | $known = 1; | ||
| 129 : | } else { | ||
| 130 : | &delProperty($file, "svn:executable") | ||
| 131 : | if grep($_ eq "svn:executable", @props); | ||
| 132 : | } | ||
| 133 : | |||
| 134 : | # check text | ||
| 135 : | if (defined($gExtText{$ext})) { | ||
| 136 : | &addProperty($file, "svn:eol-style", "native") | ||
| 137 : | unless grep($_ eq "svn:eol-style", @props); | ||
| 138 : | $known = 1; | ||
| 139 : | mjm | 67 | } elsif (defined($gExtTextLF{$ext})) { |
| 140 : | &addProperty($file, "svn:eol-style", "LF") | ||
| 141 : | unless grep($_ eq "svn:eol-style", @props); | ||
| 142 : | $known = 1; | ||
| 143 : | mjm | 57 | } else { |
| 144 : | &delProperty($file, "svn:eol-style") | ||
| 145 : | if grep($_ eq "svn:eol-style", @props); | ||
| 146 : | } | ||
| 147 : | |||
| 148 : | unless ($known || defined($gExtIgnore{$ext})) { | ||
| 149 : | print STDERR "Unknown extension '$ext'\n"; | ||
| 150 : | $gExtIgnore{$ext} = 1; | ||
| 151 : | } | ||
| 152 : | } | ||
| 153 : | |||
| 154 : | ######################################################################## | ||
| 155 : | |||
| 156 : | sub getSvnProperties | ||
| 157 : | { | ||
| 158 : | my ($file) = @_; | ||
| 159 : | my @props = (); | ||
| 160 : | |||
| 161 : | open(SVN_PROPS, "svn pl '$file' |") or | ||
| 162 : | die "Failed to run svn.\n"; | ||
| 163 : | while (<SVN_PROPS>) { | ||
| 164 : | (/(svn:\S+)/) and push(@props, $1); | ||
| 165 : | } | ||
| 166 : | close SVN_PROPS or | ||
| 167 : | die "Error running svn.\n"; | ||
| 168 : | @props; | ||
| 169 : | } | ||
| 170 : | |||
| 171 : | ######################################################################## | ||
| 172 : | |||
| 173 : | sub addProperty | ||
| 174 : | { | ||
| 175 : | my ($file, $prop, $value) = @_; | ||
| 176 : | |||
| 177 : | system("svn ps '$prop' '$value' '$file'") and | ||
| 178 : | die "Error running svn.\n"; | ||
| 179 : | } | ||
| 180 : | |||
| 181 : | sub delProperty | ||
| 182 : | { | ||
| 183 : | my ($file, $prop) = @_; | ||
| 184 : | |||
| 185 : | system("svn pd '$prop' '$file'") and | ||
| 186 : | die "Error running svn.\n"; | ||
| 187 : | } | ||
| 188 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

