Subversion Repositories Applications.gtt

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 jpm 1
<?php
2
//
3
// +------------------------------------------------------------------------+
4
// | PEAR :: Package File Manager                                           |
5
// +------------------------------------------------------------------------+
6
// | Copyright (c) 2003-2004 Gregory Beaver                                 |
7
// | Email         cellog@phpdoc.org                                        |
8
// +------------------------------------------------------------------------+
9
// | This source file is subject to version 3.00 of the PHP License,        |
10
// | that is available at http://www.php.net/license/3_0.txt.               |
11
// | If you did not receive a copy of the PHP license and are unable to     |
12
// | obtain it through the world-wide-web, please send a note to            |
13
// | license@php.net so we can mail you a copy immediately.                 |
14
// +------------------------------------------------------------------------+
15
// | Portions of this code based on phpDocumentor                           |
16
// | Web           http://www.phpdoc.org                                    |
17
// | Mirror        http://phpdocu.sourceforge.net/                          |
18
// +------------------------------------------------------------------------+
19
// $Id: Svn.php,v 1.1 2004/05/31 12:02:31 arnaud Exp $
20
//
21
/**
22
 * @package PEAR_PackageFileManager
23
 */
24
/**
25
 * The PEAR_PackageFileManager_File class
26
 */
27
require_once 'PEAR/PackageFileManager/File.php';
28
 
29
/**
30
 * Generate a file list from a Subversion checkout
31
 *
32
 * Largely based on the CVS class, modified to suit
33
 * subversion organization.
34
 *
35
 * Note that this will <b>NOT</b> work on a
36
 * repository, only on a checked out Subversion module
37
 * @package PEAR_PackageFileManager
38
 * @author Arnaud Limbour <arnaud@limbourg.com>
39
 */
40
class PEAR_PackageFileManager_Svn extends PEAR_PackageFileManager_File
41
{
42
    /**
43
     * Return a list of all files in the CVS repository
44
     *
45
     * This function is like {@link parent::dirList()} except
46
     * that instead of retrieving a regular filelist, it first
47
     * retrieves a listing of all the .svn/entries files in
48
     * $directory and all of the subdirectories.  Then, it
49
     * reads the entries file, and creates a listing of files
50
     * that are a part of the Subversion checkout.  No check is
51
     * made to see if they have been modified, but removed files
52
     * are ignored.
53
     *
54
     * @access protected
55
     * @return array list of files in a directory
56
     * @param  string $directory full path to the directory you want the list of
57
     * @uses   _recurDirList()
58
     * @uses   _readSVNEntries()
59
     */
60
    function dirList($directory)
61
    {
62
        static $in_recursion = false;
63
        if (!$in_recursion) {
64
            // include only .svn/entries files
65
            // since subversion keeps its data in a hidden
66
            // directory we must force PackageFileManager to
67
            // consider hidden directories.
68
            $this->_options['addhiddenfiles'] = true;
69
            $this->_setupIgnore(array('*/.svn/entries'), 0);
70
            $this->_setupIgnore(array(), 1);
71
            $in_recursion = true;
72
            $entries = parent::dirList($directory);
73
            $in_recursion = false;
74
        } else {
75
            return parent::dirList($directory);
76
        }
77
        if (!$entries || !is_array($entries)) {
78
            return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_NOSVNENTRIES, $directory);
79
        }
80
        return $this->_readSVNEntries($entries);
81
    }
82
 
83
    /**
84
     * Iterate over the SVN Entries files, and retrieve every
85
     * file in the repository
86
     *
87
     * @uses _getSVNEntries()
88
     * @param array array of full paths to .svn/entries files
89
     * @access private
90
     */
91
    function _readSVNEntries($entries)
92
    {
93
        $ret = array();
94
        $ignore = $this->_options['ignore'];
95
        // implicitly ignore packagefile
96
        $ignore[] = $this->_options['packagefile'];
97
        $include = $this->_options['include'];
98
        $this->ignore = array(false, false);
99
        $this->_setupIgnore($ignore, 1);
100
        $this->_setupIgnore($include, 0);
101
        foreach($entries as $cvsentry) {
102
            $directory = @dirname(@dirname($cvsentry));
103
            if (!$directory) {
104
                continue;
105
            }
106
            $d = $this->_getSVNEntries($cvsentry);
107
            if (!is_array($d)) {
108
                continue;
109
            }
110
            foreach($d as $entry) {
111
                if ($ignore) {
112
                	if ($this->_checkIgnore($entry,
113
                          $directory . '/' . $entry, 1)) {
114
                        continue;
115
                    }
116
                }
117
                if ($include) {
118
                    if ($this->_checkIgnore($entry,
119
                          $directory . '/' . $entry, 0)) {
120
                        continue;
121
                    }
122
                }
123
                $ret[] = $directory . '/' . $entry;
124
            }
125
        }
126
        return $ret;
127
    }
128
 
129
    /**
130
     * Retrieve the entries in a .svn/entries file
131
     *
132
     * Uses XML_Tree to parse the XML subversion file
133
     *
134
     * It keeps only files, excluding directories. It also
135
     * makes sure no deleted file in included.
136
     *
137
     * @return array  an array with full paths to files
138
     * @uses   PEAR::XML_Tree
139
     * @param  string full path to a .svn/entries file
140
     * @access private
141
     */
142
    function _getSVNEntries($svnentriesfilename)
143
    {
144
        require_once 'XML/Tree.php';
145
        $parser  = &new XML_Tree($svnentriesfilename);
146
        $tree    = &$parser->getTreeFromFile();
147
 
148
        // loop through the xml tree and keep only valid entries being files
149
        $entries = array();
150
        foreach ($tree->children as $entry) {
151
            if ($entry->name == 'entry'
152
                && $entry->attributes['kind'] == 'file') {
153
                    if (isset($entry->attributes['deleted'])) {
154
                        continue;
155
                    }
156
                array_push($entries, $entry->attributes['name']);
157
            }
158
        }
159
 
160
        unset($parser, $tree);
161
 
162
        if (is_array($entries)) {
163
            return $entries;
164
        } else {
165
            return false;
166
        }
167
    }
168
}
169
?>