patching local build repos

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

patching local build repos

Post by devnull » Tue Nov 13, 2018 1:23 pm

I have all of my builds, frozen files and flashing automated with bash scripts, it works very well.

But the missing part is the 'customisation' of certain files using scripts, currently after pulling the repo, I have to manually go in any update any files that I previously patched.

I see that git has a 'patches' feature that I may be able to use in bash scripts to automate my file patching before I run my builds.

Can someone let me know (with an example ??) how I can use the git patch command to automate patching of files in the build source ?

These patches will be overwritten when I pull an update, and so I would automate it in the bash script that executes my builds.

Thanks in anticipation :-)

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: patching local build repos

Post by stijn » Tue Nov 13, 2018 1:56 pm

I don't know the commands for patching, but instead of patches you could also use commits: clone from the main repository, add one or more commits on top. To update use git pull --rebase which essentially reverts your changes, pulls from the remote, then applies your commits again. Hopefully without merge conflicts :P
That's just a simple scenario, if you want to keep all of that in your own fork you can use two origins/multiple bracnhes/cherry picking/...

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: patching local build repos

Post by devnull » Tue Nov 13, 2018 2:17 pm

Thanks for helping.

So what you are suggesting is to pull, make any changes and then commit them and then by calling git pull --rebase it will downloade the latest and re-apply my patches ??

Code: Select all

1) git pull repo
2) edit files any files I choose
3) git pull --rebase
If this is all that's needed then that sounds ideal, I can modify files locally and still be able to get the latest patches ?

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: patching local build repos

Post by stijn » Tue Nov 13, 2018 2:40 pm

That's it basically yes. Here's an actual working sample:

Code: Select all

git clone https://github.com/micropython/micropython.git
cd micropython

# Make working dir 'out of date' by reverting to an an earlier version
git reset --hard HEAD 06643a0

# Do some work..
cd ports/unix
echo "#undef MICROPY_VFS_FAT" >> mpconfigport.h
echo "#define MICROPY_VFS_FAT (1)" >> mpconfigport.h

# Commit
git commit -am "Enable MICROPY_VFS_FAT"

# Check if this looks ok
git log -n2 --pretty=oneline
# Prints
#82b023793522e570c0f19d83b2c331ef535cd4df Enable MICROPY_VFS_FAT
#06643a0df4e85cbdf18549440db19dc21fccbf76 tests/extmod: Skip uselect test when CPython doesn't have poll()

# Do an update by pulling from remote
git pull --rebase
# Prints
#First, rewinding head to replay your work on top of it...
#Applying: Enable MICROPY_VFS_FAT
git log -n2 --pretty=oneline
# Prints
#dec0828c75556a5bca28dabf5c0cce0e4a2e3c97 Enable MICROPY_VFS_FAT
#d94aa577a65c10e7fe2e7ce5021b79fb30a03274 tests/import_long_dyn: Test for "import *" of a long dynamic name.
As said if you also want to keep your changes in your own fork instead of just locally, which is probably a good idea, you'd have multiple git remotes and push this master branch to your own fork. Enough tutorials for that on the web.

Post Reply