by lendude on 04-03-2017

Why is this needed?

Recently a change was committed that converted all array notations in core from array() to [].

Great change, but it does have some effect on patches that are currently in the issue queue. Namely, most of them will need a reroll, either because the changes themselves contain old style array's or because the patches don't apply anymore because changes were made to the files you are patching.

What to do

Manually rerolling patches can be a pain (and it's boring!). So finding a way to automate this would be great.

@joelpittet points to this converter script in the issue, so that's where I started (I created a fork that takes care of some of the steps below). The script looks inside php code and converts everything to new array notation. But patches are not php, so without some trickery, nothing happens.

My method for now:

  • Download the patch that was working before
  • Add <?php to the first line of the patch
  • run:
  • php convert.php -w path/to/file.patch
  • Wait a bit...
  • See: 16 replacements.
  • Remove the <?php tag from the patch file
  • Apply the new patch to the current HEAD

If it applies then do the following steps:

  • Rename the patch file to match the new comment number
  • Upload to Drupal.org

If it doesn't apply, try these steps suggested by @droplet

  • Checkout the commit right before Array changes, apply the patch and create a diff using -W to give it more context around the changes:
  • git checkout 3aba956a39a4852f42cad
  • git apply --index old.patch
  • git diff -W --cached > new.patch
  • Now repeat the steps from the top and see if that helps.

 

Update: I created a fork of convert on Github that takes care of most of these steps.

Now what?

Maybe something better will come along, but for now this seems to do the trick.

Update: I created a fork of convert to handle patch files using the -p switch. When using that fork the steps can be done like this :

  • Download the patch that was working before
  • run:
    php convert.php -p path/to/file.patch

    Wait a bit...

  • A file named path/to/file-array-reroll.patch should now have been created.

  • Try to apply the patch.

Update 2: There are situations where this won't cut it like the original patch only containing the trailing ) of the array(), added steps provided by @droplet to help take care of situations like that. Thanks @droplet!

About the author

Len Swaneveld (Lendude) is one of the subsystem maintainers of the Views module in Drupal 8 core.

Lendude