hgbook

view es/filenames.tex @ 433:7d3e036025fb

moar paragraphas. lolz
author jerojasro@localhost
date Sun Nov 30 19:51:23 2008 -0500 (2008-11-30)
parents 5da084395a69
children c847605eb2a9
line source
1 \chapter{File names and pattern matching}
2 \label{chap:names}
4 Mercurial provee mecanismos que le permiten trabajar con nombres de
5 ficheros en una manera consistente y expresiva.
7 \section{Nombrado de ficheros simple}
9 % TODO traducción literal de "under the hood". revisar
10 Mercurial usa un mecanismo unificado ``bajo el capó'' para manejar
11 nombres de ficheros. Cada comando se comporta de manera uniforme con
12 respecto a los nombres de fichero. La manera en que los comandos
13 operan con nombres de fichero es la siguiente.
15 Si usted especifica explícitamente nombres reales de ficheros en la
16 línea de comandos, Mercurial opera únicamente sobre dichos ficheros,
17 como usted esperaría.
18 \interaction{filenames.files}
20 Cuando usted provee el nombre de un directorio, Mercurial interpreta
21 eso como ``opere en cada fichero en este directorio y sus
22 subdirectorios''. Mercurial va por todos los ficheros y subdirectorios
23 de un directorio en orden alfabético. Cuando encuentra un
24 subdirectorio, lo recorrerá antes de continuar con el directorio
25 actual.
26 \interaction{filenames.dirs}
28 \section{Ejecución de comandos sin ningún nombre de fichero}
30 Los comandos de Mercurial que trabajan con nombres de fichero tienen
31 comportamientos por defecto adecuados cuando son utilizados sin pasar
32 ningún patrón o nombre de fichero. El tipo de comportamiento depende
33 de lo que haga el comando. Aquí presento unas cuantas reglas generales
34 que usted puede usar para que es lo que probablemente hará un comando
35 si usted no le pasa ningún nombre de fichero con el cual trabajar.
36 \begin{itemize}
37 \item Muchos comandos operarán sobre el directorio de trabajo
38 completo. Por ejemplo, esto es lo que hace el comando
39 \hgcmd{add},
40 \item Si el comando tiene efectos difíciles o incluso imposibles de
41 revertir, se le obligará a usted a proveer explícitamente al menos
42 % TODO revisar ese "lo proteje a usted"
43 un nombre o patrón (ver más abajo). Esto lo proteje a usted de,
44 por ejemplo, borrar ficheros accidentalmente al ejecutar
45 \hgcmd{remove} sin ningún argumento.
46 \end{itemize}
49 Es fácil evitar este comportamiento por defecto, si no es el adecuado
50 para usted. Si un comando opera normalmente en todo el directorio de
51 trabajo, usted puede llamarlo para que trabaje sólo en el directorio
52 actual y sus subdirectorio pasándole el nombre ``\dirname{.}''.
53 \interaction{filenames.wdir-subdir}
55 Siguiendo la misma línea, algunos comandos normalmente imprimen las
56 rutas de ficheros con respecto a la raíz del repositorio, aún si usted
57 los llama dentro de un subdirectorio. Dichos comandos imprimirán las
58 rutas de los ficheros respecto al directorio en que usted se encuentra
59 si se les pasan nombres explícitos. Vamos a ejecutar el comando
60 \hgcmd{status} desde un subdirectorio, y a hacer que opere en el
61 directorio de trabajo completo, a la vez que todas las rutas de
62 ficheros se imprimen respecto a nuestro subdirectorio, pasándole la
63 salida del comando \hgcmd{root}.
64 \interaction{filenames.wdir-relname}
66 \section{Reportar que está pasando}
68 El ejemplo con el comando \hgcmd{add} en la sección anterior ilustra
69 algo más que es útil acerca de los comandos de Mercurial. Si un
70 comando opera en un fichero que usted no pasó explícitamente en la
71 línea de comandos, usualmente se imprimirá el nombre del fichero, para
72 que usted no sea sorprendido por lo que sucede.
74 Esto es el principio de \emph{mínima sorpresa}. Si usted se ha
75 referido explícitamente a un fichero en la línea de comandos, no tiene
76 mucho sentido repetir esto de vuelta a usted. Si Mercurial está
77 actuando en un fichero \emph{implícitamente}, porque usted no pasó
78 nombres, ni directorios, ni patrones (ver más abajo), lo más seguro es
79 decirle a usted qué se está haciendo.
81 Usted puede silenciar a los comandos que se comportan de esta manera
82 usando la opción \hggopt{-q}. También puede hacer que impriman el
83 nombre de cada fichero, aún aquellos que usted indicó explícitamente,
84 usando la opción \hggopt{-v}.
86 \section{Uso de patrones para identificar ficheros}
88 Además de trabajar con nombres de ficheros y directorios, Mercurial le
89 permite usar \emph{patrones} para identificar ficheros. El manejo de
90 patrones de Mercurial es expresivo.
92 En sistemas tipo Unix (Linux, MacOS, etc.), el trabajo de asociar
93 patrones con nombres de ficheros recae sobre el intérprete de comandos.
94 En estos sistemas, usted debe indicarle explícitamente a Mercurial que
95 el nombre que se le pasa es un patrón. En Windows, el intérprete no
96 expande los patrones, así que Mercurial identificará automáticamente
97 los nombres que son patrones, y hará la expansión necesaria.
99 Para pasar un patrón en vez de un nombre normal en la línea de
100 comandos, el mecanismo es simple:
101 \begin{codesample2}
102 syntax:patternbody
103 \end{codesample2}
104 Un patrón es identificado por una cadena de texto corta que indica qué
105 tipo de patrón es, seguido por un dos puntos, seguido por el patrón en
106 sí.
108 Mercurial soporta dos tipos de sintaxis para patrones. La que se usa
109 con más frecuencia se denomina \texttt{glob}\ndt{Grupo, colección,
110 aglomeración.}; es el mismo tipo de asociación de patrones usado por
111 el intérprete de Unix, y también debería ser familiar para los
112 usuarios de la línea de comandos de Windows.
114 Cuando Mercurial hace asociación automática de patrones en Windows,
115 usa la sintaxis \texttt{glob}. Por esto, usted puede omitir el
116 prefijo ``\texttt{glob:}'' en Windows, pero también es seguro usarlo.
118 La sintaxis \texttt{re}\ndt{Expresiones regulares.} es más poderosa;
119 le permite especificar patrones usando expresiones regulares, también
120 conocidas como regexps.
122 A propósito, en los ejemplos siguientes, por favor note que yo tengo
123 el cuidado de rodear todos mis patrones con comillas sencillas, para
124 que no sean expandidos por el intérprete antes de que Mercurial pueda
125 verlos.
127 \subsection{Patrones \texttt{glob} estilo intérprete}
129 Este es un vistazo general de los tipos de patrones que usted puede
130 usar cuando está usando asociación con patrone glob.
132 La secuencia ``\texttt{*}'' se asocia con cualquier cadena, dentro de
133 un único directorio.
134 \interaction{filenames.glob.star}
136 La secuencia ``\texttt{**}'' se asocia con cualquier cadena, y cruza los
137 % TODO token
138 límites de los directorios. No es una elemento estándar de los tokens
139 de glob de Unix, pero es aceptado por varios intérpretes Unix
140 populares, y es muy útil.
141 \interaction{filenames.glob.starstar}
143 La secuencia ``\texttt{?}'' se asocia con cualquier caracter sencillo.
144 \interaction{filenames.glob.question}
146 El caracter ``\texttt{[}'' marca el inicio de una \emph{clase de
147 caracteres}. Ella se asocia con cualquier caracter sencillo dentro de
148 la clase. La clase se finaliza con un caracter ``\texttt{]}''. Una
149 clase puede contener múltiples \emph{rango}s de la forma
150 ``\texttt{a-f}'', que en este caso es una abreviación para
151 ``\texttt{abcdef}''.
152 \interaction{filenames.glob.range}
153 Si el primer caracter en aparecer después de ``\texttt{[}'' en la
154 clase de caracteres es un ``\texttt{!}'', se \emph{niega} la clase,
155 haciendo que se asocie con cualquier caracter sencillo que no se
156 encuentre en la clase.
158 Un ``\texttt{\{}'' marca el inicio de un grupo de subpatrones, en
159 donde todo el grupo es asociado si cualquier subpatrón en el grupo
160 puede ser asociado. El caracter ``\texttt{,}'' separa los subpatrones,
161 y el ``\texttt{\}}'' finaliza el grupo.
162 \interaction{filenames.glob.group}
164 \subsubsection{Cuidado!}
166 No olvide que si usted desea asocia un patrón con cualquier
167 directorio, no debería usar el elemento para asociar con cualquier
168 cadena ``\texttt{*}'', ya que éste sólo generará asociaciones dentro
169 de un solo directorio. En vez de eso, use el caracter para asociar con
170 cualquier cadena ``\texttt{**}''. Este pequeño ejemplo ilustra la
171 diferencia entre los dos.
172 \interaction{filenames.glob.star-starstar}
174 \subsection{Asociación con patrones de expresiones regulares \texttt{re}}
176 Mercurial acepta la misma sintaxis para expresiones regulares del
177 lenguaje de programación Python (internamente se usa el motor de
178 expresiones regulares de Python). Esta sintaxis está basada en la
179 misma del lenguaje Perl, que es el dialecto más popular en uso
180 (por ejemplo, también se usa en Java).
182 No discutiré el dialecto de expresiones regulares de Mercurial en
183 detalle aquí, ya que las mismas no son usadas frecuentemente. Las
184 expresiones regulares al estilo Perl se encuentran documentadas
185 exhaustivamente en una multitud de sitios web, y en muchos libros.
186 En vez de eso, me enfocaré en unas cuantas cosas que usted debería
187 conocer si tiene la necesidad de usar expresiones regulares en
188 Mercurial.
190 Una expresión regular es comparada contra un nombre de fichero
191 completo, relativo a la raíz del repositorio. En otras palabras, aún
192 si usted se encuentra en un subdirectorio \dirname{foo}, si desea
193 asociar ficheros en este directorio, su patrón debe empezar con
194 ``\texttt{foo/}''.
196 One thing to note, if you're familiar with Perl-style regexps, is that
197 Mercurial's are \emph{rooted}. That is, a regexp starts matching
198 against the beginning of a string; it doesn't look for a match
199 anywhere within the string. To match anywhere in a string, start
200 your pattern with ``\texttt{.*}''.
202 \section{Filtering files}
204 Not only does Mercurial give you a variety of ways to specify files;
205 it lets you further winnow those files using \emph{filters}. Commands
206 that work with file names accept two filtering options.
207 \begin{itemize}
208 \item \hggopt{-I}, or \hggopt{--include}, lets you specify a pattern
209 that file names must match in order to be processed.
210 \item \hggopt{-X}, or \hggopt{--exclude}, gives you a way to
211 \emph{avoid} processing files, if they match this pattern.
212 \end{itemize}
213 You can provide multiple \hggopt{-I} and \hggopt{-X} options on the
214 command line, and intermix them as you please. Mercurial interprets
215 the patterns you provide using glob syntax by default (but you can use
216 regexps if you need to).
218 You can read a \hggopt{-I} filter as ``process only the files that
219 match this filter''.
220 \interaction{filenames.filter.include}
221 The \hggopt{-X} filter is best read as ``process only the files that
222 don't match this pattern''.
223 \interaction{filenames.filter.exclude}
225 \section{Ignoring unwanted files and directories}
227 XXX.
229 \section{Case sensitivity}
230 \label{sec:names:case}
232 If you're working in a mixed development environment that contains
233 both Linux (or other Unix) systems and Macs or Windows systems, you
234 should keep in the back of your mind the knowledge that they treat the
235 case (``N'' versus ``n'') of file names in incompatible ways. This is
236 not very likely to affect you, and it's easy to deal with if it does,
237 but it could surprise you if you don't know about it.
239 Operating systems and filesystems differ in the way they handle the
240 \emph{case} of characters in file and directory names. There are
241 three common ways to handle case in names.
242 \begin{itemize}
243 \item Completely case insensitive. Uppercase and lowercase versions
244 of a letter are treated as identical, both when creating a file and
245 during subsequent accesses. This is common on older DOS-based
246 systems.
247 \item Case preserving, but insensitive. When a file or directory is
248 created, the case of its name is stored, and can be retrieved and
249 displayed by the operating system. When an existing file is being
250 looked up, its case is ignored. This is the standard arrangement on
251 Windows and MacOS. The names \filename{foo} and \filename{FoO}
252 identify the same file. This treatment of uppercase and lowercase
253 letters as interchangeable is also referred to as \emph{case
254 folding}.
255 \item Case sensitive. The case of a name is significant at all times.
256 The names \filename{foo} and {FoO} identify different files. This
257 is the way Linux and Unix systems normally work.
258 \end{itemize}
260 On Unix-like systems, it is possible to have any or all of the above
261 ways of handling case in action at once. For example, if you use a
262 USB thumb drive formatted with a FAT32 filesystem on a Linux system,
263 Linux will handle names on that filesystem in a case preserving, but
264 insensitive, way.
266 \subsection{Safe, portable repository storage}
268 Mercurial's repository storage mechanism is \emph{case safe}. It
269 translates file names so that they can be safely stored on both case
270 sensitive and case insensitive filesystems. This means that you can
271 use normal file copying tools to transfer a Mercurial repository onto,
272 for example, a USB thumb drive, and safely move that drive and
273 repository back and forth between a Mac, a PC running Windows, and a
274 Linux box.
276 \subsection{Detecting case conflicts}
278 When operating in the working directory, Mercurial honours the naming
279 policy of the filesystem where the working directory is located. If
280 the filesystem is case preserving, but insensitive, Mercurial will
281 treat names that differ only in case as the same.
283 An important aspect of this approach is that it is possible to commit
284 a changeset on a case sensitive (typically Linux or Unix) filesystem
285 that will cause trouble for users on case insensitive (usually Windows
286 and MacOS) users. If a Linux user commits changes to two files, one
287 named \filename{myfile.c} and the other named \filename{MyFile.C},
288 they will be stored correctly in the repository. And in the working
289 directories of other Linux users, they will be correctly represented
290 as separate files.
292 If a Windows or Mac user pulls this change, they will not initially
293 have a problem, because Mercurial's repository storage mechanism is
294 case safe. However, once they try to \hgcmd{update} the working
295 directory to that changeset, or \hgcmd{merge} with that changeset,
296 Mercurial will spot the conflict between the two file names that the
297 filesystem would treat as the same, and forbid the update or merge
298 from occurring.
300 \subsection{Fixing a case conflict}
302 If you are using Windows or a Mac in a mixed environment where some of
303 your collaborators are using Linux or Unix, and Mercurial reports a
304 case folding conflict when you try to \hgcmd{update} or \hgcmd{merge},
305 the procedure to fix the problem is simple.
307 Just find a nearby Linux or Unix box, clone the problem repository
308 onto it, and use Mercurial's \hgcmd{rename} command to change the
309 names of any offending files or directories so that they will no
310 longer cause case folding conflicts. Commit this change, \hgcmd{pull}
311 or \hgcmd{push} it across to your Windows or MacOS system, and
312 \hgcmd{update} to the revision with the non-conflicting names.
314 The changeset with case-conflicting names will remain in your
315 project's history, and you still won't be able to \hgcmd{update} your
316 working directory to that changeset on a Windows or MacOS system, but
317 you can continue development unimpeded.
319 \begin{note}
320 Prior to version~0.9.3, Mercurial did not use a case safe repository
321 storage mechanism, and did not detect case folding conflicts. If
322 you are using an older version of Mercurial on Windows or MacOS, I
323 strongly recommend that you upgrade.
324 \end{note}
326 %%% Local Variables:
327 %%% mode: latex
328 %%% TeX-master: "00book"
329 %%% End: