Index: trunk/extensions/ExtensionDistributor/ExtensionDistributorGit.php |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | return Status::newFatal( 'extdist-git-invalidsha1', $result ); |
39 | 39 | } |
40 | 40 | |
| 41 | + // TODO: Should we truncate the 40 character sha1 hash to a more common/usable 7 chars? |
41 | 42 | return Status::newGood( $result ); |
42 | 43 | } |
43 | 44 | } |
Index: trunk/extensions/ExtensionDistributor/svn-invoker.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | * @param $retval |
35 | 35 | * @return string |
36 | 36 | */ |
37 | | -function svnShellExec( $cmd, &$retval ) { |
| 37 | +function invokerShellExec( $cmd, &$retval ) { |
38 | 38 | $retval = 1; // error by default? |
39 | 39 | ob_start(); |
40 | 40 | passthru( $cmd, $retval ); |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | * @param $msg |
48 | 48 | * @param bool $info |
49 | 49 | */ |
50 | | -function svnError( $msg, $info = false ) { |
| 50 | +function invokerError( $msg, $info = false ) { |
51 | 51 | echo json_encode( array( 'error' => $msg, 'errorInfo' => $info ) ); |
52 | 52 | } |
53 | 53 | |
— | — | @@ -65,14 +65,14 @@ |
66 | 66 | $encCommand .= $buf; |
67 | 67 | } |
68 | 68 | if ( !$encCommand ) { |
69 | | - svnError( 'extdist-remote-error', "Invalid command." ); |
| 69 | + invokerError( 'extdist-remote-error', "Invalid command." ); |
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | 73 | if ( $wgExtDistLockFile ) { |
74 | 74 | $lockFile = fopen( $wgExtDistLockFile, 'a' ); |
75 | 75 | if ( !$lockFile ) { |
76 | | - svnError( 'extdist-remote-error', "Unable to open lock file." ); |
| 76 | + invokerError( 'extdist-remote-error', "Unable to open lock file." ); |
77 | 77 | return; |
78 | 78 | } |
79 | 79 | $timeout = 3; |
— | — | @@ -83,25 +83,26 @@ |
84 | 84 | sleep( 1 ); |
85 | 85 | } |
86 | 86 | if ( $i == $timeout ) { |
87 | | - svnError( 'extdist-remote-error', "Lock wait timeout." ); |
| 87 | + invokerError( 'extdist-remote-error', "Lock wait timeout." ); |
88 | 88 | return; |
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | 92 | $command = json_decode( $encCommand ); |
93 | | - if ( !isset( $command->version ) || !isset( $command->extension ) ) { |
94 | | - svnError( 'extdist-remote-error', "Missing version or extension parameter." ); |
| 93 | + if ( !isset( $command->version ) || !isset( $command->extension ) || !isset( $command->vcs ) ) { |
| 94 | + invokerError( 'extdist-remote-error', "Missing version, extension or vcs parameter." ); |
95 | 95 | return; |
96 | 96 | } |
97 | 97 | if ( !svnValidate( $command->version ) ) { |
98 | | - svnError( 'extdist-remote-error', "Invalid version parameter" ); |
| 98 | + invokerError( 'extdist-remote-error', "Invalid version parameter" ); |
99 | 99 | return; |
100 | 100 | } elseif ( !svnValidate( $command->extension ) ) { |
101 | | - svnError( 'extdist-remote-error', "Invalid extension parameter" ); |
| 101 | + invokerError( 'extdist-remote-error', "Invalid extension parameter" ); |
102 | 102 | return; |
103 | 103 | } |
104 | 104 | $version = $command->version; |
105 | 105 | $extension = $command->extension; |
| 106 | + $vcs = $command->vcs; |
106 | 107 | $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension"; |
107 | 108 | |
108 | 109 | // Determine last changed revision in the checkout |
— | — | @@ -119,10 +120,10 @@ |
120 | 121 | if ( $remoteRev != $localRev ) { |
121 | 122 | // Bad luck, we need to svn up |
122 | 123 | $cmd = "svn up --non-interactive " . escapeshellarg( $dir ) . " 2>&1"; |
123 | | - $retval = - 1; |
124 | | - $result = svnShellExec( $cmd, $retval ); |
| 124 | + $retval = -1; |
| 125 | + $result = invokerShellExec( $cmd, $retval ); |
125 | 126 | if ( $retval ) { |
126 | | - svnError( 'extdist-svn-error', $result ); |
| 127 | + invokerError( 'extdist-svn-error', $result ); |
127 | 128 | return; |
128 | 129 | } |
129 | 130 | } |
— | — | @@ -138,12 +139,11 @@ |
139 | 140 | * @return bool|string |
140 | 141 | */ |
141 | 142 | function svnGetRev( $dir, &$url = null ) { |
142 | | - |
143 | 143 | $cmd = "svn info --non-interactive --xml " . escapeshellarg( $dir ); |
144 | | - $retval = - 1; |
145 | | - $result = svnShellExec( $cmd, $retval ); |
| 144 | + $retval = -1; |
| 145 | + $result = invokerShellExec( $cmd, $retval ); |
146 | 146 | if ( $retval ) { |
147 | | - svnError( 'extdist-svn-error', $result ); |
| 147 | + invokerError( 'extdist-svn-error', $result ); |
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | |
— | — | @@ -155,9 +155,52 @@ |
156 | 156 | $rev = false; |
157 | 157 | } |
158 | 158 | if ( !$rev || strpos( $rev, '/' ) !== false || strpos( $rev, "\000" ) !== false ) { |
159 | | - svnError( 'extdist-svn-parse-error', $result ); |
| 159 | + invokerError( 'extdist-svn-parse-error', $result ); |
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | |
163 | 163 | return $rev; |
164 | 164 | } |
| 165 | + |
| 166 | +/** |
| 167 | + * @param $dir string |
| 168 | + * @return bool|string |
| 169 | + */ |
| 170 | +function gitGetRev( $dir ) { |
| 171 | + chdir( $dir ); |
| 172 | + $cmd = "git rev-parse HEAD"; |
| 173 | + $retval = -1; |
| 174 | + $result = invokerShellExec( $cmd, $retval ); |
| 175 | + if ( $retval ) { |
| 176 | + invokerError( 'extdist-git-error', $result ); |
| 177 | + return false; |
| 178 | + } |
| 179 | + |
| 180 | + // Trim trailing whitespace |
| 181 | + $result = rtrim( $result ); |
| 182 | + |
| 183 | + // Check it looks like a SHA1 hash |
| 184 | + if ( !preg_match( '/^[0-9a-f]{40}$/i', $result ) ) { |
| 185 | + invokerError( 'extdist-git-invalidsha1', $result ); |
| 186 | + return false; |
| 187 | + } |
| 188 | + |
| 189 | + // TODO: Should we truncate the 40 character sha1 hash to a more common/usable 7 chars? |
| 190 | + return $result; |
| 191 | +} |
| 192 | + |
| 193 | +/** |
| 194 | + * @param $dir string |
| 195 | + * @return bool |
| 196 | + */ |
| 197 | +function isSVNDir( $dir ) { |
| 198 | + return is_dir( "$dir/.svn"); |
| 199 | +} |
| 200 | + |
| 201 | +/** |
| 202 | + * @param $dir string |
| 203 | + * @return bool |
| 204 | + */ |
| 205 | +function isGitDir( $dir ) { |
| 206 | + return is_dir( "$dir/.svn"); |
| 207 | +} |
Index: trunk/extensions/ExtensionDistributor/ExtensionDistributor.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | $wgExtensionCredits['specialpage'][] = array( |
10 | 10 | 'path' => __FILE__, |
11 | 11 | 'name' => 'Extension Distributor', |
12 | | - 'author' => 'Tim Starling', |
| 12 | + 'author' => array( 'Tim Starling', 'Sam Reed' ), |
13 | 13 | 'url' => 'https://www.mediawiki.org/wiki/Extension:ExtensionDistributor', |
14 | 14 | 'descriptionmsg' => 'extensiondistributor-desc', |
15 | 15 | ); |