com web/rmtools: Add initial Git support: client/data/config/repo/phpnet.ini client/include/Git.php
| From: | Stephen A. Zarkos | Date: | Wed, 21 Nov 2012 23:30:42 +0000 |
| Subject: | com web/rmtools: Add initial Git support: client/data/config/repo/phpnet.ini client/include/Git.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-15642@lists.php.net to get a copy of this message | ||
Commit: 742a5efc772a25fdb19c18048780d71167a2facf
Author: Stephen Zarkos <stephen.zarkos@microsoft.com> Wed, 21 Nov 2012 15:30:42
-0800
Parents: be31b985b0c93375abff9cc2450243d7ff671620
Branches: master
Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=742a5efc772a25fdb19c18048780d71167a2facf
Log:
Add initial Git support
Changed paths:
M client/data/config/repo/phpnet.ini
A client/include/Git.php
Diff:
diff --git a/client/data/config/repo/phpnet.ini b/client/data/config/repo/phpnet.ini
index ea781cd..f9d35ca 100644
--- a/client/data/config/repo/phpnet.ini
+++ b/client/data/config/repo/phpnet.ini
@@ -1,3 +1,3 @@
-name=phpnet
-type=svn
-url=http://svn.php.net/repository
+name=phpnet
+type=git
+url=git://git.php.net
\ No newline at end of file
diff --git a/client/include/Git.php b/client/include/Git.php
new file mode 100644
index 0000000..d585c85
--- /dev/null
+++ b/client/include/Git.php
@@ -0,0 +1,56 @@
+<?php
+namespace rmtools;
+
+class Git {
+ public $repo_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)
+ {
+ $this->repo_url = $repo_url;
+ }
+
+ function setModule($module) {
+ $this->module = $module;
+ }
+
+ function setBranch($branch) {
+ $this->branch = $branch;
+ }
+
+ public function export($dest, $revision = false)
+ {
+ $http_url = preg_replace('/git:\/\//', 'http://', $this->repo_url);
+ $url = $http_url . '/?p=' . $this->module . ';a=snapshot;h=' .
$this->branch . ';sf=zip';
+ $dest .= '.zip';
+ wget($url, $dest);
+ return $dest;
+ }
+
+ public function info()
+ {
+ }
+
+ public function getLastCommitId()
+ {
+ $try = 3;
+ $cmd = $this->git_cmd . ' ls-remote ' . $this->repo_url . '/' .
$this->module . ' ' . $this->branch;
+ while ( $try > 0 ) {
+ $res = exec_sep_log($cmd);
+ if ($res && !empty($res['log_stdout'])) {
+ break;
+ }
+ $try--;
+ }
+ if ($res && $res['return_value'] != 0) {
+ throw new \Exception('git ls-remote failed <' . $this->repo_url . '/'
. $this->module . ' ' . $this->branch . '>, ' .
$res['log_stderr']);
+ }
+
+ $revision = preg_replace("/[\s\t]+.+/", "", $res['log_stdout']);
+ $revision = trim($revision);
+ return (string)$revision;
+ }
+}