SVNBOOK Chap3 Peg and Operative Revisions
De Framalang Wiki.
Cette section fait partie du livre Version control with subversion
| Pseudo | Code | Rôle | Statut |
|---|---|---|---|
| Hotshot92 | Traduction | Fait | |
| SVF | 1ère Relecture | Fait | |
| Validation |
Paragraphe 1
Peg and Operative Revisions
Piquets de révisions et révisions opérationnelles
We copy, move, rename, and completely replace files and directories on our computers all the time. And your version control system shouldn't get in the way of your doing these things with your version-controlled files and directories, either. Subversion's file management support is quite liberating, affording almost as much flexibility for versioned files as you'd expect when manipulating your unversioned ones. But that flexibility means that across the lifetime of your repository, a given versioned object might have many paths, and a given path might represent several entirely different versioned objects. This introduces a certain level of complexity to your interactions with those paths and objects.
Paragraphe 2
Subversion is pretty smart about noticing when an object's version history includes such “changes of address.” For example, if you ask for the revision history log of a particular file that was renamed last week, Subversion happily provides all those logs—the revision in which the rename itself happened, plus the logs of relevant revisions both before and after that rename. So, most of the time, you don't even have to think about such things. But occasionally, Subversion needs your help to clear up ambiguities.
Paragraphe 3
The simplest example of this occurs when a directory or file is deleted from version control, and then a new directory or file is created with the same name and added to version control. The thing you deleted and the thing you later added aren't the same thing. They merely happen to have had the same path—/trunk/object, for example. What, then, does it mean to ask Subversion about the history of /trunk/object? Are you asking about the thing currently at that location, or the old thing you deleted from that location? Are you asking about the operations that have happened to all the objects that have ever lived at that path? Subversion needs a hint about what you really want.
Paragraphe 4
And thanks to moves, versioned object history can get far more twisted than even that. For example, you might have a directory named concept, containing some nascent software project you've been toying with. Eventually, though, that project matures to the point that the idea seems to actually have some wings, so you do the unthinkable and decide to give the project a name. [17] Let's say you called your software Frabnaggilywort. At this point, it makes sense to rename the directory to reflect the project's new name, so concept is renamed to frabnaggilywort. Life goes on, Frabnaggilywort releases a 1.0 version and is downloaded and used daily by hordes of people aiming to improve their lives.
Paragraphe 5
It's a nice story, really, but it doesn't end there. Entrepreneur that you are, you've already got another think in the tank. So you make a new directory, concept, and the cycle begins again. In fact, the cycle begins again many times over the years, each time starting with that old concept directory, then sometimes seeing that directory renamed as the idea cures, sometimes seeing it deleted when you scrap the idea. Or, to get really sick, maybe you rename concept to something else for a while, but later rename the thing back to concept for some reason.
Paragraphe 6
Paragraphe 7
In version 1.1, Subversion introduced a way for you to tell it exactly which Main Street you meant. It's called the peg revision, and it is provided to Subversion for the sole purpose of identifying a unique line of history. Because at most, one versioned object may occupy a path at any given time—or, more precisely, in any one revision—the combination of a path and a peg revision is all that is needed to refer to a specific line of history. Peg revisions are specified to the Subversion command-line client using at syntax, so called because the syntax involves appending an “at sign” (@) and the peg revision to the end of the path with which the revision is associated.
Paragraphe 8
But what of the --revision (-r) of which we've spoken so much in this book? That revision (or set of revisions) is called the operative revision (or operative revision range). Once a particular line of history has been identified using a path and peg revision, Subversion performs the requested operation using the operative revision(s). To map this to our Chicagoland streets analogy, if we are told to go to 606 N. Main Street in Wheaton, [18] we can think of “Main Street” as our path and “Wheaton” as our peg revision. These two pieces of information identify a unique path that can be traveled (north or south on Main Street), and they keep us from traveling up and down the wrong Main Street in search of our destination. Now we throw in “606 N.” as our operative revision of sorts, and we know exactly where to go.
NOTE : The peg revision algorithm
- The peg revision algorithm
- Algorithme des piquets de révision
- The Subversion command-line performs the peg revision algorithm any time it needs to resolve possible ambiguities in the paths and revisions provided to it. Here's an example of such an invocation:
$ svn command -r OPERATIVE-REV item@PEG-REV
- If OPERATIVE-REV is older than PEG-REV, then the algorithm is as follows:
- Locate item in the revision identified by PEG-REV. There can be only one such object.
- Trace the object's history backwards (through any possible renames) to its ancestor in the revision OPERATIVE-REV.
- Perform the requested action on that ancestor, wherever it is located, or whatever its name might be or have been at that time.
- If OPERATIVE-REV is older than PEG-REV, then the algorithm is as follows:
- Subversion utilise l'algorithme des piquets de révision chaque fois qu'il doit résoudre une ambiguïté dans les chemins et numéros de versions fournis en ligne de commande. Voici un exemple d'une telle ligne de commande :
$ svn commande -r REVISION-OPERATIONNELLE element@PIQUET-DE-REVISION
- Si REVISION-OPERATIONNELLE est plus vieille que PIQUET-DE-REVISION, alors l'algorithme est le suivant :
- Trouver l'élément dans la révision identifiée par PIQUET-DE-REVISION. Il ne peut y avoir qu'un seul objet.
- Parcourir l'historique de l'objet à l'envers (y compris en tenant compte d'éventuels renommages) jusqu'à son ancêtre dans la révision REVISION-OPERATIONNELLE.
- Effectuer la requête sur cet ancêtre, où qu'il soit et quel que soit son nom (actuel et à ce moment là).
- Si REVISION-OPERATIONNELLE est plus vieille que PIQUET-DE-REVISION, alors l'algorithme est le suivant :
- But what if OPERATIVE-REV is younger than PEG-REV? Well, that adds some complexity to the theoretical problem of locating the path in OPERATIVE-REV, because the path's history could have forked multiple times (thanks to copy operations) between PEG-REV and OPERATIVE-REV. And that's not all—Subversion doesn't store enough information to performantly trace an object's history forward, anyway. So the algorithm is a little different:
- Locate item in the revision identified by OPERATIVE-REV. There can be only one such object.
- Trace the object's history backwards (through any possible renames) to its ancestor in the revision PEG-REV.
- Verify that the object's location (path-wise) in PEG-REV is the same as it is in OPERATIVE-REV. If that's the case, then at least the two locations are known to be directly related, so perform the requested action on the location in OPERATIVE-REV. Otherwise, relatedness was not established, so error out with a loud complaint that no viable location was found. (Someday, we expect that Subversion will be able to handle this usage scenario with more flexibility and grace.)
- But what if OPERATIVE-REV is younger than PEG-REV? Well, that adds some complexity to the theoretical problem of locating the path in OPERATIVE-REV, because the path's history could have forked multiple times (thanks to copy operations) between PEG-REV and OPERATIVE-REV. And that's not all—Subversion doesn't store enough information to performantly trace an object's history forward, anyway. So the algorithm is a little different:
- Mais que se passe-t-il si REVISION-OPERATIONNELLE est plus récente que PIQUET-DE-REVISION ? Et bien, cela ajoute un peu de complexité à la recherche du chemin dans REVISION-OPERATIONNELLE, parce que l'historique du chemin peut avoir bifurqué à plusieurs reprises (grâce aux opérations de copie) entre PEG-REV et REVISION-OPERATIONNELLE. Et ce n'est pas tout car, de toute façon, Subversion ne stocke pas suffisamment d'informations pour retracer de façon performante l'historique d'un élément dans le sens chronologique. Donc, dans ce cas, l'algorithme est un peu différent :
- Trouver l'élément dans la révision identifiée par REVISION-OPERATIONNELLE. Il ne peut y avoir qu'un seul objet.
- Parcourir l'historique de l'objet à l'envers (y compris en tenant compte d'éventuels renommages) jusqu'à son ancêtre dans la révision PIQUET-DE-REVISION.
- Vérifier que la position de l'objet (son chemin) dans PIQUET-DE-REVISION est la même que dans REVISION-OPERATIONNELLE. Si c'est le cas, puisque les deux positions sont directement liées, effectuer la requête sur la position dans REVISION-OPERATIONNELLE. Sinon, la relation entre les deux n'étant pas établie, renvoyer une erreur expliquant qu'aucune position viable n'a été trouvée. On peut espérer qu'un jour Subversion sera plus flexible et saura mieux gérer ce type de cas.
- Mais que se passe-t-il si REVISION-OPERATIONNELLE est plus récente que PIQUET-DE-REVISION ? Et bien, cela ajoute un peu de complexité à la recherche du chemin dans REVISION-OPERATIONNELLE, parce que l'historique du chemin peut avoir bifurqué à plusieurs reprises (grâce aux opérations de copie) entre PEG-REV et REVISION-OPERATIONNELLE. Et ce n'est pas tout car, de toute façon, Subversion ne stocke pas suffisamment d'informations pour retracer de façon performante l'historique d'un élément dans le sens chronologique. Donc, dans ce cas, l'algorithme est un peu différent :
- Note that even when you don't explicitly supply a peg revision or operative revision, they are still present. For your convenience, the default peg revision is BASE for working copy items and HEAD for repository URLs. And when no operative revision is provided, it defaults to being the same revision as the peg revision.
- Notez que même quand vous ne spécifiez pas explicitement de piquet de révision ni de numéro de révision opérationnelle, ils sont néanmoins présents. Par défaut, la valeur du piquet de révision est BASE pour les éléments de la copie de travail et HEAD pour les URL du dépôt. Et quand aucune révision opérationnelle n'est fournie, la valeur par défaut est celle du piquet de révision.
Paragraphe 10
Say that long ago we created our repository, and in revision 1 added our first concept directory, plus an IDEA file in that directory talking about the concept. After several revisions in which real code was added and tweaked, we, in revision 20, renamed this directory to frabnaggilywort. By revision 27, we had a new concept, a new concept directory to hold it, and a new IDEA file to describe it. And then five years and twenty thousand revisions flew by, just like they would in any good romance story.
Paragraphe 11
Now, years later, we wonder what the IDEA file looked like back in revision 1. But Subversion needs to know if we are asking about how the current file looked back in revision 1, or if we are asking for the contents of whatever file lived at concepts/IDEA in revision 1. Certainly those questions have different answers, and because of peg revisions, you can ask either of them. To find out how the current IDEA file looked in that old revision, you run:
$ svn cat -r 1 concept/IDEA svn: Unable to find repository location for 'concept/IDEA' in revision 1
A présent, plusieurs années plus tard, nous nous demandons à quoi ressemblait le fichier IDEE en révision 1. Mais Subversion a besoin de savoir si nous demandons à quoi ressemble le fichier actuel tel qu'il était lors de la révision 1 ou si nous demandons le contenu du fichier 'concept/IDEE' (quel qu'il soit) de la révision 1. Ces questions ont certainement des réponses différentes et grâce aux piquets de révisions, nous pouvons poser ces deux questions. Pour obtenir le contenu du fichier IDEE actuel tel qu'il était dans l'ancienne révision, tapez :
$ svn cat -r 1 concept/IDEE svn: Unable to find repository location for 'concept/IDEE' in revision 1
Paragraphe 12
Of course, in this example, the current IDEA file didn't exist yet in revision 1, so Subversion gives an error. The command above is shorthand for a longer notation which explicitly lists a peg revision. The expanded notation is:
$ svn cat -r 1 concept/IDEA@BASE svn: Unable to find repository location for 'concept/IDEA' in revision 1
And when executed, it has the expected results.
Bien sûr, dans cet exemple, le fichier IDEE actuel n'existait pas lors de la révision 1, c'est pourquoi Subversion renvoie une erreur. La commande ci-dessus est un raccourci pour la notation plus longue qui explicite le piquet de révision. La notation complète est donc :
$ svn cat -r 1 concept/IDEE@BASE svn: Unable to find repository location for 'concept/IDEE' in revision 1
Elle fournit le résultat attendu.
Paragraphe 13
The perceptive reader is probably wondering at this point if the peg revision syntax causes problems for working copy paths or URLs that actually have at signs in them. After all, how does svn know whether news@11 is the name of a directory in my tree, or just a syntax for “revision 11 of news”? Thankfully, while svn will always assume the latter, there is a trivial workaround. You need only append an at sign to the end of the path, such as news@11@. svn only cares about the last at sign in the argument, and it is not considered illegal to omit a literal peg revision specifier after that at sign. This workaround even applies to paths that end in an at sign—you would use filename@@ to talk about a file named filename@.
Paragraphe 14
Let's ask the other question, then—in revision 1, what were the contents of whatever file occupied the address concept/IDEA at the time? We'll use an explicit peg revision to help us out.
$ svn cat concept/IDEA@1 The idea behind this project is to come up with a piece of software that can frab a naggily wort. Frabbing naggily worts is tricky business, and doing it incorrectly can have serious ramifications, so we need to employ over-the-top input validation and data verification mechanisms.
Posons maintenant l'autre question : dans la révision 1, quel était le contenu du fichier qui occupait l'adresse concept/IDEE à ce moment là ? Nous allons utiliser explicitement un piquet de révision pour nous aider :
$ svn cat concept/IDEE@1 L'idée de ce projet est de fournir un logiciel qui peut frabber un naggily wort. Frabber les naggilys worts est particulièrement difficile et ne pas le faire correctement aurait des conséquences inimaginables. Nous devons donc utiliser des mécanismes de vérification des entrées et des données du dernier cri.
Paragraphe 15
Notice that we didn't provide an operative revision this time. That's because when no operative revision is specified, Subversion assumes a default operative revision that's the same as the peg revision.
Paragraphe 16
As you can see, the output from our operation appears to be correct. The text even mentions frabbing naggily worts, so this is almost certainly the file which describes the software now called Frabnaggilywort. In fact, we can verify this using the combination of an explicit peg revision and explicit operative revision. We know that in HEAD, the Frabnaggilywort project is located in the frabnaggilywort directory. So we specify that we want to see how the line of history identified in HEAD as the path frabnaggilywort/IDEA looked in revision 1.
$ svn cat -r 1 frabnaggilywort/IDEA@HEAD The idea behind this project is to come up with a piece of software that can frab a naggily wort. Frabbing naggily worts is tricky business, and doing it incorrectly can have serious ramifications, so we need to employ over-the-top input validation and data verification mechanisms.
Comme vous pouvez le constater, la résultat de la commande semble être correct. Le texte parle même de "frabber les naggilys worts", ce qui laisse supposer que c'est certainement le fichier décrivant le logiciel maintenant connu sous le nom de Frabnaggilywort. En fait, on peut le vérifier en combinant un piquet de révision explicite et un numéro de révision opérationnelle explicite. Nous savons que dans HEAD, le projet Frabnaggilywort est placé dans le répertoire Frabnaggilywort. Nous allons donc demander à voir, dans l'historique du fichier (actuel) frabnaggilywort/IDEE de HEAD, à quoi il ressemblait en révision 1.
$ svn cat -r 1 frabnaggilywort/IDEE@HEAD L'idée de ce projet est de fournir un logiciel qui peut frabber un naggily wort. Frabber les naggilys worts est particulièrement difficile et ne pas le faire correctement aurait des conséquences inimaginables. Nous devons donc utiliser des mécanismes de vérification des entrées et des données du dernier cri.
Paragraphe 17
And the peg and operative revisions need not be so trivial, either. For example, say frabnaggilywort had been deleted from HEAD, but we know it existed in revision 20, and we want to see the diffs for its IDEA file between revisions 4 and 10. We can use the peg revision 20 in conjunction with the URL that would have held Frabnaggilywort's IDEA file in revision 20, and then use 4 and 10 as our operative revision range.
$ svn diff -r 4:10 http://svn.red-bean.com/projects/frabnaggilywort/IDEA@20 Index: frabnaggilywort/IDEA =================================================================== --- frabnaggilywort/IDEA (revision 4) +++ frabnaggilywort/IDEA (revision 10) @@ -1,5 +1,5 @@ -The idea behind this project is to come up with a piece of software -that can frab a naggily wort. Frabbing naggily worts is tricky -business, and doing it incorrectly can have serious ramifications, so -we need to employ over-the-top input validation and data verification -mechanisms. +The idea behind this project is to come up with a piece of +client-server software that can remotely frab a naggily wort. +Frabbing naggily worts is tricky business, and doing it incorrectly +can have serious ramifications, so we need to employ over-the-top +input validation and data verification mechanisms.
Vous pouvez aussi spécifier des piquets de révision et des révisions opérationnelles moins triviales. Par exemple, disons que frabnaggilywort a été effacé de HEAD, mais nous savons qu'il existait en révision 20 et nous voulons voir les différences entre la révision 4 et la révision 10 pour son fichier IDEE. Nous pouvons utiliser le piquet de révision 20 en conjonction avec l'URL qu'avait le fichier frabnaggilywort/IDEE dans la révision 20, et utiliser 4 et 10 pour spécifier l'intervalle de révisions opérationnelles.
$ svn diff -r 4:10 http://svn.red-bean.com/projets/frabnaggilywort/IDEE@20 Index: frabnaggilywort/IDEE =================================================================== --- frabnaggilywort/IDEE (revision 4) +++ frabnaggilywort/IDEE (revision 10) @@ -1,5 +1,5 @@ -L'idée de ce projet est de fournir un logiciel qui peut frabber un -naggily wort. Frabber les naggilys worts est particulièrement difficile -et ne pas le faire correctement aurait des conséquences inimaginables. -Nous devons donc utiliser des mécanismes de vérification des -entrées et des données du dernier cri. +L'idée de ce projet est de fournir un logiciel client-serveur qui peut +frabber un naggily wort de manière distante. Frabber les naggilys worts +est particulièrement difficile et ne pas le faire correctement aurait +des conséquences inimaginables. Nous devons donc utiliser des mécanismes +de vérification des entrées et des données du dernier cri.
Paragraphe 18
Fortunately, most folks aren't faced with such complex situations. But when you are, remember that peg revisions are that extra hint Subversion needs to clear up ambiguity.

