hgbook

changeset 462:5389bef3a95b

translated up to the "Bundled hooks" section
author Javier Rojas <jerojasro@devnull.li>
date Tue Dec 23 17:33:22 2008 -0500 (2008-12-23)
parents 67d34d8b6ba0
children 0ab26d50eba3
files es/hook.tex
line diff
     1.1 --- a/es/hook.tex	Tue Dec 23 12:57:21 2008 -0500
     1.2 +++ b/es/hook.tex	Tue Dec 23 17:33:22 2008 -0500
     1.3 @@ -470,72 +470,84 @@
     1.4    def myhook(ui, repo, **kwargs):
     1.5        pass
     1.6  \end{codesample2}
     1.7 -The first argument to a Python hook is always a
     1.8 -\pymodclass{mercurial.ui}{ui} object.  The second is a repository object;
     1.9 -at the moment, it is always an instance of
    1.10 -\pymodclass{mercurial.localrepo}{localrepository}.  Following these two
    1.11 -arguments are other keyword arguments.  Which ones are passed in
    1.12 -depends on the hook being called, but a hook can ignore arguments it
    1.13 -doesn't care about by dropping them into a keyword argument dict, as
    1.14 -with \texttt{**kwargs} above.
    1.15 -
    1.16 -\section{Some hook examples}
    1.17 -
    1.18 -\subsection{Writing meaningful commit messages}
    1.19 -
    1.20 -It's hard to imagine a useful commit message being very short.  The
    1.21 -simple \hook{pretxncommit} hook of figure~\ref{ex:hook:msglen.go}
    1.22 -will prevent you from committing a changeset with a message that is
    1.23 -less than ten bytes long.
    1.24 +El primer argumento para un gancho Python siempre es un objeto
    1.25 +\pymodclass{mercurial.ui}{ui}.  El segundo es un objeto repositorio;
    1.26 +de momento, siempre es una instancia de 
    1.27 +\pymodclass{mercurial.localrepo}{localrepository}.  Después de estos
    1.28 +dos argumentos están los argumentos de palabra clave. Los argumentos
    1.29 +que se pasen dependerán del tipo de gancho que se esté llamando, pero
    1.30 +un gancho siempre puede ignorar los argumentos que no le interesen,
    1.31 +relegándolos a un diccionario de argumentos por palabras clave, como se
    1.32 +hizo arriba con \texttt{**kwargs}.
    1.33 +
    1.34 +\section{Ejemplos de ganchos}
    1.35 +
    1.36 +\subsection{Escribir mensajes de consignación significativos}
    1.37 +
    1.38 +Es difícil de imaginar un mensaje de consignación útil y al mismo
    1.39 +tiempo muy corto. El simple gancho \hook{pretxncommit} de la
    1.40 +figura~\ref{ex:hook:msglen.go} evitará que usted consigne un conjunto
    1.41 +de cambios con un mensaje de menos de 10 bytes de longitud.
    1.42  
    1.43  \begin{figure}[ht]
    1.44    \interaction{hook.msglen.go}
    1.45 -  \caption{A hook that forbids overly short commit messages}
    1.46 +  \caption{Un gancho que prohíbe mensajes de consignación demasiado
    1.47 +  cortos}
    1.48    \label{ex:hook:msglen.go}
    1.49  \end{figure}
    1.50  
    1.51 -\subsection{Checking for trailing whitespace}
    1.52 -
    1.53 -An interesting use of a commit-related hook is to help you to write
    1.54 -cleaner code.  A simple example of ``cleaner code'' is the dictum that
    1.55 -a change should not add any new lines of text that contain ``trailing
    1.56 -whitespace''.  Trailing whitespace is a series of space and tab
    1.57 -characters at the end of a line of text.  In most cases, trailing
    1.58 -whitespace is unnecessary, invisible noise, but it is occasionally
    1.59 -problematic, and people often prefer to get rid of it.
    1.60 -
    1.61 -You can use either the \hook{precommit} or \hook{pretxncommit} hook to
    1.62 -tell whether you have a trailing whitespace problem.  If you use the
    1.63 -\hook{precommit} hook, the hook will not know which files you are
    1.64 -committing, so it will have to check every modified file in the
    1.65 -repository for trailing white space.  If you want to commit a change
    1.66 -to just the file \filename{foo}, but the file \filename{bar} contains
    1.67 -trailing whitespace, doing a check in the \hook{precommit} hook will
    1.68 -prevent you from committing \filename{foo} due to the problem with
    1.69 -\filename{bar}.  This doesn't seem right.
    1.70 -
    1.71 -Should you choose the \hook{pretxncommit} hook, the check won't occur
    1.72 -until just before the transaction for the commit completes.  This will
    1.73 -allow you to check for problems only the exact files that are being
    1.74 -committed.  However, if you entered the commit message interactively
    1.75 -and the hook fails, the transaction will roll back; you'll have to
    1.76 -re-enter the commit message after you fix the trailing whitespace and
    1.77 -run \hgcmd{commit} again.
    1.78 +\subsection{Comprobar espacios en blanco finales}
    1.79 +
    1.80 +Un uso interesante para ganchos relacionados con consignaciones es
    1.81 +ayudarle a escribir código más limpio. Un ejemplo simple de
    1.82 +%TODO dictum => regla
    1.83 +``código más limpio'' es la regla de que un cambio no debe añadir
    1.84 +líneas de texto que contengan ``espacios en blanco finales''. El
    1.85 +espacio en blanco final es una serie de caracteres de espacio y
    1.86 +tabulación que se encuentran al final de una línea de texto. En la
    1.87 +mayoría de los casos, el espacio en blanco final es innecesario, ruido
    1.88 +invisible, pero ocasionalmente es problemático, y la gente en general
    1.89 +prefiere deshacerse de él.
    1.90 +
    1.91 +Usted puede usar cualquiera de los ganchos \hook{precommit} o
    1.92 +\hook{pretxncommit} para revisar si tiene el problema de los espacios
    1.93 +en blanco finales. Si usa el gancho \hook{precommit}, el gancho no
    1.94 +sabrá qué ficheros se están consignando, por lo que se tendrá que
    1.95 +revisar cada fichero modificado en el repositorio para ver si tiene
    1.96 +espacios en blanco finales. Si usted sólo quiere consignar un cambio
    1.97 +al fichero \filename{foo}, y el fichero \filename{bar} contiene
    1.98 +espacios en blanco finales, hacer la revisión en el gancho
    1.99 +\hook{precommit} evitará que usted haga la consignación de
   1.100 +\filename{foo} debido al problem en \filename{bar}.  Este no parece el
   1.101 +enfoque adeucado.
   1.102 +
   1.103 +Si usted escogiera el gancho \hook{pretxncommit}, la revisión no
   1.104 +ocurriría sino hasta justo antes de que la transacción para la
   1.105 +consignación se complete. Esto le permitirá comprobar por posibles
   1.106 +problemas sólo en los ficheros que serán consignados. Sin embargo, si
   1.107 +usted ingresó el mensaje de consignación de manera interactiva y el
   1.108 +%TODO roll-back
   1.109 +gancho falla, la transacción será deshecha; usted tendrá que
   1.110 +reingresar el mensaje de consignación luego de que corrija el problema
   1.111 +con los espacios en blanco finales y ejecute \hgcmd{commit} de nuevo.
   1.112  
   1.113  \begin{figure}[ht]
   1.114    \interaction{hook.ws.simple}
   1.115 -  \caption{A simple hook that checks for trailing whitespace}
   1.116 +  \caption{Un gancho simple que revisa si hay espacios en blanco
   1.117 +  finales}
   1.118    \label{ex:hook:ws.simple}
   1.119  \end{figure}
   1.120  
   1.121 -Figure~\ref{ex:hook:ws.simple} introduces a simple \hook{pretxncommit}
   1.122 -hook that checks for trailing whitespace.  This hook is short, but not
   1.123 -very helpful.  It exits with an error status if a change adds a line
   1.124 -with trailing whitespace to any file, but does not print any
   1.125 -information that might help us to identify the offending file or
   1.126 -line.  It also has the nice property of not paying attention to
   1.127 -unmodified lines; only lines that introduce new trailing whitespace
   1.128 -cause problems.
   1.129 +La figura~\ref{ex:hook:ws.simple} presenta un gancho
   1.130 +\hook{pretxncommit} simple que comprueba la existencia de espacios en
   1.131 +blanco finales. Este gancho es corto, pero no brinda mucha ayuda.
   1.132 +Termina con un código de salida de error si un cambio añade una línea
   1.133 +con espacio en blanco final a cualquier fichero, pero no muestra
   1.134 +ninguna información que pueda ser útil para identificar el fichero o
   1.135 +la línea de texto origen del problema. También tiene la agradable
   1.136 +propiedad de no prestar atención a las líneas que no sufrieron
   1.137 +modificaciones; sólo las líneas que introducen nuevos espacios en
   1.138 +blanco finales causan problemas.
   1.139  
   1.140  \begin{figure}[ht]
   1.141    \interaction{hook.ws.better}
   1.142 @@ -543,22 +555,25 @@
   1.143    \label{ex:hook:ws.better}
   1.144  \end{figure}
   1.145  
   1.146 -The example of figure~\ref{ex:hook:ws.better} is much more complex,
   1.147 -but also more useful.  It parses a unified diff to see if any lines
   1.148 -add trailing whitespace, and prints the name of the file and the line
   1.149 -number of each such occurrence.  Even better, if the change adds
   1.150 -trailing whitespace, this hook saves the commit comment and prints the
   1.151 -name of the save file before exiting and telling Mercurial to roll the
   1.152 -transaction back, so you can use
   1.153 -\hgcmdargs{commit}{\hgopt{commit}{-l}~\emph{filename}} to reuse the
   1.154 -saved commit message once you've corrected the problem.
   1.155 -
   1.156 -As a final aside, note in figure~\ref{ex:hook:ws.better} the use of
   1.157 -\command{perl}'s in-place editing feature to get rid of trailing
   1.158 -whitespace from a file.  This is concise and useful enough that I will
   1.159 -reproduce it here.
   1.160 -\begin{codesample2}
   1.161 -  perl -pi -e 's,\\s+\$,,' filename
   1.162 +El ejemplo de la figura~\ref{ex:hook:ws.better} es mucho más complejo,
   1.163 +pero también más útil. El gancho procesa un diff unificado para
   1.164 +revisar si alguna línea añade espacios en blanco finales, e imprime el
   1.165 +nombre del fichero y el número de línea de cada ocurrencia. Aún mejor,
   1.166 +si el cambio añade espacios en blanco finales, este gancho guarda el
   1.167 +mensaje de consignación e imprime el nombre del fichero en el que el
   1.168 +mensaje fue guardado, antes de terminar e indicarle a Mercurial que
   1.169 +deshaga la transacción, para que uste pueda usar
   1.170 +\hgcmdargs{commit}{\hgopt{commit}{-l}~\emph{nombre\_fichero}} para
   1.171 +reutilizar el mensaje de consignación guardado anteriormente, una vez
   1.172 +usted haya corregido el problema.
   1.173 +
   1.174 +Como anotación final, note que en la figura~\ref{ex:hook:ws.better} el
   1.175 +%TODO on-site => in-situ ?
   1.176 +uso de la característica de edición \emph{in-situ} de \command{perl}
   1.177 +para eliminar los espacios en blanco finales en un fichero. Esto es
   1.178 +lo suficientemente conciso y poderoso para que lo presente aquí.
   1.179 +\begin{codesample2}
   1.180 +  perl -pi -e 's,\\s+\$,,' nombre\_fichero
   1.181  \end{codesample2}
   1.182  
   1.183  \section{Bundled hooks}