Author Topic: Patch utitilities and applying patches  (Read 27510 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Patch utitilities and applying patches
« on: August 13, 2012, 05:37:42 pm »
ollydbg:
What patch executable are you using?
All I've tried crashed badly when used with linux generated patches.
I use the patch command shipped with MSYS.
I always download the MSYS zip file from mingw64 site(some one has maintain a full msys environment which contains everything), see:MSYS-20111123.zip
I have one issue about this patch utility in msys:
After applying any patches by this patch utility, all the changed files are having the "LF" EOL, this is not desired, I need to manually change those files to "CR LF" by Notepad++ or other tools.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Patch utitilities and applying patches
« Reply #1 on: August 13, 2012, 06:54:41 pm »
After applying any patches by this patch utility, all the changed files are having the "LF" EOL, this is not desired, I need to manually change those files to "CR LF" by Notepad++ or other tools.
Why do you not use C::B for this?
Set line-ending to cr-lf and check "Make EOLs consistent", works best with editor-tweaks-plugin, but should also work with plain editor, if I remember correctly.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Patch utitilities and applying patches
« Reply #2 on: August 17, 2012, 06:16:34 am »
After applying any patches by this patch utility, all the changed files are having the "LF" EOL, this is not desired, I need to manually change those files to "CR LF" by Notepad++ or other tools.
Why do you not use C::B for this?
Set line-ending to cr-lf and check "Make EOLs consistent", works best with editor-tweaks-plugin, but should also work with plain editor, if I remember correctly.
C::B can do this, but I need to open the configure dialog to do this, in notepad++, it is just a menu item, then I can quickly convert the EOL to any types.

I'm not familiar with editor-tweaks-plugin(with the latest nightly build), but I see its dialog only contains one item: see the image below:


I don't know how any other editor-tweak plugin's feature. :)

I think the final solution is patch the "patch utility", and let it handle CR LF correctly. I will report this to their maillist.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Patch utitilities and applying patches
« Reply #3 on: August 17, 2012, 06:24:31 am »
Look into "Edit->Editor Tweaks" .

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Patch utitilities and applying patches
« Reply #4 on: August 17, 2012, 07:09:45 am »
Look into "Edit->Editor Tweaks" .
Ha, thanks, I would like to suggest adding some sub-menus like:
Code
Convert to LF(Linux)
Convert to CRLF(Windows)
Convert to CR(Mac)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Patch utitilities and applying patches
« Reply #5 on: August 17, 2012, 12:54:20 pm »
Firstly I report a feature request in patch utility's official site: https://savannah.gnu.org/bugs/?37128 , but finally they said it was already implemented. ;)

Now, I can nicely apply a patch (created from git) to svn repo.

Here is the steps: suppose you create patch from git(I use tortoisegit)
1, if you patch file has LF of EOL, convert it to CRLF. This can be done by Notepad++, Codeblocks editor, or any tools you like
2, run the patch command by:
Code
patch --binary <test.patch
This works fine if your original source file is CRLF, the result file is still CRLF.

See the patch utility document:
http://linux.die.net/man/1/patch
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Patch utitilities and applying patches
« Reply #6 on: August 17, 2012, 02:05:11 pm »
By the way, if you use svn 1.7, the command:
Code
svn patch test.patch
works for any line ending combination (at least, it has never had problems for me when mixing line endings).

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Patch utitilities and applying patches
« Reply #7 on: August 17, 2012, 02:50:21 pm »
By the way, if you use svn 1.7, the command:
Code
svn patch test.patch
works for any line ending combination (at least, it has never had problems for me when mixing line endings).
Thanks.
I have not used the svn command line. I use TortoiseGit and TortoiseSVN. But I found that TortoiseSVN can not apply the patch generated by TortoiseGit. (For TortoiseSVN, when it need to apply a patch, it must have a exact svn revision information in the patch file, otherwise, it will report a failure, but the patch utility in MSYS works fine in this case)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Patch utitilities and applying patches
« Reply #8 on: August 17, 2012, 03:18:34 pm »
(For TortoiseSVN, when it need to apply a patch, it must have a exact svn revision information in the patch file, otherwise, it will report a failure)
Haha - this sounds familiar... probably you should file a bug report to the TortoiseSVN guys, too - lets see how fast they can fix it compared to my experience... 8)

BTW: Taking the risk to sound monotonous: I believe it is no good in general to create/provide patches based on a GIT repo for SVN. As you all see it is simply not compatible. However, I guess I am alone on that floor... :-\
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Patch utitilities and applying patches
« Reply #9 on: August 17, 2012, 03:39:00 pm »
Haha - this sounds familiar... probably you should file a bug report to the TortoiseSVN guys, too - lets see how fast they can fix it compared to my experience... 8)
Are you saying that smartsvn supports pure git patches now? The patches provided by Jens are not pure git patches, but patches which work with tortoisesvn (at least the once created by the script I use work perfectly).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Patch utitilities and applying patches
« Reply #10 on: August 17, 2012, 03:54:20 pm »
Hi, Alpha, it looks like the svn command line can accept the pure patch file generated from tortoiseGit.
I just create a dummy patch file from tortoisegit (I create from the c::b git clone), see below:
Code
 src/sdk/annoyingdialog.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/sdk/annoyingdialog.cpp b/src/sdk/annoyingdialog.cpp
index c6a5a29..b206647 100644
--- a/src/sdk/annoyingdialog.cpp
+++ b/src/sdk/annoyingdialog.cpp
@@ -62,6 +62,8 @@ AnnoyingDialog::AnnoyingDialog(const wxString& caption, const wxString& message,
     wxString bTxt1;
     wxString bTxt2;
     wxString bTxt3;
+    
+    adding many comments here to test the patch utility;
 
     if(style == OK || style == ONE_BUTTON)
     {
@@ -91,6 +93,8 @@ AnnoyingDialog::AnnoyingDialog(const wxString& caption, const wxString& message,
         cbThrow(wxString(_T("Fatal error:\nUndefined style in dialog ")) << caption);
 
     wxSizer* buttonSizer = 0;
+    
+    say hello;
     if (style < ONE_BUTTON) // standard buttons? use wxStdDialogButtonSizer
     {
         wxStdDialogButtonSizer *buttonArea = new wxStdDialogButtonSizer();


Then, I can use the command line:
Code
E:\code\cb\cleantrunk>svn patch test.patch --strip 1
U         src\sdk\annoyingdialog.cpp
Look, everything works fine.

BTW:
I test several cases: the file "test.patch" can have either CRLF or LF format, when applied, the result file is CRLF, this is because my local c::b svn repo is all CRLF.

BTW2:
I'm using the svn command tool, which is:
Quote
E:\code\cb\cleantrunk>svn --version
svn, version 1.7.1-SlikSvn-1.7.1-WIN32 (SlikSvn/1.7.1) WIN32
   compiled Oct 26 2011, 13:38:01

Copyright (C) 2011 The Apache Software Foundation.
This software consists of contributions made by many people; see the NOTICE
file for more information.
Subversion is open source software, see http://subversion.apache.org/

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
  - handles 'http' scheme
  - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
  - with Cyrus SASL authentication
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme
* ra_serf : Module for accessing a repository via WebDAV protocol using serf.
  - handles 'http' scheme
  - handles 'https' scheme

BTW3:
I tried the TortoiseSVN to apply the patch file, then it will shown a failure dialog "rejected patch hunks for XXXXX". :(.

As a conclusion: svn command line is better than the patch utility. :), the patch utility is better than tortoisesvn.

EDIT:
If you use tortoiseSVN to apply the patch, after its failure, You will have some dummy folder named "b", "b/src", "b/src/sdk" created. :(

« Last Edit: August 17, 2012, 04:23:50 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Patch utitilities and applying patches
« Reply #11 on: August 17, 2012, 05:36:50 pm »
I did further test, it looks like the patch utility is much robust, if I have such patch file generated from git:
Code
 src/sdk/hi.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/sdk/hi.txt b/src/sdk/hi.txt
new file mode 100644
index 0000000..3b9f311
--- /dev/null
+++ b/src/sdk/hi.txt
@@ -0,0 +1 @@
+hihihi
\ No newline at end of file


Only the patch utility works, and both TortoiseSVN and the SVN command line fail.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Patch utitilities and applying patches
« Reply #12 on: August 20, 2012, 09:28:33 am »
FYI:

I report this issue to TortoiseSVN maillist, and now, they have fixed in the subversion library, see the change:

http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/parse-diff.c?view=log

Not sure how long this will come into TortoiseSVN, as TortoiseSVN internally use subversion library.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.