Using SVN To Manage Source RTL: CS250 Tutorial 1 (Version 092509a) September 25, 2009 Yunsup Lee
Using SVN To Manage Source RTL: CS250 Tutorial 1 (Version 092509a) September 25, 2009 Yunsup Lee
te
mit
, update mit
add, com
Figure 1: Basic SVN model. Users checkout versions from the central repository into private working directories.
Getting started
Before using the CS250 toolow you must run the course setup script with the following command. The course setup script will set the SVNREPO to https://isvn.eecs.berkeley.edu/cs250. The SVN commands use this environment variable to determine the location of the repository. % source ~cs250/tools/cs250.bashrc
SVN Repository
Whenever you access the SVN repository for the rsttime, it will complain about the certicate. This is because the certicate on the server is not issued by a trusted authority. Go ahead and accept the certicate permanently. The following commands rst create a test directory and a typical SVN directory structure, test le, and then add them to the SVN repository. The trunk directory is supposed to be the main development line for the project. The branches directory is supposed to be a place for branches. The tags directory is used for creating tags. % % % % % % % mkdir svntest cd svntest mkdir trunk branches tags cd trunk echo "Fred : 510-555-0123" > phone-list.txt cd ../.. svn add svntest
Although the directory and le are added to the repository they are not actually in the repository until you commit them. Adding directories and les simply lets SVN know that you want the versioning system to track these les. You need to commit the directory and le before they are permanently in the repository. You can use the following command to check the current status of all les. % pwd tut1/yunsup/svntest % svn status The status information should reect that phone-list.txt has been locally added. Now you will commit your new les to the repository. % pwd tut1/yunsup/svntest % cd .. % svn commit svntest The svn commit command takes a list of les and directories as an argument. The svn commit command is recursive, so committing a directory will eectively commit all les (and subdirectories) within the directory. If you do not specify any les or directories, then SVN will commit the current directory. After executing the svn commit command, you will be able to enter a log message using your default text editor. You can change the default text editor by setting the environment variable SVN EDITOR. You can add the environment variable to your default shell script so that the variable is set automatically in the future whenever you login. % export SVN_EDITOR=vim Use the svn status command again to verify that the phone-list.txt le has now been committed into the repository. The status information lists a revision number. Every change is given a
unique revision number. These numbers are assigned by the SVN system, and users should usually avoid working with revision numbers directly. Our nal step is to delete your working directory. It is essential that you always keep in mind the dierence between what is in the repository versus what is in the repository. As long as all your new les have been added, and all your changes have been committed then there is nothing wrong with deleting your working directory and doing a clean checkout. % pwd tut1/yunsup % cd .. % rm -rf yunsup
SVN Repository
% pwd tut1 % svn checkout $SVNREPO/yunsup/svntest/trunk svntest Now say Freds phone number has changed. % cd svntest % perl -i -pe s/Fred.*/Fred : 510-555-4567/ phone-list.txt You can use the svn diff command to see how your current working directory diers from the repository. For example, if you use the svn diff command in the svntest directory, it will show that you have updated Freds phone number. The revision number X is the number stored on the server.
CS250 Tutorial 1 (Version 092509a), Fall 2009 % pwd tut1/svntest % svn diff Index: phone-list.txt =================================================================== --- phone-list.txt (revision X) +++ phone-list.txt (working copy) @@ -1 +1 @@ -Fred : 510-555-0123 +Fred : 510-555-4567 And nally you commit your changes with an appropriate log message. % svn commit
You are done making your changes and everything has been committed so you can now delete your working directory. % pwd tut1/svntest % cd .. % rm -rf svntest
6
User B Working Directory
SVN Repository
Make changes and add new files svn add svn commit svn update
updates
% echo "Jane : [email protected]" >> email-list.txt % cat phone-list.txt Fred : 510-555-4567 Jane : 510-555-0021 % cat email-list.txt Fred : [email protected] Jane : [email protected] % svn add email-list.txt % svn commit User Bs nal svn commit command commits both his changes to the phone-list.txt le as well as his newly added phone-list.txt le. Notice that at this point in time, User As working directory is out-of-date (it does not contain the new email-list.txt le nor does it contain the updated phone-list.txt le). User A can use the svn status --show-updates command to realize that her working directory is out-of-date with respect to the central repository. If the User A doesnt use the --show-updates option then it prints locally modied items without accessing the central repository. % pwd tut1/userB/svntest % cd ../../userA/svntest % svn status --show-updates * X phone-list.txt
CS250 Tutorial 1 (Version 092509a), Fall 2009 * email-list.txt * X . Status against revision: Y
Notice that the phone-list.txt le and the email-list.txt le have an asterisk mark which means a newer version exists on the server. X is the local revision number, while Y is the revision number stored on the server. User A can use the svn update command to bring her working directory in sync with the central repository. % pwd tut1/userA/svntest % ls -a .svn phone-list.txt % cat phone-list.txt Fred : 510-555-4567 % svn update % ls -a .svn email-list.txt phone-list.txt % cat phone-list.txt Fred : 510-555-4567 Jane : 510-555-0021 % cat email-list.txt Fred : [email protected] Jane : [email protected] If User A uses svn status --show-updates again, she will see that her les are now up-to-date with respect to the central repository. As another example, User A can use the following commands to delete a le and then restore that le to the most current version in the repository. % pwd tut1/userA/svntest % rm -f phone-list.txt % svn update If User A really wants to delete the le from the repository, then she can rst delete the le from the working directory and then use the svn remove command. These removals are not visible to other users until User A does a svn commit. % pwd tut1/userA/svntest % rm -f email-list.txt % svn remove email-list.txt % svn commit If User A wants to rename or move les, then she can use the svn move command. % pwd tut1/userA/svntest % svn move phone-list.txt telephone-list.txt % svn commit
If User B now does a svn update, his copy of email-list.txt will removed and the le phone-list.txt will be renamed as telephone-list.txt. Finish up by deleting the working directories. % pwd tut1/userA/svntest % cd ../.. % rm -rf userA % rm -rf userB
Resolving Conicts
In the previous section you examined what happens when two users simultaneously modify les in the same project. Notice however, that in the previous example, the two users never modied the same line of a le at the same time. In this section you will examine how to handle these conicts. Figure 5 shows the timeline of SVN commands involved in this section.
SVN Repository
svn checkout
files files
svn update
updates
Figure 5: Timeline for two users with conicts Begin with both User A and User B doing a standard checkout. % pwd tut1 % mkdir userA
CS250 Tutorial 1 (Version 092509a), Fall 2009 % % % % % % % cd userA svn checkout $SVNREPO/yunsup/svntest/trunk svntest cd .. mkdir userB cd userB svn checkout $SVNREPO/yunsup/svntest/trunk svntest cd ..
Now assume that User A changes Freds phone number as follows. % pwd tut1 % cd userA/svntest % perl -i -pe s/Fred.*/Fred : 510-555-3333/ telephone-list.txt % svn commit Now assume that User B changes Freds phone number to a dierent number. % pwd tut1/userA/svntest % cd ../../userB/svntest % perl -i -pe s/Fred.*/Fred : 510-555-5555/ telephone-list.txt % svn commit Sending telephone-list.txt Transmitting file data .svn: Commit failed (details follow): svn: Out of date: yunsup/svntest/trunk/telephone-list.txt in transaction X-1 svn: Your commit message was left in a temporary file: svn: tut1/userB/svntest/svn-commit.tmp Notice that User B has received an error when trying to commit his changes. The SVN repository has realized that User Bs change conicts with User As original change. So User B must do a svn update rst. % pwd tut1/userB/svntest % svn update Conflict discovered in telephone-list.txt. Select: (p) postpone, (df) diff-full, (e) edit, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: e The SVN messages during the update indicate that there is a conict in telephone-list.txt. A conict simply means that there is a le in the current working directory which has lines which dier from what is in the repository. SVN tries to merge les so that only true conicts are reported. In other words, if two people change dierent parts of the same le, then usually SVN will be able to merge the two versions without a conict. In this case both User A and User B changed the exact same line, so SVN does not know which modication should take priority. SVN requires that users resolve conicts by hand. You can pick a way to resolve a conict by selecting an option when SVN asks. Assume you picked the edit option. The text editor will show the following.
CS250 Tutorial 1 (Version 092509a), Fall 2009 1 2 3 4 5 6 <<<<<<< .mine Fred : 510-555-5555 ======= Fred : 510-555-3333 >>>>>>> .rX Jane : 510-555-0021
10
The content involved in the conict is delimited by <<<<<<< and >>>>>>>. Assume that User B wants to override User As earlier change. Leave the text from the mine part, and delete everything else to make the following. 1 Fred : 510-555-5555 2 Jane : 510-555-0021 After saving the le SVN will prompt you again, but with a new option called resolved. Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: r Now User Bs commit has succeeded and essentially User As changes will have been overridden. User A can then do a svn update to synchronize her working directory. A common rule of thumb is to always do an update (to catch conicts) before doing a commit. Finish up by deleting the working directories. % pwd tut1/userB/svntest % cd ../.. % rm -rf userA % rm -rf userB
Using Tags
In the previous sections you have learned how to use SVN to manage various versions of your source RTL. You have primarily focused on how to manipulate the most current version in the repository. Sometimes when you reach a milestone, you want to mark a version so that you can retrieve it at a later time even if you have already made (and committed) many other changes. You can do this with SVN tags. A tag is simply a symbolic name you give to a specic version of several les. The following commands checkout the svntest directory, add two new les, and then tags everything. It is important to always do a svn update and a svn commit before doing a svn copy since the tag operation works on the most current version in the repository. If you have made changes in your local directory which are not yet committed then this could incorrectly tag the les. % pwd tut1 % svn checkout $SVNREPO/yunsup/svntest/trunk svntest % cd svntest
CS250 Tutorial 1 (Version 092509a), Fall 2009 % % % % % % % % % echo "Fred : [email protected]" > email-list.txt echo "Jane : [email protected]" >> email-list.txt echo "Fred : SODA 802" > office-list.txt echo "Jane : SODA 903" >> office-list.txt svn add email-list.txt svn add office-list.txt svn update svn commit svn copy $SVNREPO/yunsup/svntest/trunk \ $SVNREPO/yunsup/svntest/tags/checkpoint
11
The above commands tag all three les (telephone-list.txt, email-list.txt, and office-list.txt) with the symbolic tag checkpoint. You can now retrieve this version of the les at any time by using this tag. To see how this works rst commit some additional changes. % pwd tut1/svntest % echo "Sara : 510-555-0234" >> telephone-list.txt % echo "Sara : [email protected]" >> email-list.txt % echo "Sara : SODA 810" >> office-list.txt % svn update % svn commit Now delete the working directory and try checking out two dierent versions of the les. % pwd tut1/svntest % cd .. % rm -rf svntest % mkdir tagged-version % cd tagged-version % svn checkout $SVNREPO/yunsup/svntest/tags/checkpoint svntest % cd .. % mkdir current-version % cd current-version % svn checkout $SVNREPO/yunsup/svntest/trunk svntest % cd .. % cat tagged-version/svntest/email-list.txt Fred : [email protected] Jane : [email protected] % cat current-version/svntest/email-list.txt Fred : [email protected] Jane : [email protected] Sara : [email protected] The checked out version in the tagged-version directory corresponds to the checkpoint symbolic tag, while the version in the current-version directory corresponds to the most recent version in SVN. Tagging is particularly useful when you reach a working milestone. You can tag your project and then at any time you can go back and retrieve the working version as of that milestone. Finish up by deleting the working directories.
CS250 Tutorial 1 (Version 092509a), Fall 2009 % pwd tut1 % cd .. % rm -rf tut1
12
13
Review
In this tutorial you have learned how to use SVN to manage your source RTL. You have learned how to add new les to the repository, checkout les from the repository, and commit local changes into the repository. The following table lists the SVN commands that you will use most frequently in this course. svn svn svn svn svn svn svn svn svn checkout (co) add commit (ci) update (up) remove (rm) move (mv) status (st) diff copy (cp) Checks out les from the repository into the working directory Adds new les to repository (must commit after adding) Commits les in working directory into the repository Brings working directory in sync with respect to repository Removes le from SVN Rename les from SVN Shows status of les in working dir compared to current version in repo Shows how les in working dir dier from current version in repo Adds a symbolic tag for current version
Acknowledgements
Many people have contributed to versions of this tutorial over the years. The tutorial was originally developed for 6.375 Complex Digital Systems course at Massachusetts Institute of Technology by Christopher Batten. Contributors include: Krste Asanovi, John Lazzaro, Yunsup Lee, and John c Wawrzynek. Versions of this tutorial have been used in the following courses: 6.375 Complex Digital Systems (2005-2009) - Massachusetts Institute of Technology CS250 VLSI Systems Design (2009) - University of California at Berkeley