com web/rmtools: Add general support for exporting from a Github mirror: data/config/repo/phpnet.ini include/Git.php include/Repository.php
| From: | Christoph Michael Becker | Date: | Mon, 07 Sep 2020 11:42:26 +0000 |
| Subject: | com web/rmtools: Add general support for exporting from a Github mirror: data/config/repo/phpnet.ini include/Git.php include/Repository.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-28771@lists.php.net to get a copy of this message | ||
Commit: 7bc1c7900fba8b34932a0618d75f37a0b649e394
Author: Christoph M. Becker <cmbecker69@gmx.de> Mon, 7 Sep 2020 13:42:26 +0200
Parents: 9e1ca1002ade165431925eca3c6ec898244de02c
Branches: master
Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=7bc1c7900fba8b34932a0618d75f37a0b649e394
Log:
Add general support for exporting from a Github mirror
This is a follow up on the quick fix for exporting from the php-src
Github mirror[1]. Instead of hard-coding everything in the code, we
introduce a configurable
gh_url, and use it if given. We cannot use
the repository URL, though, because the toplevel folder inside the
downloaded archive would have a different name (the shortened revision
number is expanded again); downloading from the codeload subdomain
gives the desired result.
[1] <https://github.com/php/web-rmtools/commit/9e1ca1002ade165431925eca3c6ec898244de02c>
Changed paths:
M data/config/repo/phpnet.ini
M include/Git.php
M include/Repository.php
Diff:
diff --git a/data/config/repo/phpnet.ini b/data/config/repo/phpnet.ini
index f9d35ca..e1c53f6 100644
--- a/data/config/repo/phpnet.ini
+++ b/data/config/repo/phpnet.ini
@@ -1,3 +1,4 @@
name=phpnet
type=git
-url=git://git.php.net
\ No newline at end of file
+url=git://git.php.net
+gh_url=https://codeload.github.com/php/php-src
diff --git a/include/Git.php b/include/Git.php
index e9c0b86...a20702a 100644
--- a/include/Git.php
+++ b/include/Git.php
@@ -3,14 +3,16 @@ namespace rmtools;
class Git {
public $repo_url;
+ private $gh_url;
public $module;
public $branch;
private $git_cmd = 'c:\apps\git\bin\git.exe';
private $tar_cmd = 'c:\apps\git\bin\tar.exe';
- public function __construct($repo_url)
+ public function __construct($repo_url, $gh_url = null)
{
$this->repo_url = $repo_url;
+ $this->gh_url = $gh_url;
if (!file_exists($this->git_cmd)) {
$git_cmd = trim(shell_exec("where git.exe"));
@@ -39,12 +41,12 @@ class Git {
public function export($dest, $revision = false)
{
- $http_url = preg_replace('/git:\/\//', 'http://', $this->repo_url);
$rev = $revision ? $revision : $this->branch;
- $url = $http_url . '/?p=' . $this->module . ';a=snapshot;h=' . $rev .
';sf=zip';
- // FIXME: hack to export from Github, since snapshot downloads have been disabled
- if ($this->repo_url === 'git://git.php.net') {
- $url = "https://codeload.github.com/php/php-src/zip/$rev";
+ if (isset($this->gh_url)) {
+ $url = $this->gh_url . '/zip/' . $rev;
+ } else {
+ $http_url = preg_replace('/git:\/\//', 'http://', $this->repo_url);
+ $url = $http_url . '/?p=' . $this->module . ';a=snapshot;h=' . $rev .
';sf=zip';
}
$dest .= '.zip';
wget($url, $dest);
diff --git a/include/Repository.php b/include/Repository.php
index 4297e3c..ac92e83 100644
--- a/include/Repository.php
+++ b/include/Repository.php
@@ -29,7 +29,7 @@ class Repository {
return $r;
break;
case 'git':
- $r = new Git($repo['url']);
+ $r = new Git($repo['url'], isset($repo['gh_url']) ?
$repo['gh_url'] : null);
return $r;
break;
default: