Mercurial > hgbook
changeset 338:cb130184dd23
more mq.tex
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 10 Apr 2008 23:41:57 +0900 |
parents | b8791971ba65 |
children | 12dde4918d24 |
files | ja/mq.tex |
diffstat | 1 files changed, 126 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/ja/mq.tex Mon Mar 31 17:28:24 2008 +0900 +++ b/ja/mq.tex Thu Apr 10 23:41:57 2008 +0900 @@ -835,90 +835,134 @@ $B$O%Q%9L>$r$3$N7A<0$G@8@.$7!$(B\hgcmd{import}$B%3%^%s%I$H(BMQ$B$O%9%H%j%C%W%+%&%s(B $B%H(B1$B$rA0Ds$H$7$F$$$k!%(B -If you receive a patch from someone that you want to add to your patch -queue, and the patch needs a strip count other than one, you cannot -just \hgxcmd{mq}{qimport} the patch, because \hgxcmd{mq}{qimport} does not yet -have a \texttt{-p} option (see~\bug{311}). - -Your best bet is to -\hgxcmd{mq}{qnew} a patch of your own, then use \cmdargs{patch}{-p\emph{N}} -to apply their patch, followed by \hgcmd{addremove} to pick up any -files added or removed by the patch, followed by \hgxcmd{mq}{qrefresh}. -This complexity may become unnecessary; see~\bug{311} for details. +%If you receive a patch from someone that you want to add to your patch +%queue, and the patch needs a strip count other than one, you cannot +%just \hgxcmd{mq}{qimport} the patch, because \hgxcmd{mq}{qimport} does not yet +%have a \texttt{-p} option (see~\bug{311}). Your best bet is to +%\hgxcmd{mq}{qnew} a patch of your own, then use \cmdargs{patch}{-p\emph{N}} +%to apply their patch, followed by \hgcmd{addremove} to pick up any +%files added or removed by the patch, followed by \hgxcmd{mq}{qrefresh}. +%This complexity may become unnecessary; see~\bug{311} for details. -$BC/$+$+$i%Q%C%A$r<u$1<h$j!$%Q%C%A%-%e!<$KDI2C$7$h$&$H$9$k;~!$%Q%C%A%+%&%s(B -$B%H$,(B1$B0J30$G$"$l$PC1$K(B\hgxcmd{mq}{qimport}$B$9$k$3$H$O$G$-$J$$!%$3$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$J$/$J$k$O$:$@!J(B\bug{311}$B$r;2(B +$B>H!K!%(B %\subsection{Strategies for applying a patch} \subsection{$B%Q%C%AE,MQ$N$?$a$N@oN,(B} -When \command{patch} applies a hunk, it tries a handful of -successively less accurate strategies to try to make the hunk apply. -This falling-back technique often makes it possible to take a patch -that was generated against an old version of a file, and apply it -against a newer version of that file. +%When \command{patch} applies a hunk, it tries a handful of +%successively less accurate strategies to try to make the hunk apply. +%This falling-back technique often makes it possible to take a patch +%that was generated against an old version of a file, and apply it +%against a newer version of that file. -\command{patch}$B$,(Bhunk$B$rE,MQ$9$k$H$-!$(B +\command{patch}$B$,(Bhunk$B$rE,MQ$9$k$H$-!$$$$/$D$+$N$"$^$j@53N$G$J$$@oN,$rB3$1(B +$B$FMQ$$$k!%$3$N%U%)!<%k%P%C%/<jK!$K$h$C$F!$8E$$%P!<%8%g%s$N%U%!%$%k$KBP$7(B +$B$F:n@.$7$?%Q%C%A$r?7$7$$%U%!%$%k$KE,MQ$9$k$3$H$5$($7$P$7$P2DG=$H$J$k!%(B +%First, \command{patch} tries an exact match, where the line numbers, +%the context, and the text to be modified must apply exactly. If it +%cannot make an exact match, it tries to find an exact match for the +%context, without honouring the line numbering information. If this +%succeeds, it prints a line of output saying that the hunk was applied, +%but at some \emph{offset} from the original line number. -First, \command{patch} tries an exact match, where the line numbers, -the context, and the text to be modified must apply exactly. If it -cannot make an exact match, it tries to find an exact match for the -context, without honouring the line numbering information. If this -succeeds, it prints a line of output saying that the hunk was applied, -but at some \emph{offset} from the original line number. +$B:G=i$K!$(B\command{patch}$B$O9THV9f!$%3%s%F%-%9%H!$JQ99$5$l$k%F%-%9%H$N@53N$J(B +$B%^%C%A$r;n$_$k!%@53N$J%^%C%A$,$G$-$J$$>l9g!$9THV9f$rL5;k$7$F%3%s%F%-%9%H(B +$B$N@53N$J%^%C%A$r;n$_$k!%$3$l$,@.8y$9$l$P!$(Bhunk$B$,E,MQ$5$l$?$,!$(B\emph{$B%*%U(B +$B%;%C%H(B}$B$,@8$8$?$H$$$&%a%C%;!<%8$rI=<($9$k!%(B + +%If a context-only match fails, \command{patch} removes the first and +%last lines of the context, and tries a \emph{reduced} context-only +%match. If the hunk with reduced context succeeds, it prints a message +%saying that it applied the hunk with a \emph{fuzz factor} (the number +%after the fuzz factor indicates how many lines of context +%\command{patch} had to trim before the patch applied). -If a context-only match fails, \command{patch} removes the first and -last lines of the context, and tries a \emph{reduced} context-only -match. If the hunk with reduced context succeeds, it prints a message -saying that it applied the hunk with a \emph{fuzz factor} (the number -after the fuzz factor indicates how many lines of context -\command{patch} had to trim before the patch applied). +$B%3%s%F%-%9%H$N$_$N%^%C%A$,<:GT$9$k$H!$(B\command{patch}$B$O%3%s%F%-%9%H$N:G=i(B +$B$H:G8e$N9T$r:o$j!$%3%s%F%-%9%H$N(B\emph{$B=L>.(B}$B%^%C%A$r;n$_$k!%=L>.%3%s%F%-%9(B +$B%H$K$h$k(Bhunk$B$,@.8y$9$k$H!$(Bhunk$B$,E,MQ$5$l$?$3$H$H(B\emph{fuzz $B%U%!%/%?!<(B}$B$r(B +$B4^$`%a%C%;!<%8$rI=<($9$k!%!J(Bfuzz$B%U%!%/%?!<$N8e$m$N?t;z$O!$(B +\command{patch}$B%3%^%s%I$,!$%Q%C%A$rE,MQ$9$kA0$K%3%s%F%-%9%H$N2?9T$r:o=|$9(B +$B$kI,MW$,$"$C$?$N$+$r<($9!%!K(B -When neither of these techniques works, \command{patch} prints a -message saying that the hunk in question was rejected. It saves -rejected hunks (also simply called ``rejects'') to a file with the -same name, and an added \sfilename{.rej} extension. It also saves an -unmodified copy of the file with a \sfilename{.orig} extension; the -copy of the file without any extensions will contain any changes made -by hunks that \emph{did} apply cleanly. If you have a patch that -modifies \filename{foo} with six hunks, and one of them fails to -apply, you will have: an unmodified \filename{foo.orig}, a -\filename{foo.rej} containing one hunk, and \filename{foo}, containing -the changes made by the five successful five hunks. +%When neither of these techniques works, \command{patch} prints a message +%saying that the hunk in question was rejected. It saves rejected hunks +%(also simply called ``rejects'') to a file with the same name, and an +%added \sfilename{.rej} extension. It also saves an unmodified copy of +%the file with a \sfilename{.orig} extension; the copy of the file +%without any extensions will contain any changes made by hunks that +%\emph{did} apply cleanly. If you have a patch that modifies +%\filename{foo} with six hunks, and one of them fails to apply, you will +%have: an unmodified \filename{foo.orig}, a \filename{foo.rej} containing +%one hunk, and \filename{foo}, containing the changes made by the five +%successful five hunks. + +$B$I$A$i$b>e<j$/$$$+$J$+$C$?>l9g!$(B\command{patch}$B$O(Bhunk$B$,%j%8%'%/%H$5$l$?$H(B +$B$$$&%a%C%;!<%8$rI=<($9$k!%%3%^%s%I$O%j%8%'%/%H$5$l$?(Bhunk$B!J$"$k$$$OC1$K(B +``rejects''$B!K$rF1L>$G3HD%;R(B\sfilename{.rej}$B$N%U%!%$%k$K%;!<%V$9$k!%%3%^%s(B +$B%I$OF1;~$KL5JQ99$N%U%!%$%k$r(B\sfilename{.orig}$B$H$$$&3HD%;R$G%;!<%V$9$k!#3H(B +$BD%;R$N$J$$%U%!%$%k$N%3%T!<$O!$(Bhunk$B$+$i%/%j!<%s$KE,MQ$5$l$?JQ99$rA4$F4^$`!%(B +\filename{foo}$B$H$$$&%U%!%$%k$rJQ99$9$k(B6$B$D$N(Bhunk$B$r4^$`%Q%C%A%U%!%$%k$,$"$j!$(B +$B$=$NFb$N(B1$B$D$,E,MQ$G$-$J$+$C$?$H$9$k$H!$L5JQ99$N%U%!%$%k(B +\filename{foo.orig}$B!$(Bhunk1$B$D$r4^$`%U%!%$%k(B\filename{foo.rej}$B!$@5$7$/E,MQ(B +$B$5$l$?(B5$B$D$N(Bhunk$B$r4^$`%U%!%$%k(B\filename{foo}$B$,@8@.$5$l$k!%(B %\subsection{Some quirks of patch representation} \subsection{$B%Q%C%AI=8=$N4qL/$JE@(B} -There are a few useful things to know about how \command{patch} works -with files. +%There are a few useful things to know about how \command{patch} works +%with files. +%\begin{itemize} +%\item This should already be obvious, but \command{patch} cannot +% handle binary files. +%\item Neither does it care about the executable bit; it creates new +% files as readable, but not executable. +%\item \command{patch} treats the removal of a file as a diff between +% the file to be removed and the empty file. So your idea of ``I +% deleted this file'' looks like ``every line of this file was +% deleted'' in a patch. +%\item It treats the addition of a file as a diff between the empty +% file and the file to be added. So in a patch, your idea of ``I +% added this file'' looks like ``every line of this file was added''. +%\item It treats a renamed file as the removal of the old name, and the +% addition of the new name. This means that renamed files have a big +% footprint in patches. (Note also that Mercurial does not currently +% try to infer when files have been renamed or copied in a patch.) +%\item \command{patch} cannot represent empty files, so you cannot use +% a patch to represent the notion ``I added this empty file to the +% tree''. +%\end{itemize} + +\command{patch}$B$,%U%!%$%k$K$I$N$h$&$K:nMQ$9$k$+!$M-MQ$JE@$r$$$/$D$+=R$Y(B +$B$k!%(B \begin{itemize} -\item This should already be obvious, but \command{patch} cannot - handle binary files. -\item Neither does it care about the executable bit; it creates new - files as readable, but not executable. -\item \command{patch} treats the removal of a file as a diff between - the file to be removed and the empty file. So your idea of ``I - deleted this file'' looks like ``every line of this file was - deleted'' in a patch. -\item It treats the addition of a file as a diff between the empty - file and the file to be added. So in a patch, your idea of ``I - added this file'' looks like ``every line of this file was added''. -\item It treats a renamed file as the removal of the old name, and the - addition of the new name. This means that renamed files have a big - footprint in patches. (Note also that Mercurial does not currently - try to infer when files have been renamed or copied in a patch.) -\item \command{patch} cannot represent empty files, so you cannot use - a patch to represent the notion ``I added this empty file to the - tree''. + \item $B$9$G$KL@Gr$@$,!$(B\command{patch}$B$O%P%$%J%j%U%!%$%k$r07$&$3$H$O$G$-(B + $B$J$$!%(B + \item $B<B9T%S%C%H$r9MN8$7$J$$$@$1$G$J$/!$?7$7$$%U%!%$%k$rFI$_<h$j2DG=B0(B + $B@-$G:n@.$7!$<B9T2DG=B0@-$OIU$1$J$$!%(B + \item \command{patch}$B%3%^%s%I$O%U%!%$%k$N:o=|$r:o=|$5$l$k%U%!%$%k$HCf?H(B + $B$,$+$i$N%U%!%$%k$H$N:9J,$H$7$F07$&!%=>$C$F!$%U%!%$%k$r:o=|$9$k$H$$(B + $B$&$3$H$O!$%Q%C%A%U%!%$%k$NCf$G$O%U%!%$%k$NCf$NA4$F$N9T$r:o=|$9$k$3(B + $B$H$HEy2A$G$"$k!%(B + \item \command{patch}$B%3%^%s%I$O%U%!%$%k$NDI2C$r6u$N%U%!%$%k$HDI2C$5$l$k(B + $B%U%!%$%k$N:9J,$H$7$F07$&!%=>$C$F%U%!%$%k$NDI2C$O%Q%C%A%U%!%$%k$NCf(B + $B$G$O%U%!%$%k$KA4$F$N9T$rDI2C$9$k$3$H$HEy2A$G$"$k!%(B + \item \command{patch}$B%3%^%s%I$OL>A0$NJQ99$5$l$?%U%!%$%k$r5lL>$N%U%!%$%k(B + $B$N:o=|$H?7$7$$%U%!%$%k$NDI2C$H$7$F07$&!%=>$C$FL>A0$NJQ99$5$l$?%U%!(B + $B%$%k$O%Q%C%AFb$GBg$-$J%U%C%H%W%j%s%H$r@j$a$k!%!J(BMercurial$B$O8=:_$N(B + $B$H$3$m!$%Q%C%AFb$G%U%!%$%k$,%j%M!<%`$5$l$?$N$+!$%3%T!<$5$l$?$N$+(B + $B$r4XCN$7$J$$!K(B + \item \command{patch}$B%3%^%s%I$OCf?H$N6u$N%U%!%$%k$rI=8=$G$-$J$$!%=>$C$F(B + $B%Q%C%A%U%!%$%k$r!V6u$N%U%!%$%k$r%D%j!<$KDI2C$9$k!W$H$$$&MQES$K;H(B + $B$&$3$H$O$G$-$J$$!%(B \end{itemize} %\subsection{Beware the fuzz} @@ -928,10 +972,22 @@ be completely successful, these inexact techniques naturally leave open the possibility of corrupting the patched file. The most common cases typically involve applying a patch twice, or at an incorrect -location in the file. If \command{patch} or \hgxcmd{mq}{qpush} ever +location in the file. + +If \command{patch} or \hgxcmd{mq}{qpush} ever mentions an offset or fuzz factor, you should make sure that the modified files are correct afterwards. +$B$"$k%*%U%;%C%H$d(Bfuzz factor$B$N0LCV$X$N(Bhunk$B$NE,MQ$OB?$/$N>l9gA4$/LdBj$J$/@.(B +$B8y$9$k$,!$IT@53N$J%^%C%A$rMQ$$$?>l9g!$%Q%C%A$rE,MQ$7$?%U%!%$%k$r2u$7$F$$(B +$B$k2DG=@-$,;D$k!%(B + +$B%Q%C%A$rFsEYE,MQ$7$?$j!$%U%!%$%k$N4V0c$C$?>l=j$KE,MQ$7$F$7$^$&$N$,0lHV$h(B +$B$/$"$k4V0c$$$@!%(B + + + + It's often a good idea to refresh a patch that has applied with an offset or fuzz factor; refreshing the patch generates new context information that will make it apply cleanly. I say ``often,'' not