Mercurial > hgbook
view ja/filenames.tex @ 837:b775f963b18c
Clean up chapter 8, and add content
propagate 7226e5e750a6
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Tue, 15 Sep 2009 22:32:03 +0900 |
parents | 8a3041e6f3cb |
children |
line wrap: on
line source
%\chapter{File names and pattern matching} \chapter{$B%U%!%$%kL>$H%Q%?!<%s%^%C%A%s%0(B} \label{chap:names} %Mercurial provides mechanisms that let you work with file names in a %consistent and expressive way. Mercurial$B$O%U%!%$%kL>$K$D$$$F0l4S@-$N$"$jJ,$+$j$d$9$$%a%+%K%:%`$rDs6!$9(B $B$k!%(B %\section{Simple file naming} \section{$B%7%s%W%k$J%U%!%$%kL?L>(B} %Mercurial uses a unified piece of machinery ``under the hood'' to %handle file names. Every command behaves uniformly with respect to %file names. The way in which commands work with file names is as %follows. Mercurial$B$O%U%!%$%kL>$r<h$j07$&FbIt$N%a%+%K%:%`$r;}$C$F$$$k!%$"$i$f$k%3%^(B $B%s%I$O%U%!%$%kL>$KBP$7$FF10l$K$U$k$^$&!%%3%^%s%I$,%U%!%$%kL>$r07$&$d$jJ}(B $B$r0J2<$K<($9!%(B %If you explicitly name real files on the command line, Mercurial works %with exactly those files, as you would expect. $B%3%^%s%I%i%$%s$K<B:]$N%U%!%$%kL>$rL@<(E*$KM?$($?;~$O!$(BMercurial$B$OM?$($i(B $B$l$?%U%!%$%k$@$1$r07$&!%(B \interaction{filenames.files} %When you provide a directory name, Mercurial will interpret this as %``operate on every file in this directory and its subdirectories''. %Mercurial traverses the files and subdirectories in a directory in %alphabetical order. When it encounters a subdirectory, it will %traverse that subdirectory before continuing with the current %directory. $B%G%#%l%/%H%jL>$rM?$($?>l9g$O!$(BMercurial$B$O(B``$B$3$N%G%#%l%/%H%j$H%5%V%G%#%l%/(B $B%H%jFb$N$9$Y$F$N%U%!%$%k$KBP$7$F=hM}$r9T$&(B''$B$H2r<a$9$k!%(B Mercurial$B$O%G%#%l%/%H%jFb$N%U%!%$%k$H%5%V%G%#%l%/%H%j$r%"%k%U%!%Y%C%H=g(B $B$KEO$jJb$/!%%5%V%G%#%l%/%H%j$r8+$D$1$k$H!$%+%l%s%H%G%#%l%/%H%j$N=hM}$rB3(B $B$1$k$N$G$O$J$/!$%5%V%G%#%l%/%H%jFb$r8+$K9T$/!%(B \interaction{filenames.dirs} %\section{Running commands without any file names} \section{$B%U%!%$%kL>$J$7$G%3%^%s%I$r<B9T$9$k(B} %Mercurial's commands that work with file names have useful default %behaviours when you invoke them without providing any file names or %patterns. What kind of behaviour you should expect depends on what %the command does. Here are a few rules of thumb you can use to %predict what a command is likely to do if you don't give it any names %to work with. $B%U%!%$%kL>$r<h$k(BMercurial$B%3%^%s%I$O%U%!%$%kL>$d%Q%?!<%s$rM?$($J$$$G5/F0$7(B $B$?>l9g$G$bM-MQ$J%G%U%)%k%H$N?6Iq$r;}$D!%4|BT$9$k5sF0$O!$2?$r$9$k%3%^%s%I(B $B$+$K$h$k!%%3%^%s%I$K%U%!%$%kL>Ey$rM?$($J$+$C$?>l9g$K%3%^%s%I$,$I$N$h$&$K(B $BF0$/$+?dB,$9$kBg$^$+$J%k!<%k$r$$$/$D$+5s$2$k!%(B \begin{itemize} %\item Most commands will operate on the entire working directory. % This is what the \hgcmd{add} command does, for example. \item $BBgH>$N%3%^%s%I$O%o!<%-%s%0%G%#%l%/%H%jA4BN$KBP$7$FF/$/!%Nc$($P(B \hgcmd{add}$B%3%^%s%I$N$U$k$^$$$,$3$l$K$"$?$k!%(B %\item If the command has effects that are difficult or impossible to % reverse, it will force you to explicitly provide at least one name % or pattern (see below). This protects you from accidentally % deleting files by running \hgcmd{remove} with no arguments, for % example. \item $BI|85$,:$Fq$G$"$C$?$jIT2DG=$G$"$k$h$&$J8z2L$r;}$D%3%^%s%I$N>l9g!$:G(B $BDc(B1$B$D$NL>A0$d%Q%?!<%s$rL@<($9$k$3$H$r5a$a$k!J2<5-$r;2>H!%!K!%$3$&(B $B$9$k$3$H$G!$Nc$($P(B\hgcmd{remove}$B$K0z?t$rM?$($J$+$C$?$?$a$K%U%!%$%k(B $B$9$Y$F$r8m$C$F>C$9$3$H$,$J$/$J$k!%(B \end{itemize} %It's easy to work around these default behaviours if they don't suit %you. If a command normally operates on the whole working directory, %you can invoke it on just the current directory and its subdirectories %by giving it the name ``\dirname{.}''. %\interaction{filenames.wdir-subdir} $B%G%U%)%k%H$N5sF0$,5$$KF~$i$J$$>l9g!$$3$l$rJQ99$9$k$N$O$?$d$9$$!%(B $B%3%^%s%I$,DL>o%o!<%-%s%0%G%#%l%/%H%jA4BN$KBP$7$FF0:n$9$k$H$7$h$&!%(B $B$3$l$r%+%l%s%H%G%#%l%/%H%j$H$=$N%5%V%G%#%l%/%H%j$KBP$7$F$N$_F0:n$9$k$h$&(B $B$KJQ$($k$K$O!$(B``\dirname{.}''$B$rEO$;$PNI$$!%(B \interaction{filenames.wdir-subdir} %Along the same lines, some commands normally print file names relative %to the root of the repository, even if you're invoking them from a %subdirectory. Such a command will print file names relative to your %subdirectory if you give it explicit names. Here, we're going to run %\hgcmd{status} from a subdirectory, and get it to operate on the %entire working directory while printing file names relative to our %subdirectory, by passing it the output of the \hgcmd{root} command. %\interaction{filenames.wdir-relname} $B%5%V%G%#%l%/%H%j$+$i5/F0$7$F$b%U%!%$%kL>$r%j%]%8%H%j$N%k!<%H$+$i$NAjBP%Q(B $B%9$GI=<($9$k%3%^%s%I$,$"$k!%$=$N$h$&$J%3%^%s%I$KL@<(E*$K%5%V%G%#%l%/%H%j(B $BL>$rM?$($k$H!$8=:_$N%5%V%G%#%l%/%H%j$+$i$NAjBP%Q%9$,I=<($5$l$k!%$3$3$G!$(B $B%5%V%G%#%l%/%H%jFb$+$i(B\hgcmd{status}$B%3%^%s%I$K(B\hgcmd{root}$B%3%^%s%I$N=PNO(B $B$r0z?t$H$7$FM?$($F5/F0$7!$(B \hgcmd{status}$B%3%^%s%I$,%o!<%-%s%0%G%#%l%/%H%j(B $BFb$N%U%!%$%k$r8=:_$N%5%V%G%#%l%/%H%j$KBP$9$kAjBP%Q%9$GI=<($9$kMM;R$r8+$F(B $B$_$h$&!%(B \interaction{filenames.wdir-relname} %\section{Telling you what's going on} \section{$B2?$,5/$-$F$$$k$N$+(B} %The \hgcmd{add} example in the preceding section illustrates something %else that's helpful about Mercurial commands. If a command operates %on a file that you didn't name explicitly on the command line, it will %usually print the name of the file, so that you will not be surprised %what's going on. $BA0%;%/%7%g%s$N(B\hgcmd{add}$B$NNc$O(BMercurial$B%3%^%s%I$K$D$$$FJL$NM-MQ$J>pJs$r(B $B<($7$F$$$k!%%3%^%s%I%i%$%s$GL@<(E*$KL>A0$r;XDj$7$J$+$C$?%U%!%$%k$KBP$7$F(B $B%3%^%s%I=hM}$r9T$&>l9g!$%U%!%$%kL>$rI=<($7!$2?$,5/$3$C$F$$$k$N$+J,$+$i$J(B $B$/$J$i$J$$$h$&$K$7$F$$$k!%(B %The principle here is of \emph{least surprise}. If you've exactly %named a file on the command line, there's no point in repeating it %back at you. If Mercurial is acting on a file \emph{implicitly}, e.g. %because you provided no names, or a directory, or a pattern (see %below), it is safest to tell you what it's operating on. \emph{$B$G$-$k$@$1$S$C$/$j$5$;$J$$(B}$B$H$$$&$N$,$3$3$G$N86B'$G$"$k!%%3%^%s%I%i(B $B%$%s$G%U%!%$%kL>$r40A4$K;XDj$7$?>l9g!$%U%!%$%kL>$,I=<($5$l$k$3$H$O$J$$!%(B Mercurial$B$O!$L>A0$rM?$($J$$$+!$%G%#%l%/%H%jL>$d!$0J2<$G@bL@$9$k$h$&$J%Q%?!<(B $B%s$rM?$(!$%U%!%$%k$,(B\emph{$B0EL[E*$K(B}$B;XDj$5$l$?>l9g$O!$0BA4$N$?$a$K8=:_A`(B $B:n$7$F$$$k%U%!%$%kL>$rI=<($9$k!%(B %For commands that behave this way, you can silence them using the %\hggopt{-q} option. You can also get them to print the name of every %file, even those you've named explicitly, using the \hggopt{-v} %option. $B$3$N$h$&$K?6Iq$&%3%^%s%I$r!$(B\hggopt{-q}$B%*%W%7%g%s$rM?$($k$3$H$GD@L[$5$;$k(B $B$3$H$b$G$-$k!%5U$KL@<(E*$K;XDj$7$?%U%!%$%k$X$NF0:n$G$"$C$F$b(B\hggopt{-v}$B%*(B $B%W%7%g%s$rM?$($k$3$H$G$9$Y$F$N%U%!%$%kL>$rI=<($5$;$k$3$H$b$G$-$k!%(B %\section{Using patterns to identify files} \section{$B%U%!%$%kL><1JL$K%Q%?!<%s$rMQ$$$k(B} %In addition to working with file and directory names, Mercurial lets %you use \emph{patterns} to identify files. Mercurial's pattern %handling is expressive. $B%U%!%$%k$d%G%#%l%/%H%jL>$r;H$C$?F0:n$NB>$K!$(BMercurial$B$G$O(B\emph{patterns} $B$r;H$C$F%U%!%$%k$r<1JL$9$k$3$H$b$G$-$k!%(BMercurial$B$N%Q%?!<%s=hM}$O6/NO$G(B $B$"$k!%(B %On Unix-like systems (Linux, MacOS, etc.), the job of matching file %names to patterns normally falls to the shell. On these systems, you %must explicitly tell Mercurial that a name is a pattern. On Windows, %the shell does not expand patterns, so Mercurial will automatically %identify names that are patterns, and expand them for you. Unix$B7O$N%7%9%F%`(B(Linux, MacOS$BEy(B)$B$G$O%U%!%$%kL>$H%Q%?!<%s$r%^%C%A$5$;$k;E(B $B;v$O%7%'%k$KG$$5$l$k!%$3$l$i$N%7%9%F%`$G$O!$L>A0$,%Q%?!<%s$G$"$k$3$H$rL@(B $B<(E*$K(BMercurial$B$K<($5$J$1$l$P$J$i$J$$!%(B Windows$B$G$O%7%'%k$O%Q%?!<%s$rE83+(B $B$7$J$$$N$G!$(BMercurial$B$OM?$($i$l$?L>A0$,<+F0E*$K%Q%?!<%s$G$"$k$3$H$rG'<1(B $B$7!$E83+$9$k!%(B %To provide a pattern in place of a regular name on the command line, %the mechanism is simple: $B%3%^%s%I%i%$%s$GDL>o$NL>A0$NBe$o$j$K%Q%?!<%s$rEO$9$?$a$N%a%+%K%:%`$O%7%s(B $B%W%k$G$"$k!%(B: \begin{codesample2} syntax:patternbody \end{codesample2} %That is, a pattern is identified by a short text string that says what %kind of pattern this is, followed by a colon, followed by the actual %pattern. $B$I$N$h$&$J%Q%?!<%s$J$N$+$r<1JL$9$k$?$a$NC;$$%F%-%9%H$N8e$m$K%3%m%s$r64$s(B $B$G<B:]$N%Q%?!<%s$,B3$/!%(B %Mercurial supports two kinds of pattern syntax. The most frequently %used is called \texttt{glob}; this is the same kind of pattern %matching used by the Unix shell, and should be familiar to Windows %command prompt users, too. Mercurial$B$O(B2$BDL$j$N%Q%?!<%s9=J8$r%5%]!<%H$9$k!%:G$b$h$/;H$o$l$k$N$O(B \texttt{glob};$B$G!$(BUnix$B%7%'%k$,%Q%?!<%s%^%C%A%s%0$K;HMQ$7$F$$$k$b$N$HF1MM(B $B$N%Q%?!<%s$G$"$j!$$3$l$O(BWindows$B$N%3%^%s%I%W%m%s%W%H%f!<%6$K$H$C$F$b?F$7(B $B$_?<$$$b$N$G$"$k!%(B %When Mercurial does automatic pattern matching on Windows, it uses %\texttt{glob} syntax. You can thus omit the ``\texttt{glob:}'' prefix %on Windows, but it's safe to use it, too. Mercurial$B$O(BWindows$B$G$O<+F0E*$K%Q%?!<%s%^%C%A%s%0$r9T$&$H$-(B $B$O!$(B\texttt{glob}$B9=J8$rMQ$$$k!%=>$C$F(BWindows$B$G$O(B``\texttt{glob:}''$B%W%l%U%#(B $B%/%9$r>JN,$7$F$b0BA4$G$"$k!%(B %The \texttt{re} syntax is more powerful; it lets you specify patterns %using regular expressions, also known as regexps. \texttt{re}$B9=J8$O$h$j6/NO$G!$@55,I=8=$rMQ$$$k$3$H$,$G$-$k!%(B %By the way, in the examples that follow, notice that I'm careful to %wrap all of my patterns in quote characters, so that they won't get %expanded by the shell before Mercurial sees them. $B8e$G<($9Nc$G$O!$(BMercurial$B$,8+$kA0$K%7%'%k$GE83+$5$l$k$N$rKI$0$?$a$K%Q%?!<(B $B%s$r0zMQJ8;z$G$/$k$s$G$$$k$3$H$KCm0U$5$l$?$$!%(B %\subsection{Shell-style \texttt{glob} patterns} \subsection{$B%7%'%k7A<0$N(B\texttt{glob}$B%Q%?!<%s(B} %This is an overview of the kinds of patterns you can use when you're %matching on glob patterns. glob$B%Q%?!<%s$G%^%C%A%s%0$r9T$&;~$K;H$($k%Q%?!<%s$N35N,$r<($9!%(B %The ``\texttt{*}'' character matches any string, within a single %directory. ``\texttt{*}''$BJ8;z$O%G%#%l%/%H%jFb$NG$0U$NJ8;zNs$H%^%C%A$9$k!%(B \interaction{filenames.glob.star} %The ``\texttt{**}'' pattern matches any string, and crosses directory %boundaries. It's not a standard Unix glob token, but it's accepted by %several popular Unix shells, and is very useful. %\interaction{filenames.glob.starstar} ``\texttt{**}''$B%Q%?!<%s$O%G%#%l%/%H%j$r1[$($FG$0U$NJ8;zNs$K%^%C%A$9$k!%$3(B $B$l$O(BUnix$BI8=`$N(Bglob$B%H!<%/%s$G$O$J$$$,!$$$$/$D$+$N?M5$$N$"$k(BUnix$B%7%'%k$G;H(B $B$&$3$H$,$G$-!$$H$F$bM-MQ$G$"$k!%(B \interaction{filenames.glob.starstar} %The ``\texttt{?}'' pattern matches any single character. %\interaction{filenames.glob.question} ``\texttt{?}''$B%Q%?!<%s$OG$0U$N(B1$BJ8;z$K%^%C%A$9$k!%(B \interaction{filenames.glob.question} %The ``\texttt{[}'' character begins a \emph{character class}. This %matches any single character within the class. The class ends with a %``\texttt{]}'' character. A class may contain multiple \emph{range}s %of the form ``\texttt{a-f}'', which is shorthand for %``\texttt{abcdef}''. ``\texttt{[}''$BJ8;z$O(B\emph{$BJ8;z%/%i%9(B}$B$r3+;O$9$k!%$3$l$O%/%i%9Fb$NG$0U$N(B1 $BJ8;z$K%^%C%A$9$k!%%/%i%9$O(B``\texttt{]}''$BJ8;z$G=*$k!%%/%i%9$O(B ``\texttt{a-f}''$B$N$h$&$JHO0O$rJ#?t;}$D$3$H$,$G$-$k!%$3$NHO0O$O(B ``\texttt{abcdef}''$B$NC;=L7A$KAjEv$9$k!%(B \interaction{filenames.glob.range} %If the first character after the ``\texttt{[}'' in a character class %is a ``\texttt{!}'', it \emph{negates} the class, making it match any %single character not in the class. $BJ8;z%/%i%9$G(B``\texttt{[}''$B$N8e$K(B``\texttt{!}''$B$,Mh$?>l9g!$$3$l$O%/%i%9$N(B $BH]Dj$H$J$j!$%/%i%9$K4^$^$l$J$$G$0U$N(B1$BJ8;z$H%^%C%A$9$k!%(B %A ``\texttt{\{}'' begins a group of subpatterns, where the whole group %matches if any subpattern in the group matches. The ``\texttt{,}'' %character separates subpatterns, and ``\texttt{\}}'' ends the group. ``\texttt{\{}''$B$O%5%V%Q%?!<%s$N%0%k!<%W$r3+;O$9$k!%%0%k!<%W$G$O!$%0%k!<%W(B $BFb$NG$0U$N%5%V%Q%?!<%s$,%^%C%A$9$l$P%0%k!<%WA4BN$,%^%C%A$7$?$3$H$K$J$k!%(B ``\texttt{,}''$BJ8;z$O%5%V%Q%?!<%s$rJ,N%$7!$(B``\texttt{\}}''$B$O%0%k!<%W$r=*N;(B $B$9$k!%(B \interaction{filenames.glob.group} %\subsubsection{Watch out!} \subsubsection{$B$3$3$KCm0U!*(B} %Don't forget that if you want to match a pattern in any directory, you %should not be using the ``\texttt{*}'' match-any token, as this will %only match within one directory. Instead, use the ``\texttt{**}'' %token. This small example illustrates the difference between the two. $BG$0U$N%G%#%l%/%H%j$G%Q%?!<%s$r%^%C%A$5$;$k>l9g!$(B``\texttt{*}''$B$rA4$F$H%^%C(B $B%A$9$k%H!<%/%s$H$7$F;H$&$3$H$O$G$-$J$$!%$3$NJ8;z$O(B1$B$D$N%G%#%l%/%H%jFb$G$N(B $B$_%^%C%A$9$k!%$=$NBe$o$j!$(B``\texttt{**}''$B%H!<%/%s$r;H$&!%$3$l$i$N0c$$$r@b(B $BL@$9$k$?$a$KNc$r<($9!%(B \interaction{filenames.glob.star-starstar} %\subsection{Regular expression matching with \texttt{re} patterns} \subsection{\texttt{re}$B%Q%?!<%s$r;H$C$?@55,I=8=%^%C%A(B} %Mercurial accepts the same regular expression syntax as the Python %programming language (it uses Python's regexp engine internally). %This is based on the Perl language's regexp syntax, which is the most %popular dialect in use (it's also used in Java, for example). Mercurial$B$O(BPython$B8@8l$HF1$8@55,I=8=9=J8$r<u$1IU$1$k!%!J(BMercurial$B$OFbIt$G(B Python$B$N@55,I=8=%(%s%8%s$r;H$C$F$$$k!%!K$3$l$O(BPerl$B$N(Bregexp$B9=J8$r85$K$7$F(B $B$$$k!%$3$N9=J8$O:G$b$h$/MQ$$$i$l$F$$$k$b$N$G$"$j!$$?$H$($P(BJava$B$G$bMxMQ$5(B $B$l$F$$$k!%(B %I won't discuss Mercurial's regexp dialect in any detail here, as %regexps are not often used. Perl-style regexps are in any case %already exhaustively documented on a multitude of web sites, and in %many books. Instead, I will focus here on a few things you should %know if you find yourself needing to use regexps with Mercurial. regexp$B$,$=$l$[$I;H$o$l$F$$$J$$$+$N$h$&$K$3$3$G(BMercurial$B$N(Bregexp$B9=J8$K$D$$(B $B$F5DO@$9$k$3$H$OHr$1$k!%(B Perl$B%9%?%$%k(Bregexp$B$O$9$G$KB?$/$N%&%'%V%5%$%H$d=q(B $B@R$G$G>\:Y$KEO$C$F@bL@$5$l$F$$$k!%$=$NBe$o$j!$$3$3$G$O(BMercurial$B$G(Bregexp$B$r(B $B;H$&:]$KCN$C$F$*$/$Y$-$$$/$D$+$NE@$K>GE@$rEv$F$k$3$H$K$9$k!%(B %A regexp is matched against an entire file name, relative to the root %of the repository. In other words, even if you're already in %subbdirectory \dirname{foo}, if you want to match files under this %directory, your pattern must start with ``\texttt{foo/}''. regexp$B$O%U%!%$%kL>A4BN$H%^%C%A$9$k$,!$%U%!%$%kL>$O%j%]%8%H%j$N%k!<%H$+$i(B $B$NAjBP%Q%9$GI=$5$l$k!%8@$$BX$($l$P!$$9$G$K%5%V%G%#%l%/%H%j(B\dirname{foo}$B$K(B $B$$$k$H$7$F!$$3$N%G%#%l%/%H%jFb$N%U%!%$%k$K%^%C%A$5$;$?$1$l(B $B$P!$(B``\texttt{foo/}''$B$G;O$^$k%Q%?!<%s$rEO$9I,MW$,$"$k!%(B %One thing to note, if you're familiar with Perl-style regexps, is that %Mercurial's are \emph{rooted}. That is, a regexp starts matching %against the beginning of a string; it doesn't look for a match %anywhere within the string. To match anywhere in a string, start %your pattern with ``\texttt{.*}''. Perl$B7A<0$N(Bregexp$B$K47$l$F$$$k$N$J$i!$(BMercurial$B$N(Bregexp$B$O(B\emph{root}$B$r;}$D(B $B$H$$$&E@$KCm0U$7$F$*$/$H$h$$!%$9$J$o$A!$(Bregexp$B$OJ8;zNs$N;O$^$j$+$i%^%C%A(B $B$7!$J8;zNs$NESCf$+$i$O%^%C%A$7$J$$!%J8;zNs$NESCf$+$i%^%C%A$5$;$?$$>l9g(B $B$O!$%Q%?!<%s$r(B``\texttt{.*}''$B$G;O$a$kI,MW$,$"$k!%(B %\section{Filtering files} \section{$B%U%!%$%k$r%U%#%k%?$9$k(B} %Not only does Mercurial give you a variety of ways to specify files; %it lets you further winnow those files using \emph{filters}. Commands %that work with file names accept two filtering options. Mercurial$B$O%U%!%$%k$r;XDj$9$kMM!9$JJ}K!$rDs6!$9$k$@$1$G$J$/!$$5$i$K(B \emph{$B%U%#%k%?(B}$B$K$h$C$F%U%!%$%k$rA*JL$9$kJ}K!$rDs6!$9$k!%%U%!%$%kL>$r<h$C(B $B$FF0:n$9$k%3%^%s%I$O(B2$B$D$N%U%#%k%?%*%W%7%g%s$r<u$1IU$1$k!%(B \begin{itemize} %\item \hggopt{-I}, or \hggopt{--include}, lets you specify a pattern % that file names must match in order to be processed. \item \hggopt{-I}$B$^$?$O(B\hggopt{--include}$B%*%W%7%g%s$G;XDj$7$?%Q%?!<%s$K(B $B%^%C%A$7$?%U%!%$%k$,=hM}$5$l$k!%(B %\item \hggopt{-X}, or \hggopt{--exclude}, gives you a way to % \emph{avoid} processing files, if they match this pattern. \item \hggopt{-X}$B$^$?$O(B\hggopt{--exclude}$B%*%W%7%g%s$G;XDj$7$?%Q%?!<%s$K(B $B%^%C%A$7$?%U%!%$%k$O=hM}$+$i=|30$5$l$k!%(B \end{itemize} %You can provide multiple \hggopt{-I} and \hggopt{-X} options on the %command line, and intermix them as you please. Mercurial interprets %the patterns you provide using glob syntax by default (but you can use %regexps if you need to). $B%3%^%s%I%i%$%s$GJ#?t$N(B\hggopt{-I}$B$*$h$S(B\hggopt{-X}$B%*%W%7%g%s$r;XDj$7!$=j(B $BK>$NAH9g$;$K$9$k$3$H$,$G$-$k!%(B Mercurial$B$O%G%U%)%k%H$G$O(Bglob$B9=J8$GM?$($?(B $B%Q%?!<%s$r2r<a$9$k$,!$@55,I=8=$r;H$&$3$H$b2DG=$G$"$k!%(B %You can read a \hggopt{-I} filter as ``process only the files that %match this filter''. \hggopt{-I}$B%U%#%k%?$O(B``$B$3$N%U%#%k%?$K%^%C%A$9$k%U%!%$%k$@$1$r=hM}$9$k(B'' $B$HFI$_BX$($k$3$H$,$G$-$k!%(B \interaction{filenames.filter.include} %The \hggopt{-X} filter is best read as ``process only the files that %don't match this pattern''. \hggopt{-X}$B%U%#%k%?$O(B``$B$3$N%Q%?!<%s$K%^%C%A$7$J$$%U%!%$%k$@$1$r=hM}$9$k(B''$B$H(B $BFI$_BX$($k$N$,:G$bAj1~$7$$!%(B \interaction{filenames.filter.exclude} %\section{Permanently ignoring unwanted files and directories} \section{$BITI,MW$J%U%!%$%k$d%G%#%l%/%H%j$r1J5WE*$KL5;k$9$k(B} %When you create a new repository, the chances are that over time it will %grow to contain files that ought to \emph{not} be managed by Mercurial, %but which you don't want to see listed every time you run %\hgcmd{status}. For instance, ``build products'' are files that are %created as part of a build but which should not be managed by a revision %control system. The most common build products are output files %produced by software tools such as compilers. As another example, many %text editors litter a directory with lock files, temporary working %files, and backup files, which it also makes no sense to manage. $B?7$7$$%j%]%8%H%j$r:n@.$7!$3+H/:n6H$rB3$1$k$H!$;~4V$N7P2a$H$H$b$K%S%k%I@8(B $B@.J*$J$I$N$h$&$K%j%S%8%g%s4IM}%7%9%F%`$G4IM}$9$Y$-$G$J$$%U%!%$%k$,%j%]%8(B $B%H%j$KB?$/4^$^$l$k$h$&$K$J$k!%(BMercurial$B$N4IM}30$K$"$k$3$l$i$N%U%!%$%k(B $B$O!$(B\hgcmd{status}$B$r<B9T$9$k$H$$$A$$$A2hLL$KI=<($5$l$F$7$^$&!%:G$bE57?E*(B $B$J%S%k%I@8@.J*$O!$%3%s%Q%$%i$J$I$N%D!<%k$G@8@.$5$l$k=PNO%U%!%$%k$G$"$k!%(B $B$=$NB>$K$O!$B?$/$N%F%-%9%H%(%G%#%?$,%G%#%l%/%H%j$KCV$/%m%C%/%U%!%$%k$d!$(B $B0l;~E*$J%o!<%-%s%0%U%!%$%k!$%P%C%/%"%C%W%U%!%$%k$J$I$,$"$k!%(B %To have Mercurial permanently ignore such files, create a file named %\filename{.hgignore} in the root of your repository. You \emph{should} %\hgcmd{add} this file so that it gets tracked with the rest of your %repository contents, since your collaborators will probably find it %useful too. Mercurial$B$K$3$l$i$r1J5WE*$KL5;k$5$;$k$?$a$K$O!$%j%]%8%H%j$N%k!<%H%G%#%l%/(B $B%H%j$K(B\filename{.hgignore}$B$H$$$&L>A0$N%U%!%$%k$r:n@.$9$k!%$3$N%U%!%$%k$O(B $B$*$=$i$/B>$N6(NO<TC#$K$H$C$F$bM-MQ$G$"$k$+$i!$%j%]%8%H%j$NB>$N;D$j$NItJ,(B $B$HF1MM$K4IM}$5$l$k$h$&!$(B \hgcmd{add}$B$9$Y$-$G$"$k!%(B %By default, the \filename{.hgignore} file should contain a list of %regular expressions, one per line. Empty lines are skipped. Most people %prefer to describe the files they want to ignore using the ``glob'' %syntax that we described above, so a typical \filename{.hgignore} file %will start with this directive: $B%G%U%)%k%H$G$O(B\filename{.hgignore}$B%U%!%$%k$O(B1$B9T$K(B1$B$D$:$D@55,I=8=$N%j%9%H(B $B$r<u$1IU$1$k$h$&$K$J$C$F$$$k!%6u9T$OL5;k$5$l$k!%KX$s$I$N%f!<%6$OL5;k$9$Y(B $B$-%U%!%$%k$rA0=R$N(B``glob''$B9=J8$rMQ$$$F5-=R$9$k$3$H$r9%$`$N$G!$(B \filename{.hgignore}$B$N:G=i$O<!$N$h$&$J%G%#%l%/%F%#%V$G;O$a$k!%(B \begin{codesample2} syntax: glob \end{codesample2} %This tells Mercurial to interpret the lines that follow as glob %patterns, not regular expressions. $B$3$l$O8eB3$N9T$r@55,I=8=$G$O$J$/(Bglob$B%Q%?!<%s$H$7$F2r<a$9$k$h$&(BMercurial$B$K(B $B;X<($9$k!%(B %Here is a typical-looking \filename{.hgignore} file. $BE57?E*$J(B\filename{.hgignore}$B%U%!%$%k$NNc$r<($9!%(B \begin{codesample2} syntax: glob %# This line is a comment, and will be skipped. %# Empty lines are skipped too. # $B$3$N9T$O%3%a%s%H$G!$%9%-%C%W$5$l$k!%(B # $B6u9T$bF1MM$K%9%-%C%W$5$l$k!%(B %# Backup files left behind by the Emacs editor. # Emacs$B%(%G%#%?$K$h$C$F;D$5$l$k%P%C%/%"%C%W%U%!%$%k!%(B *~ %# Lock files used by the Emacs editor. %# Notice that the "#" character is quoted with a backslash. %# This prevents it from being interpreted as starting a comment. # Emacs$B%(%G%#%?$,;HMQ$9$k%m%C%/%U%!%$%k(B # "#"$BJ8;z$,%P%C%/%9%i%C%7%e$G%(%9%1!<%W$5$l$F$$$k$3$H$KCm0U!%(B # $B$3$l$K$h$C$F%3%a%s%H$N3+;OJ8;z$H$7$F2r<a$5$l$k$N$rKI$$$G$$$k!%(B .\#* %# Temporary files used by the vim editor. # vim$B%(%G%#%?$,;HMQ$9$k0l;~%U%!%$%k(B .*.swp %# A hidden file created by the Mac OS X Finder. # Mac OS X$B$N%U%!%$%s%@!<$K$h$C$F:n$i$l$k1#$7%U%!%$%k(B .DS_Store \end{codesample2} %\section{Case sensitivity} \section{$BBgJ8;z>.J8;z$N1F6A(B} \label{sec:names:case} %If you're working in a mixed development environment that contains %both Linux (or other Unix) systems and Macs or Windows systems, you %should keep in the back of your mind the knowledge that they treat the %case (``N'' versus ``n'') of file names in incompatible ways. This is %not very likely to affect you, and it's easy to deal with if it does, %but it could surprise you if you don't know about it. Linux$B$r$O$8$a$H$9$k(BUnix$B$d(BMac$B!$(BWindows$B$,:.:_$9$k3+H/4D6-$G:n6H$r$7$F$$$k$N(B $B$J$i!$3F!9$N%7%9%F%`$O%U%!%$%kL>$N(B(``N''$B$H(B``n'')$B$N$h$&$JBg>.J8;z$r0[$J$C(B $B$?$d$jJ}$G<h$j07$&$3$H$KN10U$9$Y$-$G$"$k!%$3$l$,LdBj$K$J$k$3$H$OLGB?$K$J(B $B$/!$LdBj$K$J$k>l9g$G$b4JC1$K2r7h$G$-$k$,!$%7%9%F%`4V$G$N<h$j07$$$N0c$$$r(B $BCN$i$J$1$l$P6C$/$3$H$K$J$k$@$m$&!%(B %Operating systems and filesystems differ in the way they handle the %\emph{case} of characters in file and directory names. There are %three common ways to handle case in names. $B%*%Z%l!<%F%#%s%0%7%9%F%`$H%U%!%$%k%7%9%F%`$O!$%U%!%$%kL>$H%G%#%l%/%H%jL>(B $B$N(B\emph{$BBg>.J8;z(B}$B$N07$$$G0[$J$C$F$$$k!%Bg>.J8;z$r07$&J}K!$O(B3$BDL$j$"$k!%(B \begin{itemize} %\item Completely case insensitive. Uppercase and lowercase versions % of a letter are treated as identical, both when creating a file and % during subsequent accesses. This is common on older DOS-based % systems. \item $B40A4$KBg>.J8;z$r6hJL$7$J$$!%BgJ8;z$H>.J8;z$O!$%U%!%$%k$N:n@.$H$=(B $B$N8e$N%"%/%;%9$GF10l$K07$o$l$k!%$3$l$O8E$$(BDOS$B%Y!<%9$N%7%9%F%`$GMQ(B $B$$$i$l$F$$$?!%(B %\item Case preserving, but insensitive. When a file or directory is % created, the case of its name is stored, and can be retrieved and % displayed by the operating system. When an existing file is being % looked up, its case is ignored. This is the standard arrangement on % Windows and MacOS. The names \filename{foo} and \filename{FoO} % identify the same file. This treatment of uppercase and lowercase % letters as interchangeable is also referred to as \emph{case % folding}. \item $BBg>.J8;z$N0c$$$OJ]B8$5$l$k$,6hJL$5$l$J$$!%%U%!%$%k$d%G%#%l%/%H%j$,(B $B:n$i$l$k$H!$%*%Z%l!<%F%#%s%0%7%9%F%`$OL>A0$NBg>.J8;z$rJ]B8$7!$I=<((B $B$J$I$K;HMQ$9$k!%4{B8$N%U%!%$%k$,;2>H$5$l$k;~$O!$Bg>.J8;z$OL5;k$5$l(B $B$k!%$3$l$O(BWindows$B$H(BMacOS$B$GI8=`E*$J<h$j07$$$G$"$k!%(B\filename{foo}$B$H(B \filename{FoO}$B$OF10l$N%U%!%$%k$HG'<1$5$l$k!%$3$N$h$&$JBg>.J8;z$N<h(B $B$j07$$$O(B\emph{case folding}$B$H8F$P$l$k$3$H$b$"$k!%(B %\item Case sensitive. The case of a name is significant at all times. % The names \filename{foo} and {FoO} identify different files. This % is the way Linux and Unix systems normally work. \item $BBg>.J8;z$r6hJL$9$k!%>o$KBg>.J8;z$GL>A0$r6hJL$9$k!%(B\filename{foo} $B$H(B{FoO}$B$OJL$N%U%!%$%k$HG'<1$5$l$k!%$3$l$O(BLinux$B$d(BUnix$B%7%9%F%`$NDL(B $B>o$N<h$j07$$$G$"$k!%(B \end{itemize} %On Unix-like systems, it is possible to have any or all of the above %ways of handling case in action at once. For example, if you use a %USB thumb drive formatted with a FAT32 filesystem on a Linux system, %Linux will handle names on that filesystem in a case preserving, but %insensitive, way. Unix$B7O$N%7%9%F%`$G$OF1;~$K>e5-$NJ}K!$rMxMQ$9$k$3$H$,2DG=$G$"$k!%Nc$($P(B USB$B%a%b%j$r(BLinux$B$G(BFAT32$B%U%!%$%k%7%9%F%`$H$7$F%U%)!<%^%C%H$7$?>l9g!$(B Linux$B$O$=$N%U%!%$%k%7%9%F%`>e$N%U%!%$%kL>$rBg>.J8;zJ]B8$@$,6hJL$;$:$K<h$j(B $B07$&!%(B %\subsection{Safe, portable repository storage} \subsection{$B0BA4$G2DHB$J%j%]%8%H%j%9%H%l!<%8(B} %Mercurial's repository storage mechanism is \emph{case safe}. It %translates file names so that they can be safely stored on both case %sensitive and case insensitive filesystems. This means that you can %use normal file copying tools to transfer a Mercurial repository onto, %for example, a USB thumb drive, and safely move that drive and %repository back and forth between a Mac, a PC running Windows, and a %Linux box. Mercurial$B$N%j%]%8%H%j3JG<%a%+%K%:%`$O(B\emph{$BBg>.J8;z%;!<%U(B}$B$G$"$k!%(B Mercurial$B$OBg>.J8;z$N6hJL$r$9$k%7%9%F%`$G$b$7$J$$%7%9%F%`$G$b0BA4$KJ]B8$G(B $B$-$k$h$&$K%U%!%$%kL>$rJQ49$9$k!%$3$N$?$a!$DL>o$N%U%!%$%k%3%T!<%D!<%k$r;H$C(B $B$F(BMercurial$B%j%]%8%H%j$r(BUSB$B%a%b%j$KE>Aw$7!$(BMac$B!$(BWindows$B$NF0$/(BPC$B!$(BLinux$B%^%7(B $B%s$N4V$G0\F0$7$F$b0BA4$G$"$k!%(B %\subsection{Detecting case conflicts} \subsection{$BBgJ8;z>.J8;z$N>WFM$r8!=P$9$k(B} %When operating in the working directory, Mercurial honours the naming %policy of the filesystem where the working directory is located. If %the filesystem is case preserving, but insensitive, Mercurial will %treat names that differ only in case as the same. $B%o!<%-%s%0%G%#%l%/%H%j$G$NF0:n$N:]$K!$(B Mercurial$B$O%o!<%-%s%0%G%#%l%/%H%j(B $B$N$"$k%U%!%$%k%7%9%F%`$N%M!<%_%s%0%]%j%7!<$rB:=E$9$k!%Bg>.J8;z$rJ]B8$9$k(B $B$,6hJL$7$J$$%U%!%$%k%7%9%F%`$N>l9g!$(BMercurial$B$OL>A0$NBg>.$@$1$,0[$J$C$F$$(B $B$k%U%!%$%k$rF1$8%U%!%$%k$H$7$F<h$j07$&!%(B %An important aspect of this approach is that it is possible to commit %a changeset on a case sensitive (typically Linux or Unix) filesystem %that will cause trouble for users on case insensitive (usually Windows %and MacOS) users. If a Linux user commits changes to two files, one %named \filename{myfile.c} and the other named \filename{MyFile.C}, %they will be stored correctly in the repository. And in the working %directories of other Linux users, they will be correctly represented %as separate files. $B$3$N%"%W%m!<%A$G=EMW$J$N$O!$Bg>.$r6hJL$9$k%U%!%$%k%7%9%F%`!JE57?E*$K$O(B Linux$B$*$h$S(BUnix$B!K$GBg>.$r6hJL$7$J$$%7%9%F%`!JDL>o!$(BWindows$B$^$?$O(BMacOS$B!K$N(B $B%f!<%6$K$H$C$F%H%i%V%k$H$J$k$h$&$J%A%'%s%8%;%C%H$r%3%_%C%H$9$k$3$H$,2DG=(B $B$G$"$k$H$$$&E@$G$"$k!%$b$7(BLinux$B%f!<%6$,(B\filename{myfile.c}$B$H$$$&%U%!%$%k(B $B$H(B\filename{MyFile.C}$B$H$$$&%U%!%$%k$KBP$9$k%A%'%s%8%;%C%H$r%3%_%C%H$7$?>l(B $B9g!$$=$l$i$O%j%]%8%H%j$K@5$7$/J]B8$5$l!$B>$N(BLinux$B%f!<%6$N%o!<%-%s%0%G%#%l(B $B%/%H%j$G$b@5$7$/JL!9$N%U%!%$%k$H$7$F8=$l$k!%(B %If a Windows or Mac user pulls this change, they will not initially %have a problem, because Mercurial's repository storage mechanism is %case safe. However, once they try to \hgcmd{update} the working %directory to that changeset, or \hgcmd{merge} with that changeset, %Mercurial will spot the conflict between the two file names that the %filesystem would treat as the same, and forbid the update or merge %from occurring. $B$3$3$G(BWindows$B$^$?$O(BMac$B$N%f!<%6$,$3$N%A%'%s%8%;%C%H$r(Bpull$B$9$k$H!$(B Mercurial$B$N%j%]%8%H%j3JG<%a%+%K%:%`$OBg>.J8;z$KBP$7$F0BA4$J$?$a!$:G=i$N$&(B $B$A$OLdBj$H$J$i$J$$!%$7$+$7%o!<%-%s%0%G%#%l%/%H%j$r$=$N%A%'%s%8%;%C%H$K(B \hgcmd{update}$B$7$h$&$H$7$?$j!$$=$N%A%'%s%8%;%C%H$H(B\hgcmd{merge}$B$7$h$&$H$9(B $B$k$H!$(BMercurial$B$O!$(B 2$B$D$N%U%!%$%kL>$r%U%!%$%k%7%9%F%`$,F1$8L>A0$H$7$F07$&(B $B$?$a$K@8$8$k%3%s%U%j%/%H$r8!=P$7!$(B \hgcmd{update}$B$d(B\hgcmd{merge}$B$r5v$5$J(B $B$$!%(B %\subsection{Fixing a case conflict} \subsection{$BBgJ8;z>.J8;z$N>WFM$r2r7h$9$k(B} %If you are using Windows or a Mac in a mixed environment where some of %your collaborators are using Linux or Unix, and Mercurial reports a %case folding conflict when you try to \hgcmd{update} or \hgcmd{merge}, %the procedure to fix the problem is simple. $B$b$7$"$J$?$,(BWindows$B$d(BMac$B$r;H$C$F$$$F!$2??M$+$N6(NO<T$,(BLinux$B$^$?$O(BUnix$B$r;H$C(B $B$F$$$k:.9g4D6-$G3+H/$r$7$F$*$j!$(B \hgcmd{update}$B$^$?$O(B\hgcmd{merge}$B$G(B Mercurial$B$,Bg>.J8;z$N%3%s%U%j%/%H$r8!=P$9$k$N$G$"$l$P!$2r7hJ}K!$O%7%s%W%k(B $B$G$"$k!%(B %Just find a nearby Linux or Unix box, clone the problem repository %onto it, and use Mercurial's \hgcmd{rename} command to change the %names of any offending files or directories so that they will no %longer cause case folding conflicts. Commit this change, \hgcmd{pull} %or \hgcmd{push} it across to your Windows or MacOS system, and %\hgcmd{update} to the revision with the non-conflicting names. $B<j6a$J(BLinux$B$^$?$O(BUnix$B%^%7%s$N>e$K!$LdBj$N$"$k%j%]%8%H%j$r%/%m!<%s$7!$(B Mercurial$B$N(B\hgcmd{rename}$B$r<B9T$7$FLdBj$N$"$k%U%!%$%k$d%G%#%l%/%H%j$NL>A0(B $B$rJQ99$7!$%3%s%U%j%/%H$r2r7h$9$k!%$3$NJQ99$r%3%_%C%H$7!$(B\hgcmd{pull}$B$^$?(B $B$O(B\hgcmd{push}$B%3%^%s%I$G$"$J$?$N(BWindows$B$^$?$O(BMacOS$B%7%9%F%`$KE>Aw(B $B$7!$(B\hgcmd{update}$B$G%3%s%U%j%/%H$N$J$$%j%S%8%g%s$X99?7$9$l$P$h$$!%(B %The changeset with case-conflicting names will remain in your %project's history, and you still won't be able to \hgcmd{update} your %working directory to that changeset on a Windows or MacOS system, but %you can continue development unimpeded. $BBg>.J8;z$N%U%!%$%kL>%3%s%U%j%/%H$,$"$k%A%'%s%8%;%C%H$O%W%m%8%'%/%H$NMzNr(B $B$K;D$C$F$*$j!$(B Windows$B$d(BMacOS$B%7%9%F%`$G$O$=$N%A%'%s%8%;%C%H$X(B \hgcmd{update}$B$9$k$3$H$O$G$-$J$$$b$N$N!$LdBj$J$/3+H/$rB3$1$k$3$H$,$G$-$k!%(B %%% Local Variables: %%% mode: yatex %%% TeX-master: "00book" %%% End: