changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / scripts / add_cvs.php
1 <?php\r
2 //\r
3 // +------------------------------------------------------------------------+\r
4 // | phpDocumentor                                                          |\r
5 // +------------------------------------------------------------------------+\r
6 // | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |\r
7 // | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |\r
8 // | Web           http://www.phpdoc.org                                    |\r
9 // | Mirror        http://phpdocu.sourceforge.net/                          |\r
10 // | PEAR          http://pear.php.net/package/PhpDocumentor                |\r
11 // +------------------------------------------------------------------------+\r
12 // | This source file is subject to version 3.00 of the PHP License,        |\r
13 // | that is available at http://www.php.net/license/3_0.txt.               |\r
14 // | If you did not receive a copy of the PHP license and are unable to     |\r
15 // | obtain it through the world-wide-web, please send a note to            |\r
16 // | license@php.net so we can mail you a copy immediately.                 |\r
17 // +------------------------------------------------------------------------+\r
18 //\r
19 /**\r
20  * CVS file adding iterator\r
21  *\r
22  * This file iterates over a directory, and adds everything to CVS that is\r
23  * found, ignoring any error messages, until all files in each directory\r
24  * and subdirectory have been added to cvs.  It then commits the files to cvs\r
25  * @package phpDocumentor\r
26  * @author Greg Beaver <cellog@php.net>\r
27  * @copyright Copyright 2003, Greg Beaver\r
28  * @version 1.0\r
29  */\r
30 /**#@+\r
31  * phpDocumentor include files.  If you don't have phpDocumentor, go get it!\r
32  * Your php life will be changed forever\r
33  */\r
34 $dir = realpath(dirname(__FILE__).'/..');\r
35 require_once("$dir/phpDocumentor/common.inc.php");\r
36 require_once("$dir/phpDocumentor/Io.inc");\r
37 /**#@-*/\r
38 \r
39 /**\r
40 * Physical location on this computer of the package to parse\r
41 * @global string $cvsadd_directory\r
42 */\r
43 $cvsadd_directory = realpath('.');\r
44 /**\r
45 * Comma-separated list of files and directories to ignore\r
46 *\r
47 * This uses wildcards * and ? to remove extra files/directories that are\r
48 * not part of the package or release\r
49 * @global string $ignore\r
50 */\r
51 $ignore = array('CVS/');\r
52 \r
53 /******************************************************************************\r
54 *       Don't change anything below here unless you're adventuresome          *\r
55 *******************************************************************************/\r
56 \r
57 /**\r
58  * @global Io $files\r
59  */\r
60 $files = new Io;\r
61 \r
62 $allfiles = $files->dirList($cvsadd_directory);\r
63 /**#@+\r
64  * Sorting functions for the file list\r
65  * @param string\r
66  * @param string\r
67  */\r
68 function sortfiles($a, $b)\r
69 {\r
70         return strnatcasecmp($a['file'],$b['file']);\r
71 }\r
72 \r
73 function mystrucsort($a, $b)\r
74 {\r
75         if (is_numeric($a) && is_string($b)) return 1;\r
76         if (is_numeric($b) && is_string($a)) return -1;\r
77         if (is_numeric($a) && is_numeric($b))\r
78         {\r
79                 if ($a > $b) return 1;\r
80                 if ($a < $b) return -1;\r
81                 if ($a == $b) return 0;\r
82         }\r
83         return strnatcasecmp($a,$b);\r
84 }\r
85 /**#@-*/\r
86 \r
87 $struc = array();\r
88 foreach($allfiles as $file)\r
89 {\r
90         if ($files->checkIgnore(basename($file),dirname($file),$ignore, false))\r
91     {\r
92 //        print 'Ignoring '.$file."<br>\n";\r
93         continue;\r
94     }\r
95         $path = substr(dirname($file),strlen(str_replace('\\','/',realpath($cvsadd_directory)))+1);\r
96         if (!$path) $path = '/';\r
97         $file = basename($file);\r
98         $ext = array_pop(explode('.',$file));\r
99         if (strlen($ext) == strlen($file)) $ext = '';\r
100         $struc[$path][] = array('file' => $file,'ext' => $ext);\r
101 }\r
102 uksort($struc,'strnatcasecmp');\r
103 foreach($struc as $key => $ind)\r
104 {\r
105         usort($ind,'sortfiles');\r
106         $struc[$key] = $ind;\r
107 }\r
108 $tempstruc = $struc;\r
109 $struc = array('/' => $tempstruc['/']);\r
110 $bv = 0;\r
111 foreach($tempstruc as $key => $ind)\r
112 {\r
113         $save = $key;\r
114         if ($key != '/')\r
115         {\r
116         $struc['/'] = setup_dirs($struc['/'], explode('/',$key), $tempstruc[$key]);\r
117         }\r
118 }\r
119 uksort($struc['/'],'mystrucsort');\r
120 /**\r
121  * Recursively add files to cvs\r
122  * @param array the sorted directory structure\r
123  */\r
124 function addToCVS($struc)\r
125 {\r
126         foreach($struc as $dir => $files)\r
127         {\r
128                 if ($dir === '/')\r
129                 {\r
130             print 'processing '.$dir . "\n";\r
131                         addToCVS($struc[$dir]);\r
132                         return;\r
133                 } else\r
134                 {\r
135                         if (!isset($files['file']))\r
136                         {\r
137                 print 'adding '.$dir . "\n";\r
138                 system('cvs add '.$dir);\r
139                 chdir($dir);\r
140                                 addToCVS($files);\r
141                 chdir('..');\r
142                         } else\r
143                         {\r
144                 print 'adding '.$files['file'] . "\n";\r
145                 system('cvs add '.$files['file']);\r
146                 system('cvs commit -m "" '.$files['file']);\r
147                         }\r
148                 }\r
149         }\r
150 }\r
151 addToCVS($struc);\r
152 print "\n".'done';\r
153 ?>