MarkAHershberger has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/92043


Change subject: Allow reuse of extension checkout
......................................................................

Allow reuse of extension checkout

Change-Id: Iba45d1f558b024e9feb2277443280bb232c1aca2
---
M make-extension-branches/default.conf
M make-extension-branches/make-extension-branches
2 files changed, 35 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/release 
refs/changes/43/92043/1

diff --git a/make-extension-branches/default.conf 
b/make-extension-branches/default.conf
index 0a25916..81e28ee 100644
--- a/make-extension-branches/default.conf
+++ b/make-extension-branches/default.conf
@@ -8,6 +8,12 @@
 
 $conf->verbose = false;
 
+// Directory to use for the checkouts
+$conf->buildDir = sys_get_temp_dir() . '/make-extension-branches';
+
+// Do not reuse the directory if it already exists
+$conf->reuseDir = false;
+
 // Array of repository names. Will substituted in extRepoUrlFormat
 $conf->extRepos = false;
 
diff --git a/make-extension-branches/make-extension-branches 
b/make-extension-branches/make-extension-branches
index af5dada..768c9ca 100755
--- a/make-extension-branches/make-extension-branches
+++ b/make-extension-branches/make-extension-branches
@@ -49,12 +49,11 @@
 
 class MakeExtensionBranches {
 
-       protected $codeDir, $buildDir;
+       protected $codeDir;
        protected $conf, $opts;
 
        public function __construct( $opts ) {
                $this->codeDir = __DIR__;
-               $this->buildDir = sys_get_temp_dir() . 
'/make-extension-branches';
 
                require "{$this->codeDir}/default.conf";
                if ( file_exists( "{$this->codeDir}/local.conf" ) ) {
@@ -81,22 +80,37 @@
 
        public function start() {
                $this->setup();
-               $this->setupBuildDirectory();
+               if ( !$this->conf->reuseDir ) {
+                       $this->setupBuildDirectory( $this->conf->buildDir );
+               }
 
                $branchName = $this->opts->branchName;
                foreach ( $this->conf->extRepos as $extRepo ) {
                        // Move back to the build dir in each loop,
                        // otherwise we'll get build/AntiBot/CategoryTree/.. 
instead of build/AntiBot, build/CategoryTree, ..
-                       $this->chdir( $this->buildDir );
+                       $this->chdir( $this->conf->buildDir );
 
                        if ( $extRepo === 'mediawiki/extensions' ) {
                                // Skip the meta repository
                                continue;
                        }
+                       $name = substr( $extRepo, strlen( 
"mediawiki/extensions/" ) );
                        echo "... $extRepo\n";
                        $url = str_replace( '{repository}', $extRepo, 
$this->conf->extRepoUrlFormat );
-                       $name = basename( $extRepo );
-                       $this->execCmd( 'git', 'clone', '-q', $url, '-b', 
'master', $name );
+                       if ( file_exists( $name ) ) {
+                               if ( !$this->conf->reuseDir ) {
+                                       echo "$name already exists.  Can't 
continue.";
+                                       exit(1);
+                               } elseif ( !is_dir( "$name/.git" ) ) {
+                                       echo "$name is not a git repo.  Can't 
continue.";
+                                       exit(1);
+                               }
+                       }
+
+                       if ( !$this->conf->reuseDir || !file_exists( $name ) ) {
+                               $this->execCmd( 'git', 'clone', '-q', $url, 
'-b', 'master', $name );
+                       }
+
                        $this->chdir( $name );
 
                        $out = $exitcode = null;
@@ -117,8 +131,10 @@
                        $this->execCmd( 'git', 'checkout', '-q', $commit );
                        exec( 'git branch ' . escapeshellarg( $branchName ) . ' 
2>&1', $out, $exitcode );
                        if ( $exitcode != 0 ) {
-                               echo "Skipping $extRepo: Creating branch failed 
(exit code: $exitcode)\n";
-                               continue;
+                               if ( $exitcode != 128 || !$this->conf->reuseDir 
) {
+                                       echo "Skipping $extRepo: Creating 
branch failed (exit code: $exitcode)\n";
+                                       continue;
+                               }
                        }
 
                        # Intermediate commit & fixes
@@ -132,12 +148,12 @@
                echo "Done!\n";
        }
 
-       protected function setupBuildDirectory() {
-               if ( is_dir( $this->buildDir ) ) {
-                       $this->execCmd( 'rm', '-rf', '--', $this->buildDir );
+       protected function setupBuildDirectory( $buildDir ) {
+               if ( is_dir( $buildDir ) ) {
+                       $this->execCmd( 'rm', '-rf', '--', $buildDir );
                }
-               if ( !mkdir( $this->buildDir ) ) {
-                       $this->error( "Unable to create directory 
{$this->buildDir}" );
+               if ( !mkdir( $buildDir ) ) {
+                       $this->error( "Unable to create directory {$buildDir}" 
);
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/92043
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba45d1f558b024e9feb2277443280bb232c1aca2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/release
Gerrit-Branch: master
Gerrit-Owner: MarkAHershberger <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to