Difference between revisions of "Patch"

From Sega Retro

old>Kram1024
 
(37 intermediate revisions by 7 users not shown)
Line 1: Line 1:
==NAME==
+
{{RetroCDN}}
patch - apply a diff file to an original
+
A '''patch''' is a file or set of files that is used to modify another file or set of files. It may be distributed as either a standalone program, or a data file which requires a specialised program to apply the patch.
  
==SYNOPSIS==
+
==ROM patches==
'''patch''' [''options''] [''originalfile'' [''patchfile'']]
+
The hacking scene has seen several types of patches, including [[IPS]] and [[RXL]], used for [[ROM hack]]s. Both these types of patch require programs (for example [[StealthPatch]]) to modify the target file. Patches were used during a time when downloading full ROMs would be a lengthy task for slow Internet connections, but with the advent of high-speed Internet connections, patches have fallen into disuse as Sonic-game hackers have made fully modified ROMs available.
  
but usually just
+
ROM patches are still utilized (and often, required) by other communities, due to precautions related to copyright.
  
'''patch''' -p''num'' <''patchfile''
+
==Software patches==
 +
More complicated games and programs require more complicated patches. Most installed games consist of many files and folders, so something as simple as an IPS patch would be inappropriate. In these cases, standalone programs are used to modify or replace several files automatically. If a game has a fault which was not detected in the [[beta]] testing phase, the developer will typically distribute a patch to correct it.
  
==DESCRIPTION==
+
[[Category:Technical information]]
'''patch'''  takes  a  patch  file ''patchfile'' containing a difference listing produced by the '''diff''' program and applies those differences to one or more original files, producing patched versions.  Normally  the  patched versions are put in place of the originals.  Backups can be made; see the '''-b''' or '''--backup option'''.  The names of the files  to  be  patched  are  usually taken  from  the patch file, but if there’s just one file to be patched it can specified on the command line as ''originalfile''.
 
 
 
Upon startup, patch attempts to determine the type of the diff listing, unless overruled by a  '''-c''' ('''--context'''), '''-e''' ('''--ed'''), '''-n''' ('''--normal'''), or '''-u''' (--unified) option.  Context diffs (old-style, new-style, and unified) and normal diffs are applied by the  '''patch'''  program  itself, while '''ed''' diffs are simply fed to the '''ed'''(1) editor via a pipe.
 
 
 
'''patch''' tries to skip any leading garbage, apply the diff, and then skip any trailing garbage.  Thus you could feed an article or message containing a diff listing to '''patch''', and it should work.  If the entire diff is indented by a consistent amount, or if a context diff contains lines ending in CRLF or is encapsulated one or more times by prepending "'''-'''  " to lines starting with "'''-'''" as specified by Internet RFC 934, this is taken into account.
 
 
 
With context diffs, and to a lesser extent with normal diffs, '''patch''' can detect when the line numbers mentioned in the patch are incorrect, and attempts to find the  correct  place to apply each hunk of the patch.  As a first guess, it takes the line number mentioned for the hunk, plus or minus any offset used in applying the previous hunk.  If that is not the correct place, '''patch''' scans both forwards and backwards for a set of lines matching the context given in the hunk.  First '''patch''' looks for a place where all lines of the context match.  If no such place is found, and it’s a context diff, and the maximum fuzz factor is set to 1 or more, then another scan takes place ignoring the first and last line of context.  If that fails, and the maximum fuzz factor is set to 2 or more, the first two and last two lines of context are ignored, and another scan is made.  (The default maximum fuzz factor  is 2.)  If '''patch''' cannot find a place to install that hunk of the patch, it puts the hunk out to a reject file, which normally is the name of the output file plus a  '''.rej'''  suffix, or '''#''' if '''.rej''' would generate a file name that is too long (if even appending the single character '''#''' makes the file name too long, then '''#''' replaces the file name’s last  character).  (The  rejected hunk comes out in ordinary context diff form regardless of the input patch’s form.  If the input was a normal diff, many of the contexts are  simply  null.)  The line numbers on the hunks in the reject file may be different than in the patch file: they reflect the approximate location patch thinks the failed hunks belong in the  new file rather than the old one.
 
 
 
As each hunk is completed, you are told if the hunk failed, and if so which line (in the new file) '''patch''' thought the hunk should go on.  If the hunk is installed at a different line from the line number specified in the diff you are told the offset.  A single large offset may indicate that a hunk was installed in the wrong place.  You are also told if a fuzz factor was used to make the match, in which case you should also be slightly suspicious.  If the '''--verbose''' option is given, you are also told about hunks that match exactly.
 

Latest revision as of 07:19, 7 July 2022

Retrocdn-round.svg
This file or page has been flagged for relocation to Retro CDN, the Wikimedia Commons-esque service for all Retro wikis. This message is for the benefit of Sega Retro wiki staff.

A patch is a file or set of files that is used to modify another file or set of files. It may be distributed as either a standalone program, or a data file which requires a specialised program to apply the patch.

ROM patches

The hacking scene has seen several types of patches, including IPS and RXL, used for ROM hacks. Both these types of patch require programs (for example StealthPatch) to modify the target file. Patches were used during a time when downloading full ROMs would be a lengthy task for slow Internet connections, but with the advent of high-speed Internet connections, patches have fallen into disuse as Sonic-game hackers have made fully modified ROMs available.

ROM patches are still utilized (and often, required) by other communities, due to precautions related to copyright.

Software patches

More complicated games and programs require more complicated patches. Most installed games consist of many files and folders, so something as simple as an IPS patch would be inappropriate. In these cases, standalone programs are used to modify or replace several files automatically. If a game has a fault which was not detected in the beta testing phase, the developer will typically distribute a patch to correct it.