Post on 21-Jan-2021
1
Development: Revision Control
November 26, 2007
Class Meeting 14
* Notes adapted by Lenwood Heath from previous work by other members of the CS faculty at Virginia Tech
Lenwood Heath, Virginia Tech, Fall, 2004 2
Software Development Process
� Creation of source files� Text editors
� vi� emacs
� Revision (version) control systems� rcs / cvs
� svn
� Compilation and linking
� Running, testing, revising
2
Lenwood Heath, Virginia Tech, Fall, 2004 3
Development on a Server
Lenwood Heath, Virginia Tech, Fall, 2004 4
Problems With Direct Access
� Every time a source file is edited, the old version is lost.
� The project as a whole can be in an inconsistent state while it is being edited.
� Developers may simultaneously edit the same source file, leading to multiple,
irreconcilable versions.
3
Lenwood Heath, Virginia Tech, Fall, 2004 5
How not to keep multiple versions of your files
Lenwood Heath, Virginia Tech, Fall, 2004 6
What is revision control?
� Maintains versions of project files
� logged and archived
� enforces consistency
� Especially applicable when projects include:
� multiple files
� multiple developers
� maintenance (corrective and enhancing)
4
Lenwood Heath, Virginia Tech, Fall, 2004 7
Why do you need revision control?
� Software development is normally done in teams
� Multiple people may be responsible for code in a single file
� You may want to freeze a working version and create a new revision branch
� You may want to roll back development to a previous point in time
Lenwood Heath, Virginia Tech, Fall, 2004 8
Example need for version control
� Acute problem: working on a website
� Can rarely test your changes locally for dynamic sites
� If you upload the wrong version of a file –poof, site is gone
� Google caching is your friend
� No substitute for real version control
5
Lenwood Heath, Virginia Tech, Fall, 2004 9
Team Project Development
Lenwood Heath, Virginia Tech, Fall, 2004 10
Concurrent Versions Control
6
Lenwood Heath, Virginia Tech, Fall, 2004 11
Overview of RCS and SVN
� Maintains all committed versions of source files — SVN saves differences only
� Each version of each file has a unique revision number (e.g., 1.1, 1.2, 1.3.2.2)
� Supports merging two edits of the same file
� Can place metadata into source files
� Locking files for one user to edit
Lenwood Heath, Virginia Tech, Fall, 2004 12
Comparison of RCS / CVS / SVN
� RCS – Designed for multiple users on one machine to work together on a project
� CVS – Central machine with multiple client machines working on a project
� SVN – Same as CVS except better version history / atomicity / consistent data handling / better branching
7
Lenwood Heath, Virginia Tech, Fall, 2004 13
Short plug: Use SVN where possible
Lenwood Heath, Virginia Tech, Fall, 2004 14
Everyday SVN Commands
Get files from repositoryco
Check changes into repositoryci
Clears out local changes to filesrevert
Check for updates in repositoryup
Show status of working filesstatus
DescriptionCommand
8
Lenwood Heath, Virginia Tech, Fall, 2004 15
Everyday SVN Usage
co
edit/compile/testci
revert
status
up
Lenwood Heath, Virginia Tech, Fall, 2004 16
SVN Example — checkout
$ svn co http://something.com/mine_projectmine_project
U mine_project/Makefile
U mine_project/mine1.c
$ cd mine_project/
9
Lenwood Heath, Virginia Tech, Fall, 2004 17
SVN Example — commit
$ vi Makefile
$ svn ci Makefile
Sending Makefile
Transmitting file data .
Committed revision 788.
Lenwood Heath, Virginia Tech, Fall, 2004 18
SVN Example — status
[anray2@console amadeus]$ svn status
? X2.fab.tmp
! .
M X2.fab
A test.cpp
M expDSO/loadWorld.C
10
Lenwood Heath, Virginia Tech, Fall, 2004 19
Branching and merging
� What happens when need to take a stable codebase and go in two different directions with it?
� Two different engines / feature sets
� What happens when you want to make the changes the official code?
Lenwood Heath, Virginia Tech, Fall, 2004 20
SVN branching
$ svn copy trunk branches/my-calc-branch $ svn status A + branches/my-calc-branch
11
Lenwood Heath, Virginia Tech, Fall, 2004 21
Checking out the newly created branch
$ svn checkout http://svn.example.com/repos/calc/branches/my-calc-branch
A my-calc-branch/Makefile
A my-calc-branch/integer.c
A my-calc-branch/button.c
Checked out revision 341.
-Can use svn switch also, but not recommended
Lenwood Heath, Virginia Tech, Fall, 2004 22
Time progression of codebase
12
Lenwood Heath, Virginia Tech, Fall, 2004 23
Merging
$ svn merge -r 343:344 http://svn.example.com/repos/calc/trunk
$svn status
U integer.c
$svn ci
Lenwood Heath, Virginia Tech, Fall, 2004 24
The ePaper trail
$ svn log -r 5:19 # shows logs 5 through 19 in chronological order
$ svn log -r 19:5 # shows logs 5 through 19 in reverse order
$ svn log -r 8 # shows log for revision 8
$ svn log foo.c
$ svn log http://foo.com/svn/trunk/code/foo.c
13
Lenwood Heath, Virginia Tech, Fall, 2004 25
Investigating old versions
� Can diff between revisions
svn diff –r 2:3 yourFile.c
� Can checkout old revisions, simply add a –r X to checkout revision X
svn co –r 100 http://svn.google.com
Lenwood Heath, Virginia Tech, Fall, 2004 26
Putting SVN info in your programs
� $Date – the last time a file was changed
� $Revision – the last known revision for a file
� $Author – Who last changed the file
� $HeadURL – Where the repository came from
� $Id – Combination of date / revision / author
14
Lenwood Heath, Virginia Tech, Fall, 2004 27
Locking files
� svn lock filename
� Owner of locked file can update
� svn unlock filename
� Normal operations for the file
� Possible to break locks with admin programs if needed
� svn info filename will give you information on the lock
Lenwood Heath, Virginia Tech, Fall, 2004 28
Other SVN Commands
Initialize a new SVN repositorycreate
Diff of working and repository filesdiff
Import files into repositoryimport
Remove file from repositoryrm
Add files to repositoryadd
DescriptionCommand
http://svnbook.red-bean.com/en/1.4/index.html
Details in this week's lab assignment