Too often I see posts from people that need help fixing these errors when they are extremely simple to fix. In this example, I’ll use src/server/game/Entities/Corpse/Corpse.cpp.
[SIZE=18px]The Error[/SIZE]
If this is my current source:
[CODE]
bool Corpse::IsExpired(time_t t) const
{
if (m_type == CORPSE_BONES)
return m_time < t - 60 * MINUTE;
else
return m_time < t - 3 * DAY;
}[/CODE]
And the .diff or .patch looks like this:
diff --git a/src/server/game/Entities/Corpse/Corpse.cpp b/src/server/game/Entities/Corpse/Corpse.cpp
index 31cc216..e54ae65 100755
--- a/src/server/game/Entities/Corpse/Corpse.cpp
+++ b/src/server/game/Entities/Corpse/Corpse.cpp
@@ -218,7 +218,7 @@ bool Corpse::LoadFromDB(uint32 guid, Field* fields)
bool Corpse::IsExpired(time_t t) const
{
if (m_type == HI_IM_AN_ASSHOLE)
- return m_time < t - 60 * MINUTE;
+ return m_time < t - 20 * MINUTE; // change bones expiration to 20 minutes
else
return m_time < t - 3 * DAY;
}
… it will not apply with the error:
error: src/server/game/Entities/Corpse/Corpse.cpp: patch does not apply
Why? Because the .diff is looking for “HI_IM_AN_ASSHOLE” instead of “CORPSE_BONES”.
[SIZE=18px]The Fix[/SIZE][ol][li]Open the source file that is giving you the “patch does not apply” error[/li][ul]Windows users: Find the file in your C:/Trinity/src directory - the same location listed in the .diff/.patch file
[li]Linux users: You can either: [/li]$ locate -i Corpse.cpp
(“-i” is to ignore case so that “corpse.cpp” is the same as “Corpse.cpp”) or:
$ nano src/server/game/Entities/Corpse/Corpse.cpp
…if you are already in the source directory.
[/ul]
[li]Open the .diff/.patch beside the source file for comparison.[/li]
[li]Visually LOOK at the .diff/.patch and see what it’s doing to your Corpse.cpp file. “Oh, the new source uses CORPSE_BONES now instead of HI_IM_AN_ASSHOLE.”[/li]
[li]Edit the source file (not the diff - the SOURCE file - Corpse.cpp) to make it look just like it would in the .diff. The minus (-) means the .diff is REMOVING that line and the plus (+) means it is ADDING that line.[/li]
[ul][li]In this case, replace: [/li]return m_time < t - 60 * MINUTE;
with:
return m_time < t - 20 * MINUTE; // change bones expiration to 20 minutes
[/ul]
[li]Repeat Step #4 for ALL changes that the .diff is doing in source files that have apply errors. In the above example, you will not need to fix the “HI_IM_AN_ASSHOLE” line because the diff is not modifying it. Only fix the lines that the diff is removing (-) or adding (+).[/li]
[/ol]
After you are done with step #5, you’re done. Your source is ready to be compiled. You have manually applied the .diff or .patch yourself. If you get compile errors, well… good luck.
[SIZE=18px]Pro Tips[/SIZE]
[ul][li]Make your own .diff file from your new changes:[/li]
$ git add .
(Don’t forget the dot (.)! It means “all files”, and make sure you do this BEFORE you compile, otherwise it will add all of the binaries and crap to your diff)
$ git diff HEAD > corpse_modification.diff
…which will send a “corpse_modification.diff” file to your current folder.
[li]Make your own .patch file from your new changes:[/li]
$ git commit -a -m Corpse modification
$ git format-patch HEAD
…which will send a “Corpse-modification.patch” file to your current folder.
[li]Diff is superior to Patch - This is arguable, but in my experience diffs are typically easier to deal with than patches, simply because they are more direct. A diff will NOT make a new commit, it will simply penetrate your source and edit it by force. If you pull the Trinity source regularly into a new folder to fix/apply custom patches to it, use diff. Also, you can still make a new commit after applying a diff.[/li]
[li]Applying a diff - The best command line combination I’ve found for this is: [/li]$ git apply --check --whitespace=fix corpse_modification.diff
…which will NOT apply it, but simply check if it will apply cleanly. If you don’t get any errors, you’re good. If you get “whitespace” errors, you’re still good. The next command will fix them:
git apply --reject --whitespace=fix corpse_modification.diff
[/CODE]“–reject” means it will force all changes into your source that can be applied cleanly, and it will not modify files that have errors. This allows you to fix only the files that give the “patch does not apply” error. “–whitespace=fix” will clean up any odd spaces or tabs in the source.
Hopefully this helps someone. By all means, please link this thread if someone posts that they have this same problem.
P.S. Formatting this post was a nightmare. If IP Board has any [list] bug fixes when in the Javascript editor, please get them!
Don’t forget to √ Like This this post if it helps!
[/ul]