Mercurial > hgbook
comparison en/mq.tex @ 14:e2aa527bafa0
Describe unified diffs
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Mon, 03 Jul 2006 17:12:11 -0700 |
parents | 5c3966f6991b |
children | b8ac9f312a47 |
comparison
equal
deleted
inserted
replaced
13:5c3966f6991b | 14:e2aa527bafa0 |
---|---|
316 \hgcmd{qrefresh} the UI patch to save your in-progress changes, and | 316 \hgcmd{qrefresh} the UI patch to save your in-progress changes, and |
317 \hgcmd{qpop} down to the core patch. Fix the core bug, | 317 \hgcmd{qpop} down to the core patch. Fix the core bug, |
318 \hgcmd{qrefresh} the core patch, and \hgcmd{qpush} back to the UI | 318 \hgcmd{qrefresh} the core patch, and \hgcmd{qpush} back to the UI |
319 patch to continue where you left off. | 319 patch to continue where you left off. |
320 | 320 |
321 \section{Mercurial Queues and GNU patch} | |
322 | |
323 MQ uses the GNU \command{patch} command to apply patches. It will | |
324 help you to understand the data that MQ and \command{patch} work with, | |
325 and a few aspects of how \command{patch} operates. | |
326 | |
327 A patch file can start with arbitrary text; MQ uses this text as the | |
328 commit message when creating changesets. It treats the first line | |
329 that starts with the string ``\texttt{diff~-}'' as the separator | |
330 between header and content. | |
331 | |
332 MQ works with \emph{unified diffs} (\command{patch} can accept several | |
333 other kinds of diff, but MQ doesn't). A unified diff contains two | |
334 kinds of header. The \emph{file header} describes the file being | |
335 modified; it contains the name of the file to modify. When | |
336 \command{patch} sees a new file header, it looks for a file of that | |
337 name to start modifying. | |
338 | |
339 After the file header come a series of \emph{hunks}. Each hunk starts | |
340 with a header; this identifies the range of line numbers within the | |
341 file that the hunk should modify. Following the header, a hunk starts | |
342 and ends with a few lines of text from the unmodified file; these are | |
343 called the \emph{context} for the hunk. Each unmodified line begins | |
344 with a space characters. Within the hunk, a line that begins with | |
345 ``\texttt{-}'' means ``remove this line,'' while a line that begins | |
346 with ``\texttt{+}'' means ``insert this line.'' For example, a line | |
347 that is modified is represented by one deletion and one insertion. | |
348 | |
349 When \command{patch} applies a hunk, it tries a handful of | |
350 successively less accurate strategies to try to make the hunk apply. | |
351 This falling-back technique often makes it possible to take a patch | |
352 that was generated against an old version of a file, and apply it | |
353 against a newer version of that file. | |
354 | |
355 First, \command{patch} tries an exact match, where the line numbers, | |
356 the context, and the text to be modified must apply exactly. If it | |
357 cannot make an exact match, it tries to find an exact match for the | |
358 context, without honouring the line numbering information. If this | |
359 succeeds, it prints a line of output saying that the hunk was applied, | |
360 but at some \emph{offset} from the original line number. | |
361 | |
362 If a context-only match fails, \command{patch} removes the first and | |
363 last lines of the context, and tries a \emph{reduced} context-only | |
364 match. If the hunk with reduced context succeeds, it prints a message | |
365 saying that it applied the hunk with a \emph{fuzz factor} (the number | |
366 after the fuzz factor indicates how many lines of context | |
367 \command{patch} had to trim before the patch applied). | |
368 | |
369 When neither of these techniques works, \command{patch} prints a | |
370 message saying that the hunk in question was rejected. It saves | |
371 rejected hunks to a file with the same name, and an added | |
372 \filename{.rej} extension. If \hgcmd{qpush} fails to apply a patch, | |
373 it will print an error message and exit. | |
374 | |
375 \subsection{Beware the fuzz} | |
376 | |
377 While applying a hunk at an offset, or with a fuzz factor, will often | |
378 be completely successful, these inexact techniques naturally leave | |
379 open the possibility of corrupting the patched file. The most common | |
380 cases typically involve applying a patch twice, or at an incorrect | |
381 location in the file. If \command{patch} or \hgcmd{qpush} ever | |
382 mentions an offset or fuzz factor, you should make sure that the | |
383 modified files are correct afterwards. | |
384 | |
385 It's often a good idea to refresh a patch that has applied with an | |
386 offset or fuzz factor; refreshing the patch generates new context | |
387 information that will make it apply cleanly. I say ``often,'' not | |
388 ``always,'' because sometimes refreshing a patch will make it fail to | |
389 apply against a different revision of the underlying files. In some | |
390 cases, such as when you're maintaining a patch that must sit on top of | |
391 multiple versions of a source tree, it's acceptable to have a patch | |
392 apply with some fuzz, provided you've verified the results of the | |
393 patching process in such cases. | |
394 | |
321 | 395 |
322 %%% Local Variables: | 396 %%% Local Variables: |
323 %%% mode: latex | 397 %%% mode: latex |
324 %%% TeX-master: "00book" | 398 %%% TeX-master: "00book" |
325 %%% End: | 399 %%% End: |