Difference between revisions of "How to migrate SVN patches"

From ReactOS Wiki
Jump to: navigation, search
m
Line 3: Line 3:
 
Everything in this wiki page is provided "as is", i.e. I do not take any responsibility, if it destroys your patches, your repository, your car, your house, your life, or your mom's friend's garden! And if you think it's ugly and lacking sufficient explanantion, it is YOUR responsibilty to fix that!
 
Everything in this wiki page is provided "as is", i.e. I do not take any responsibility, if it destroys your patches, your repository, your car, your house, your life, or your mom's friend's garden! And if you think it's ugly and lacking sufficient explanantion, it is YOUR responsibilty to fix that!
  
<big>What?</big>
+
<big>What is this?</big>
  
 
If you have a lot of SVN patches (like I used to have) you might wonder how to get them into the new git repository.
 
If you have a lot of SVN patches (like I used to have) you might wonder how to get them into the new git repository.
Line 9: Line 9:
 
In fact it is really messy and doesn't work as it was supposed to be, yet it can help.
 
In fact it is really messy and doesn't work as it was supposed to be, yet it can help.
  
<big>Can I improve this?</big>
+
<big>Isn't that overcomplicated?</big>
  
I don't know. If you think you can, try it. If you succeed, great. If you are a nice person, please update this wiki-page with whatever you think is useful.
+
Well, if you have 5 patches, then yes! Don't bother! Apply them manually. But if you have more than 350 patch files like I had, then this might be useful for you.
  
 
<big>How to use it</big>
 
<big>How to use it</big>
Line 23: Line 23:
 
* If you get an error, check if the scrtipt told you a commit hash. If not, it might not be in your git repo, so find the next one after it and rename your patch file accordingly
 
* If you get an error, check if the scrtipt told you a commit hash. If not, it might not be in your git repo, so find the next one after it and rename your patch file accordingly
 
* If you get the commit hash (thus the correct revision sjould have been checked out) and an error occurs, try moving the patch file into the git repo to apply manually (with TGIT). If often works. Then Commit manually.
 
* If you get the commit hash (thus the correct revision sjould have been checked out) and an error occurs, try moving the patch file into the git repo to apply manually (with TGIT). If often works. Then Commit manually.
 +
 +
<big>Can I improve this?</big>
 +
 +
I don't know. If you think you can, try it. If you succeed, great. If you are a nice person, please update this wiki-page with whatever you think is useful.
 +
 +
<big>The batch file</big>
  
 
<pre>
 
<pre>

Revision as of 20:21, 3 October 2017

Disclaimer

Everything in this wiki page is provided "as is", i.e. I do not take any responsibility, if it destroys your patches, your repository, your car, your house, your life, or your mom's friend's garden! And if you think it's ugly and lacking sufficient explanantion, it is YOUR responsibilty to fix that!

What is this?

If you have a lot of SVN patches (like I used to have) you might wonder how to get them into the new git repository. I wrote a small batch file to exactly this and it really helps, although it is not 100% fail-safe. In fact it is really messy and doesn't work as it was supposed to be, yet it can help.

Isn't that overcomplicated?

Well, if you have 5 patches, then yes! Don't bother! Apply them manually. But if you have more than 350 patch files like I had, then this might be useful for you.

How to use it

  • Put this batch file in a folder, adjust the pathes accordingly (some are not even used, I don't give...)
  • Put ONE (it might look like the script could handle multiple files, but it can't!) patch file in the same folder and run the batch script
  • The patch file must have a very specific file name: "r<svn-revision-number>-<repopath>-<patchname>.patch" (no spaces anywhere!)
  • Use the highest revision number that you can see in your patch files. This won't guarantee that it can be applied (since SVN allows to check out arbitrary revisions of each file at the same time), but is the best guess.
  • repopath is the subfolder inside the repo, where "\" is replaced by ".", e.g. "reactos.base.applications")
  • patchname is whatever you want, just without any spaces
  • If you get an error, check if the scrtipt told you a commit hash. If not, it might not be in your git repo, so find the next one after it and rename your patch file accordingly
  • If you get the commit hash (thus the correct revision sjould have been checked out) and an error occurs, try moving the patch file into the git repo to apply manually (with TGIT). If often works. Then Commit manually.

Can I improve this?

I don't know. If you think you can, try it. If you succeed, great. If you are a nice person, please update this wiki-page with whatever you think is useful.

The batch file

@echo off

setlocal EnableDelayedExpansion

set PATCH_FILE_PATH="D:\Dev\ReactOS\Patches\Diffs\test"
set DONE_PATH="D:\Dev\ReactOS\Patches\Diffs\done"
set FAILED_PATH="D:\Dev\ReactOS\Patches\Diffs\failed"
set GIT_REPO_PATH="D:\Dev\ReactOS\git.reactos.org"

cd %GIT_REPO_PATH%

:. Chlean the repo
git checkout .
git clean -d -f

:: Process all patches
for /f %%F in ('dir /b /a-d /one %PATCH_FILE_PATH%\r?????*.patch 2^>nul') do (

    :: Set the patch file name
    set PATCH_FILE=%%F
    set PATCH_FILE1=!PATCH_FILE:~1!
    set PATCH_FILE2=!PATCH_FILE1:.patch=!

    :: Extract some fields from the name
    for /F "tokens=1,2,3 delims=-" %%a in ("!PATCH_FILE2!") do (
        set REVISION=%%a
        set PATCH_DIR0=%%b
        set BRANCH_NAME=%%c
    )

    set PATCH_DIR=!PATCH_DIR0:.=/!
    echo Processing file !PATCH_FILE!
    echo   - Revision: !REVISION!, Directory: !PATCH_DIR!, Branch name: !BRANCH_NAME!)

    :: Find the commit with the desired SVN revision
    for /f %%h in ('git --no-pager log --all "--pretty=%%H" "--grep=file:///srv/svn/reactos/trunk@!REVISION! "') do set COMMIT_HASH=%%h
    echo Using commit hash: !COMMIT_HASH!

    :: Checkout the revision
    git checkout --detach !COMMIT_HASH!

    :: Apply the patch
    git apply -p0 --directory=!PATCH_DIR! -v !PATCH_FILE_PATH!\!PATCH_FILE! && goto Success

        echo Failed to apply patch!
        :: move !PATCH_FILE_PATH!\!PATCH_FILE! !FAILED_PATH!\
        goto Next

:Success
    :: Create the new branch
    git branch patchfiles/!BRANCH_NAME!
    git checkout patchfiles/!BRANCH_NAME!

    :: Commit to new branch
    git add .
    git commit --all --message="Patch from file !PATCH_FILE! on r!REVISION!"

    :: Move file away
    move !PATCH_FILE_PATH!\!PATCH_FILE! !DONE_PATH!\

:Next
    echo -------------------------------------
    pause
)

:: for /f %F in ('dir /b /a-d /one D:\Dev\ReactOS\Patches\Diffs\r?????*.patch 2^>nul') do @set FILE=%F && @set REVISION=%FILE:~1,5%

echo Done!