MarkAHershberger has uploaded a new change for review.

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


Change subject: Clean up
......................................................................

Clean up

* Produce gitreview for branch
* Don't rely on “master” since some won't have it

Change-Id: I3e02be1b9a0c220518e8ec6a249080038af2d17e
---
M make-extension-branches/make-extension-branches
1 file changed, 66 insertions(+), 18 deletions(-)


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

diff --git a/make-extension-branches/make-extension-branches 
b/make-extension-branches/make-extension-branches
index 768c9ca..8631e10 100755
--- a/make-extension-branches/make-extension-branches
+++ b/make-extension-branches/make-extension-branches
@@ -108,7 +108,7 @@
                        }
 
                        if ( !$this->conf->reuseDir || !file_exists( $name ) ) {
-                               $this->execCmd( 'git', 'clone', '-q', $url, 
'-b', 'master', $name );
+                               $this->execCmd( 'git', 'clone', '-q', $url, 
$name );
                        }
 
                        $this->chdir( $name );
@@ -120,7 +120,11 @@
                                echo "Skipping $extRepo: Branch exists 
already\n";
                                continue;
                        }
-                       $commit = $this->execReadCmd( 'git', 'rev-list', '-n', 
'1', '--before', $this->opts->branchDate, 'master' );
+                       $commit = false;
+                       if( array_filter( $this->getBranches(), function($b) { 
return $b === "master" || $b === "* master"; } ) ) {
+                               list( $exitcode, $commit ) = 
$this->execReadCmd( 'git', 'rev-list', '-n', '1', '--before',
+                                       $this->opts->branchDate, 'master' );
+                       }
                        if ( !$commit ) {
                                echo "Skipping $extRepo: Repo does not have a 
commit before the branch date\n";
                                continue;
@@ -128,8 +132,12 @@
                        if ( $this->conf->verbose ) {
                                echo "... $extRepo: Branching $branchName at 
$commit\n";
                        }
+                       $match = array_filter( $this->getBranches(), 
function($l) use ($branchName) { return trim( $l ) === $branchName; } );
+                       if ( count( $match ) ) {
+                               $this->execWriteCmd( 'git', 'branch', '-D', 
$branchName );
+                       }
                        $this->execCmd( 'git', 'checkout', '-q', $commit );
-                       exec( 'git branch ' . escapeshellarg( $branchName ) . ' 
2>&1', $out, $exitcode );
+                       $exitcode = $this->execWriteCmd( 'git', 'branch', 
$branchName );
                        if ( $exitcode != 0 ) {
                                if ( $exitcode != 128 || !$this->conf->reuseDir 
) {
                                        echo "Skipping $extRepo: Creating 
branch failed (exit code: $exitcode)\n";
@@ -138,8 +146,12 @@
                        }
 
                        # Intermediate commit & fixes
-                       $this->fixGitReview( $branchName );
-                       $this->execWriteCmd( 'git', 'commit', '-a', '-q', '-m', 
"Creating new {$branchName} branch" );
+                       if( $this->fixGitReview( $branchName, $name ) ) {
+                               $this->execWriteCmd( 'git', 'commit', '-a', 
'-q', '-m', "Creating new {$branchName} branch" );
+                       } else {
+                               echo "Trouble with $name\n";
+                               exit;
+                       }
 
                        # Final push to repo for this extension
                        $this->execWriteCmd( 'git', 'push', 'origin', 
"$branchName:refs/heads/$branchName" );
@@ -174,34 +186,66 @@
                $cmd = implode( ' ', array_map( 'escapeshellarg', $args ) );
                if ( $this->conf->verbose ) {
                        echo "[exec] $cmd\n";
+                       if( ob_get_contents() ) {
+                               ob_clean();
+                       }
                }
                $ret = null;
                passthru( $cmd, $ret );
                if ( $ret ) {
+                       $cont = ob_get_contents();
                        $this->error( $args[0] . " exit with status $ret\n" );
+                       if( $cont ) {
+                               ob_clean();
+                               echo $cont;
+                       }
+                       exit(1);
                }
+               return $ret;
        }
 
        protected function execReadCmd( /*...*/ ) {
-               $cmd = implode( ' ', array_map( 'escapeshellarg', 
func_get_args() ) );
-               if ( $this->conf->verbose ) {
-                       echo "[exec] $cmd\n";
-               }
-               $ret = null;
+               $args = func_get_args();
                ob_start();
-               passthru( $cmd, $ret );
+               $ret = call_user_func_array( array( $this, 'execCmd' ), $args );
                $output = ob_get_contents();
                ob_end_clean();
-               if ( $ret ) {
-                       $this->error( $args[0] . " exit with status $ret\n" );
-               }
-               return trim( $output );
+               return array( $ret, trim( $output ) );
        }
 
-       protected function fixGitReview( $branchName ) {
+       protected function fixGitReview( $branchName, $project ) {
+               if ( !file_exists( ".gitreview" ) ) {
+                       $review = array();
+                       $review[] = "[gerrit]";
+                       $review[] = "host=gerrit.wikimedia.org";
+                       $review[] = "port=29418";
+                       $review[] = "project=mediawiki/extensions/$project.git";
+                       $review[] = "defaultbranch=$branchName";
+                       $review[] = "defaultrebase=0";
+
+                       echo "No .gitreview! Creating...\n";
+                       $ret = file_put_contents( ".gitreview", implode( "\n", 
$review ) );
+                       if ( $ret === false ) {
+                               $err = error_get_last();
+                               $this->error( "Error writing .gitreview: 
{$err['message']}\n" );
+                               return false;
+                       }
+
+                       $this->execCmd( "git", "add", ".gitreview" );
+                       return true;
+               }
+               echo "Fixing .gitreview\n";
+
                $s = file_get_contents( ".gitreview" );
                $s = str_replace( "defaultbranch=master", 
"defaultbranch={$branchName}", $s );
-               file_put_contents( ".gitreview", $s );
+               $ret = file_put_contents( ".gitreview", $s );
+               if ( $ret === false ) {
+                       $err = error_get_last();
+                       $this->error( "Error writing .gitreview: 
{$err['message']}\n" );
+                       return false;
+               }
+               $this->execCmd( "git", "add", '-f', ".gitreview" );
+               return true;
        }
 
        /**
@@ -219,6 +263,10 @@
 
        protected function error( $msg ) {
                fwrite( STDERR, "$msg\n" );
-               exit( 1 );
+       }
+
+       protected function getBranches( ) {
+               list( $exitcode, $output ) = $this->execReadCmd( 'git', 
'branch', '-a' );
+               return array_map( "trim", explode( "\n", $output ) );
        }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e02be1b9a0c220518e8ec6a249080038af2d17e
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