File: cvs2svn_revchange.php

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (227 lines) | stat: -rwxr-xr-x 6,685 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/php -q
<?php
/*
  +----------------------------------------------------------------------+
  | PHP Version 4                                                        |
  +----------------------------------------------------------------------+
  | Copyright (c) 2009-2010 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Nilgün Belma Bugüner <nilgun@php.net>                           |
  +----------------------------------------------------------------------+

  $Id: cvs2svn_revchange.php 293138 2010-01-05 10:21:11Z rquadling $
*/
if ($argc != 2) {
?>

Check the revision of translated files against the actual english xml files,
and change revision of translated files from cvs to svn

  Usage:
  <?php echo $argv[0]; ?> <language-code>

  <language-code> must be a valid language code used
  in the repository

  Read more about Revision comments and related
  functionality in the PHP Documentation Howto:
    http://php.net/dochowto

<?php
  exit;
}

// Long runtime
set_time_limit(0);


// Initializing variables from parameters
$LANG = $argv[1];

// Main directory of the PHP documentation (depends on the
// sapi used). We do need the trailing slash!
if ("cli" === php_sapi_name()) {
  if (isset($PHPDOCDIR) && is_dir($PHPDOCDIR)) {
    $DOCDIR = $PHPDOCDIR."/";
  } else {
    $DOCDIR = "./";
  }
} else {
  $DOCDIR = "../";
}
// =========================================================================
// Functions to get revision info and credits from a file
// =========================================================================

// Grabs the revision tag and stores credits from the file given
function get_tags($file, $val = "cvs-rev") {

  // Check for English CVS revision tag
  if ($val == "cvs-rev") {
    $cvsrev = substr (`svn propget cvs2svn:cvs-rev $file`, 2);
    return $cvsrev;
  }


  // Read the first 500 chars. The comment should be at
  // the begining of the file
  $fp = @fopen($file, "r") or die ("Unable to read $file.");
  $line = fread($fp, 500);
  fclose($fp);

  // No match before the preg
  $match = array();

  // Check for English SVN revision tag
  if ($val == "svn-rev") {
    preg_match ("/<!-- .Revision: (\d+) . -->/", $line, $match);

    return $match[1];
  }
  // Check for the translations "revision tag"

  preg_match ("/<!--.EN-Revision:\s*.*\.?(\d+)\s*Maintainer:/U", $line, $match);

  // Return with found revision number
  return $match[1];

} // get_tags() function end


// =========================================================================
// Functions to check file status in translated directory, and change revision
// =========================================================================

// Checks a file, and change revision
function change_revision($file) {

  global $DOCDIR, $LANG;

  $en_file = preg_replace("'^".$DOCDIR.$LANG."/'", $DOCDIR."en/", $file);

  // Get en file cvs revision
  $cvs_rev = get_tags($en_file);

  // Get en file cvs revision
  $svn_rev = get_tags($en_file, "svn-rev");

  // Get translated file revision
  $this_rev = get_tags($file, "this-rev");

  // If we have a numeric revision number (not n/a), compute rev. diff
  if (is_numeric($this_rev)) {

    $rev_diff = intval($cvs_rev) - intval($this_rev);

    if (!$rev_diff) {
      /* change revision number from cvs to svn */

      $line = file_get_contents($file);
      $str = "<!-- EN-Revision: $svn_rev Maintainer:";
      $newline = preg_replace("/<!--.EN-Revision:\s*.\d+\.\d+\s*Maintainer:/U", $str, $line);

      $fp = fopen($file, "w");
      fwrite ($fp, $newline);
      fclose($fp);

    } elseif ($rev_diff > 0) {
      /* change revision number to n/a */

      $line = file_get_contents($file);
      $str = "<!-- EN-Revision: n/a Maintainer:";
      $newline = preg_replace("/<!--.EN-Revision:\s*.\d+\.\d+\s*Maintainer:/U", $str, $line);

      $fp = fopen($file, "w");
      fwrite ($fp, $newline);
      fclose($fp);

    } // else no touch
  }

} // change_revision() function end

// =========================================================================
// A function to check directory status in translated directory
// =========================================================================

// Check the status of files in a diretory of phpdoc XML files
// The English directory is passed to this function to check
function get_dirs($dir) {

  global $DOCDIR;

  // Collect files and diretcories in these arrays
  $directories = array();
  $files       = array();

  // Open the directory
  $handle = @opendir($dir);

  // Walk through all names in the directory
  while ($file = @readdir($handle)) {

    if (
    (!is_dir($dir.'/' .$file) && !in_array(substr($file, -3), array('xml','ent')) && substr($file, -13) != 'PHPEditBackup' )
    || strpos($file, 'entities.') === 0
    || $file == 'translation.xml'
    || $file == 'README'
    || $file == 'DO_NOT_TRANSLATE'
    || $file == 'rsusi.txt'
    || $file == 'missing-ids.xml'
    || $file == 'license.xml'
    || $file == 'versions.xml'
    ) {
      continue;
    }

    if ($file != '.' && $file != '..' && $file != '.svn' && $dir != '/functions') {
      if (is_dir($dir.'/' .$file)) {
          $directories[] = $file;
      } elseif (is_file($dir.'/' .$file)) {
          $files[] = $file;
      }
    }

  }

  // Close the directory
  @closedir($handle);

  // Sort files and directories
  sort($directories);
  sort($files);

  // Go through files first
  foreach ($files as $file) {
    change_revision($dir.$file);
  }

  // Then go through subdirectories
  foreach ($directories as $file) {
    get_dirs($dir.$file.'/');
  }

} // get_dirs() function end


// =========================================================================
// Start of the program execution
// =========================================================================

// Check for directory validity
if (!@is_dir($DOCDIR . $LANG)) {
  die("The $LANG language code is not valid");
}

// Get all files status
get_dirs($DOCDIR.$LANG."/");

?>