Making WordPress.org

Changeset 10540


Ignore:
Timestamp:
12/21/2020 03:39:30 AM (4 years ago)
Author:
dd32
Message:

Theme Directory: Use svn cp during the theme import process for updates to reduce the diff size.

This is an attempt at making the diff between two versions of a theme upload visible on themes.trac again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php

    r10432 r10540  
    2323
    2424    /**
     25     * Path to `cp` script.
     26     *
     27     * @var string
     28     */
     29    const CP = '/bin/cp';
     30
     31    /**
    2532     * Path to `unzip` script.
    2633     *
     
    3744
    3845    /**
     46     * Path to a temporary SVN checkout directory.
     47     *
     48     * @var string
     49     */
     50    protected $tmp_svn_dir;
     51
     52    /**
    3953     * Path to temporary theme folder.
    4054     *
     
    7791     */
    7892    protected $trac_ticket;
     93
     94    /**
     95     * Trac changeset.
     96     *
     97     * @var string
     98     */
     99    protected $trac_changeset;
    79100
    80101    /**
     
    390411
    391412        // Create a directory with that unique name.
    392         mkdir( $this->tmp_dir, 0777 );
     413        mkdir( $this->tmp_dir );
     414        chmod( $this->tmp_dir, 0777 );
    393415
    394416        // Get a sanitized name for that theme and create a directory for it.
    395         $base_name       = $this->get_sanitized_zip_name();
    396         $this->theme_dir = "{$this->tmp_dir}/{$base_name}";
    397         mkdir( $this->theme_dir, 0777 );
     417        $base_name         = $this->get_sanitized_zip_name();
     418        $this->theme_dir   = "{$this->tmp_dir}/{$base_name}";
     419        $this->tmp_svn_dir = "{$this->tmp_dir}/svn";
     420        mkdir( $this->theme_dir );
     421        mkdir( $this->tmp_svn_dir );
     422        chmod( $this->theme_dir, 0777 );
     423        chmod( $this->tmp_svn_dir, 0777 );
    398424
    399425        // Make sure we clean up after ourselves.
     
    692718        $this->trac_ticket->diff_line = '';
    693719        if ( ! empty( $this->theme_post->max_version ) ) {
    694             $this->trac_ticket->diff_line = "\nDiff with previous version: https://themes.trac.wordpress.org/changeset?old_path={$this->theme_slug}/{$this->theme_post->max_version}&new_path={$this->theme_slug}/{$this->theme->display( 'Version' )}\n";
     720            $this->trac_ticket->diff_line = "\nDiff with previous version: [{$this->trac_changeset}] https://themes.trac.wordpress.org/changeset?old_path={$this->theme_slug}/{$this->theme_post->max_version}&new_path={$this->theme_slug}/{$this->theme->display( 'Version' )}\n";
    695721        }
    696722
     
    801827
    802828            // Make sure the ticket has not yet been resolved.
    803             if ( empty( $ticket[3]['resolution'] ) ) {
     829            if ( $ticket && empty( $ticket[3]['resolution'] ) ) {
    804830                $result    = $this->trac->ticket_update( $ticket_id, $this->trac_ticket->description, array( 'summary' => $this->trac_ticket->summary, 'keywords' => implode( ' ', $this->trac_ticket->keywords ) ), true /* Trigger email notifications */ );
    805831                $ticket_id = $result ? $ticket_id : false;
     
    903929    /**
    904930     * Add theme files to SVN.
     931     *
     932     * This attempts to do a SVN copy to allow for simpler diff views, but falls back to a svn import as an error condition.
    905933     */
    906934    public function add_to_svn() {
     935        // Either new theme upload, or we don't have the needed variables to copy it directly.
     936        if ( empty( $this->theme_post ) || empty( $this->theme_post->max_version ) ) {
     937            return $this->add_to_svn_via_svn_import();
     938        }
     939
     940        $new_version_dir = escapeshellarg( "{$this->tmp_svn_dir}/{$this->theme->display( 'Version' )}" );
     941
     942        // Theme exists, attempt to do a copy from old version to new.
     943        exec( self::SVN . " co https://themes.svn.wordpress.org/{$this->theme_slug}/ {$this->tmp_svn_dir} --depth=empty  2>&1", $output, $return_var );
     944        if ( $return_var > 0 ) {
     945            return $this->add_to_svn_via_svn_import();
     946        }
     947
     948        // Try to copy the previous version over.
     949        $prev_version = escapeshellarg( "https://themes.svn.wordpress.org/{$this->theme_slug}/{$this->theme_post->max_version}" );
     950        exec( self::SVN . " cp $prev_version $new_version_dir 2>&1", $output, $return_var );
     951        if ( $return_var > 0 ) {
     952            return $this->add_to_svn_via_svn_import();
     953        }
     954
     955        // Remove the files from the old version, so that we can track file removals.
     956        exec( self::RM . " -rf {$new_version_dir}/*" );
     957
     958        $theme_dir = escapeshellarg( $this->theme_dir );
     959        exec( self::CP . " -R {$theme_dir}/* {$new_version_dir}" );
     960
     961        // Process file additions and removals.
     962        exec( self::SVN . " st {$new_version_dir} | grep '^?' | cut -c 2- | xargs " . self::SVN . " add" );
     963        exec( self::SVN . " st {$new_version_dir} | grep '^!' | cut -c 2- | xargs " . self::SVN . " rm" );
     964
     965        // Commit it to SVN.
     966        $password = escapeshellarg( THEME_DROPBOX_PASSWORD );
     967        $message  = escapeshellarg( sprintf(
     968            __( 'New version of %1$s - %2$s', 'wporg-themes' ),
     969            $this->theme->display( 'Name' ),
     970            $this->theme->display( 'Version' )
     971        ) );
     972        exec( self::SVN . " ci --non-interactive --username themedropbox --password {$password} -m {$message} {$new_version_dir} 2>&1", $output, $return_var );
     973        if ( $return_var > 0 ) {
     974            return $this->add_to_svn_via_svn_import();
     975        }
     976
     977        if ( preg_match( '/Committed revision (\d+)./i', implode( '', $output ), $m ) ) {
     978            $this->trac_changeset = $m[1];
     979        }
     980
     981        return true;
     982    }
     983
     984    /**
     985     * Add the theme files to SVN via svn import.
     986     */
     987    function add_to_svn_via_svn_import() {
    907988        $import_msg = empty( $this->theme_post ) ?  __( 'New theme: %1$s - %2$s', 'wporg-themes' ) : __( 'New version of %1$s - %2$s', 'wporg-themes' );
    908989        $import_msg = escapeshellarg( sprintf( $import_msg, $this->theme->display( 'Name' ), $this->theme->display( 'Version' ) ) );
     
    914995        $result = exec( "{$svn} --non-interactive --username themedropbox --password {$password} --no-auto-props -m {$import_msg} import {$theme_path} {$svn_path} 2>&1" );
    915996
    916         return ( false !== strpos( $result, 'Committed revision' ) );
     997        if ( preg_match( '/Committed revision (\d+)./i', $result, $m ) ) {
     998            $this->trac_changeset = $m[1];
     999            return true;
     1000        }
     1001
     1002        return false;
    9171003    }
    9181004
Note: See TracChangeset for help on using the changeset viewer.