While working on #22336: Move all core Drupal files under a /core folder to improve usability and upgrades we've hit the patch upload limit on d.o currently at 3MB. Because we move a lot of files in this issue (pretty much all core files are moved into a core directory), the regular patch syntax will be very verbose and display 2 hunks for each file for the deletion and the addition into the destination directory. While discussing with rfay on #drupal-infrastructure, we thought git would be smart enough to generate a patch that only stores a move instructions as opposed to the verbose old fashion diff syntax. But it does not seem to be the case. Here are the steps to reproduce with a simple example in core:

git checkout 8.x
git checkout -b move
git mv README.txt README2.txt 
git commit -m "move README file"
git fetch origin
git rebase origin/8.x
git format-patch origin/8.x
more 0001-move-README-file.patch 

Comments

rfay’s picture

subscribe - interested

Damien Tournoud’s picture

You want to add --find-renames and --find-copies to git format-patch. In that case, the patch can only be applied with git apply / git am.

Damien Tournoud’s picture

This doesn't work as it should on Scor's mega patch, for some reason.

My version of Git is only able to find pure renames, not renames + modify on this patch, even if this works on simpler patches.

scor’s picture

--find-renames and --find-copies are not supported in git 1.7.3.2 but you can use -C -M instead. it works, thanks DamZ.

To get the smallest patch, it is best to make the move operations and the file changes in two separate commits:
- Files which are moved and have changes in the same commit will not go through the git mv shortcut, and will get their content displayed twice through the verbose diff. From 19MB, the patch at goes down to 7MB.
- With 2 separate commits, the command git format-patch -C -M origin/8.x --stdout will pack the 2 commits into a single file. (while git format-patch alone would generates 2 files, which might be tricky to integrate with pifr). Patch size is now 473KB.

UPDATE: patch uploaded at #22336-138: Move all core Drupal files under a /core folder to improve usability and upgrades

eliza411’s picture

Status: Active » Fixed

This looks fixed. If I'm wrong, please re-open.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.