Take Notes from Practical Subversion

Take Notes from Practical Subversion

Creating the Repository

Subversion has two kinds of repository type: Berkeley DB Repository and FSFS Repository. Default is FSFS Repository.

svnadmin create D:/svn_repository/repos

svn mkdir --parents file:///D:/svn_repository/repos/myproject/trunk file:///D:/svn_repository/repos/myproject/branches file:///D:/svn_repository/repos/myproject/tags -m "creating initial repository layout"

svn list file:///D:/svn_repository/repos/myproject/

Populating the Repository

svn import D:/ws/myproject file:///D:/svn_repository/repos/myproject/trunk -m "importing my project"

Checking Out a Working Copy

svn checkout file:///D:/svn_repository/repos/myproject/trunk D:/ws/svnprojetcs/myproject

Optional arguments:

-r or --revision argument, which allows to indicate what revision to check out. Default is the HEAD revision of the repository.

Getting Information about Working Copy

svn status (-v) print out the current status of working copy

svn info find information about items in working copy.

Adding, Copying, Renaming, and Removing Files

svn mkdir --parents src\java\org\kenny

svn add src\java\org\kenny\Hello.java

svn commit -m "commit messgae"

svn log -r BASE:HEAD

svn update

Copying and Moving Versioned Items

svn move Hello.java HelloWorld.java

svn copy HelloWorld.java HelloWorldCpoy.java

Deleting Versioned Items

svn delete HelloWorld.java


Although the file has been removed from the HEAD revision of the repository, it still exists in the previous revisions, and you can easily get the file back either by using svn copy to copy the file from the previous revision into your working copy.


svn copy --revision 10 file:///D:/svn_repository/repos/myproject/trunk/src/java/org/kenny/HelloWorld.java HelloWorld.java

Working with Branches and Tags

The difference between Branches and Tags:

Tags are used to mark a particular version or release of project so we can easily refer back to it later, normally they are just a copy of project at particular time and left them here.

A tag is intended to never be modified again (this may be enforced by various means).


Branches are different; they can be modified, and are used for further development. for example, we don't want our modification in the main development(trunk), maybe they are experimental code, and might never be committed to the mainline version.or maybe this is a branch we want to make a release from and only want to allow bug fixes.

In cases like these we might want to create a new development branch by making a separate

copy of the trunk and then commit our changes to the branch. If we later decide that the

changes are ready, they can be merged into the version of the project in the trunk and com-

mitted so that everyone can see them.

Creating Branches and Tags

svn copy file:///D:/svn_repository/repos/myproject/trunk file:///D:/svn_repository/repos/myproject/tags/0.9-release -m "tagging 0.9 release"

svn diff file:///D:/svn_repository/repos/myproject/trunk file:///D:/svn_repository/repos/myproject/tags/0.9-release

Merging Changes between Branches

The merge command has three modes of operation.

In the first, you give the command two source URLs (with optional revisions specified with @REVNUM at the end of the URL), and it will merge the differences between the two sources

into your current working directory (or another directory if it’s specified on the command line).

svn merge file:///D:/svn_repository/repos/myproject/tags/0.9-release file:///D:/svn_repository/repos/myproject/tags/1.0-release D:\ws\svnprojetcs\0.9-branch

Merge a particular change or set of changes from one branch into another

svn merge -r 12:13 file:///D:/svn_repository/repos/myproject/branches/0.9-branch D:/ws/svnprojetcs/myproject_trunk

Use “SVN MERGE” to Revert a Change

svn merge -r 9:8 HelloWorld.java

Apply the change needed to go from revision 9 of HelloWorld.java to revision 8 of HelloWorld.java to the version of HelloWorld.java

Switching to another Branch

svn switch can move checked-out working copy to another branch in the repository. Standard use is either to migrate an entire working copy from one branch to another or, more commonly, to move specific parts of your working copy to another branch.

svn switch file:///D:/svn_repository/repos/myproject/trunk D:\ws\svnprojetcs\0.9-release

svn switch file:///D:/svn_repository/repos/myproject/tags/0.9-release D:\ws\svnprojetcs\0.9-release

Changing a Repository URL with svn switch --relocate

This would happen when the URL you use to access your Subversion repository has changed.

svn switch --relocate file:///D:/svn_repository/repos/myproject http://localhost/svn/myproject/

Removing Old Branches

svn list file:///D:/svn_repository/repos/myproject/branches/

svn delete file:///D:/svn_repository/repos/myproject/branches/0.9-branch/


Working with Locks

This often happens when working with binary files which don’t work in a nonlocking model.

svn lock logo.jpg –message “Working on drawing for the next hour”

svn unlock logo.jpg

svn unlock –force http://example/repos/trunk/logo.jpg

Properties

Associate arbitrary metadata with files, directories, and even revisions in the repository.


svn proplist

Tell what properties have been set on a particular versioned resource.

svn proplist index.html

svn propget command prints out the value of a given property.

svn propget svn:mime-type index.html


svn propset and svn propedit commands set and change he value of a given property.

svn propset svn:mime-type image/png logo.png


Special Properties

svn:mime-type, svn:ignore,

svn:needs-lock

Specify which files should be locked before editing them. When this property is set on a file it will be read-only until svn lock is called on the file. This is useful in order to ensure that locking of unmergable files occurs before they are edited.

svn:keywords

/* $URL$

* $Rev$

* $Author$

* $Date$

* $Id$

*/

svn:executable

svn blame

Output in each line the version that line originates from, and the username of author of that line.

svn blame D:\ws\svnprojetcs\0.9-release\src\src\java\org\kenny\HelloWorld.java

svn cleanup

Return everything to working order, by finishing up all unfinished work and removing stray locks.

svn export

The export command is useful when you need to release a version of your software and don’t want to include all the administrative directories from a working copy.

svn export file:///D:/svn_repository/repos/myproject/tags/1.0-release D:\ws\svnprojetcs\release-1.0

Choosing a Repository Type

Subversion has two kinds of repository: FSFS or Berkeley DB, default is FSFS. and it is highly recommended we go with the FSFS default repository type.

svnadmin create --fs-type bdb D:/svn_repository/repos-bdb

svnadmin create --fs-type fsfs D:/svn_repository/repos-fsfs

Tools for Working with the Repository

svnadmin

svnadmin create

Using svnadmin to Manipulate Transactions

Use svnadmin lstxns to find old, abandoned transactions, and use svnadmin rmtxns to remove them

svnadmin lstxns /path/to/repository

svnadmin rmtxns /path/to/repository 2

svnlook

A safer way to work with the repository

svnlook uuid prints the UUID of a repository.

svnlook youngest prints the current HEAD revision number of the repository

Backups

svnadmin hotcopy D:/svn_repository/repos D:/repos-backups/repos0714

Optional arguments:--clean-logs

Dumping and Loading Repository Contents

svnadmin create D:/svn_repository/new-repos0714

svnadmin dump D:/svn_repository/repos > D:/repos-backups/repos0714.dump

svnadmin load D:/svn_repository/new-repos0714 < D:/repos-backups/repos0714.dump

The above step is equivalent as followings:

svnadmin create D:/svn_repository/new-repos0714

svnadmin dump D:/svn_repository/repos | svnadmin load D:/svn_repository/new-repos0714


svnadmin dump can be used in conjunction with the svndumpfilter tool to migrate

portions of a repository from one repository to another or to remove specific portions of

a repository if data that can’t be allowed to exist in the repository at all has been accidentally

committed.

svnadmin dump D:/svn_repository/repos| svndumpfilter include trunk | svnadmin load D:/svn_repository/new-repos0714


svnadmin dump --incremental -r 0:5 D:/svn_repository/repos > D:/repos-backups/dump-0-5

svnadmin dump --incremental -r 6:10 D:/svn_repository/repos > D:/repos-backups/dump-6-10


svnadmin create D:/svn_repository/repos-incremental

svnadmin load D:/svn_repository/repos-incremental < D:/repos-backups/dump-0-5

svnadmin load D:/svn_repository/repos-incremental < D:/repos-backups/dump-6-10


Networking with ra_dav

Integration Subversion with Apache Server

Add the following to httpd.conf:

LoadModule dav_module modules/mod_dav.so

LoadModule dav_svn_module modules/mod_dav_svn.so

<Location /svn>

DAV svn

SVNPathAuthz off

SVNPath D:/svn_repository/repos

AuthType basic

AuthName "Kenny Subversion Repository"

AuthUserFile "D:/Program Files/Apache Software Foundation/Apache2.2.6/bin/svn-passwd"

<LimitExcept GET PROPFIND OPTIONS REPORT>

Require valid-user

</LimitExcept>

</Location>

Create and Modify user/pass

htpasswd -c svn-passwd kenny

htpasswd svn-passwd kenny

SVNParentPath

This indicates that a single parent directory contains several Subversion repositories, so we don’t have to list them each in their own individual Location block.

SVNListParentPath option enables a web browser accessing SVNParentPath to display a list of repositories

And these options are exclusive with SVNPath.

Networking with ra_svn

svnserve --daemon --root D:/svn_repository/repos

Configuration file: conf/svnserve.conf in each Subversion repository.

Optional flags: --listen-host, --threads

svn checkout svn://localhost/myproject/trunk D:/ws/svnprojetcs/myproject-svn

mod_auth

Use Apache htpasswd command to create file including username and password

htpasswd -c svn-passwd kenny

Read-only access available without an account

<LimitExcept GET PROPFIND OPTIONS REPORT>

Require valid-user

</LimitExcept>

Restricting User Actions with mod_authz_svn

mod_authz_svn allows to define authorization rules in a simple text file.

LoadModule authz_svn_module modules/mod_authz_svn.so


And add the following line to <Location /svn> section.

AuthzSVNAccessFile D: /svn_repository/repos/conf/authzSVNAccessFile


Combining "Satisfy Any" and "Require valid-user" together allows anonymous users access to the repository for anything that’s allowed for all users (specified as an * in the AuthzSVNAccessFile), but for anything that requires a specific user or group the client will be required to authenticate.

AuthzSVNAccessFile config file

It contains several sections, one special section named [groups] that contains definitions for groups of users, and a number of other sections, each of which has a path specification for a name and contains users or groups and their access rights. To distinguish groups from users in the permission specifications, groups are prefixed with an @. An * can be used in the place of a user or a group as a wildcard that indicates all users have that kind of access. Access rights can be specified as r for read, w for write, rw for read-write, or nothing for no access at all.

[groups]

committers = tom,dick,harry,michelle,tracey,jessica,mark,dave

documenters = phil,fred,rob,james

[/]

# give everyone read access to the whole repository

* = r

@committers = rw

[/trunk/docs]

# documentation people have read-write access

@documenters = rw

[/tags]

# phil is the release manager, so he lays down the tags

phil = rw

[/private]

# default to denying access in this section

* =

# but give committers read-write and documenters read access

@committers = rw

@documenters = r

If combining mod_authz_svn with the SVNParentPath directive, you need to be a bit careful. If you just specify raw paths such as the previous AuthzSVNAccessFile, those rules will be applied to all of the repositories under the SVNParentPath directory. If you want to limit the rule to a particular repository, you prefix the path with the repository name and a colon, like this:

[groups]

javacommitters = tom,dick,harry,michelle,tracey,jessica,mark,dave

perlcommitters = simon,casey,larry,chip

[java:/]

# give everyone read access to the whole java repository

* = r

@javacommitters = rw

[perl:/]

# everyone has read access to the perl repository

* = r

@perlcommitters = rw

Encrypting Traffic with mod_ssl

Use mod_ssl to provide access to repository via https instead of http.

1. Create a self-signed certificate

cd D:\OpenSSL\bin

openssl genrsa help

openssl genrsa -des3 -out "D:\Program Files\Apache Software Foundation\Apache2.2.6\bin\server-svn.key" 4096

2. Then create a certificate signing request

openssl req -new -key server-svn.key -out server-svn.csr

3. Sign the certificate signing request

openssl x509 -req -days 365 -in server-svn.csr -signkey server-svn.key -out server-svn.crt

4. Add following lints to httpd.conf

LoadModule ssl_module modules/mod_ssl.so

Include conf/extra/httpd-ssl.conf

Require clients always access the repository via SSL, add following lines to Location section:

<IfDefine SSL>

SSLRequireSSL

</IfDefine>

Compression

Use apache module mod_deflate to compress HTTPtraffic

1.Uncooment "LoadModule deflate_module modules/mod_deflate.so" in httpd.conf.

2.Add a SetOutputFilter DEFLATE directive to repository’s Location block in httpd.conf

SetOutputFilter DEFLATE

Logging

CustomLog logs/svn_logfile "%t %{SVN-ACTION}e %u" env=SVN-ACTION

log a time-stamp, an SVN action, and a username to a log file named logs/svn_logfile

Choosing a Repository Layout

For single projects, the standard trunk/branches/tags repository layout works great.

branches

tags

trunk

For multiple projects, there are two basic schools of thought on the subject, the first being to do the following:

branches

project1

project2

tags

project1

project2

trunk

project1

project2

The second is to do this:

project1

branches

tags

trunk

project2

branches

tags

trunk

Best Practices

Avoid Locking Mergeable Files

Committing Changes:

Commit Early, Commit Often

Make Small, Atomic Changes

Use Meaningful Log Messages

Don’t Break the Tree

Use svn switch to only branch small portions of the tree, instead of something as large as the entire trunk.

Releases

Making a Release Branch

A release branch is a branch created from development trunk once you determine that all the goals for your release have been reached. After the release branch has been created, all testing of the release should be done on the branch, and development work can continue on the trunk. The majority of the developers can turn their attention to working on the next phase of the project, while those who are tasked with making the release can feel free to take their time testing the branch without worrying about holding up development work.

svn copy svn://example.org/repos/trunk

svn://example.org/repos/branches/release-1.0 -m "create release branch"

Merge fixes in Release Branch’s working copy, and then commit to Release Branch

svn merge -r 2070:2071 svn://example.org/repos/trunk .

svn commit -m "merge fix for issue #175 into the release branch."

Finalizing the Release

svn cp svn://example.org/repos/branches/release-1.0 svn://example.org/repos/tags/1.0 -m "tag version 1.0"

Once the tag is created, the release is finalized, and if a problem is found, a new release needs to be created if you want to fix it.

Use "svn export" to roll out distribution

Integration Subversion with CruiseControl to automate test

Integrating Subversion with Other Tools

Ant Integration:svnant

Download svnant from http://subclipse.tigris.org/svnant.html.

The next step is to tell Ant how to find SVNAnt task by adding the following to build.xml file:

<path id= "svnant.classpath" >

<fileset dir= "D:/kenny/software/Subversion/svnant-1.0.0/lib" >

<include name= "*.jar" />

</fileset>

</path>

<typedef resource="svntask.properties" classpathref="svnant.classpath" />

Then we can use svn task in ant:

<target name="svn-checkout">

<svn>

<checkout url="http://localhost/svn/dms/trunk/"

destPath="dms" />

</svn>

</target>

Eclipse Integration: http://subclipse.tigris.org/

TortoiseSVN http://tortoisesvn.net


Access via custom protocol (svn://)
svnserve -d -r /usr/local/repositories
-d|--daemon, -r|--root

edit $repos/conf/svnserve.conf:
[general]
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz
realm = My First Repository

in passwd:
[users]
harry = foopassword
sally = barpassword
Access via custom protocol with SSL encryption (svn+ssh://)
 $ svn co svn+ssh://hostname/home/svn/myproject myproject --username user_name
NOTE: You must use full path (/home/svn/myproject) to access SVN repository using this access method.

Start svnserve at bootup

cd /etc/init.d/
sudo vi svnserve
svnserve -d -r /usr/local/svn/repository_name
or we can download this init script and to start it manually, run sudo /etc/init.d/svnserve start.
sudo chmod +x /etc/init.d/svnserve
Add the script to the boot sequence
sudo update-rc.d svnserve defaults

Creating Branches and Tags
svn copy file://path/to/repos/branches/my-development-branch \
file:///path/to/repos/tags/0.9-release \
-m "create development branch from version 0.9 tag"
List Repository
svn list -R file:///path/to/repos

Material:

Installation of Subversion on Ubuntu with Apache

How-To: Set up SVN with Apache2 in Linux (Ubuntu)

https://help.ubuntu.com/community/Subversion

Setting Up an Ubuntu Subversion Server


Post a Comment

Labels

Java (159) Lucene-Solr (110) All (60) Interview (59) J2SE (53) Algorithm (37) Eclipse (35) Soft Skills (35) Code Example (31) Linux (26) JavaScript (23) Spring (22) Windows (22) Web Development (20) Tools (19) Nutch2 (18) Bugs (17) Debug (15) Defects (14) Text Mining (14) J2EE (13) Network (13) PowerShell (11) Chrome (9) Continuous Integration (9) How to (9) Learning code (9) Performance (9) UIMA (9) html (9) Design (8) Dynamic Languages (8) Http Client (8) Maven (8) Security (8) Trouble Shooting (8) bat (8) blogger (8) Big Data (7) Google (7) Guava (7) JSON (7) Problem Solving (7) ANT (6) Coding Skills (6) Database (6) Scala (6) Shell (6) css (6) Algorithm Series (5) Cache (5) IDE (5) Lesson Learned (5) Miscs (5) Programmer Skills (5) System Design (5) Tips (5) adsense (5) xml (5) AIX (4) Code Quality (4) GAE (4) Git (4) Good Programming Practices (4) Jackson (4) Memory Usage (4) OpenNLP (4) Project Managment (4) Python (4) Spark (4) Testing (4) ads (4) regular-expression (4) Android (3) Apache Spark (3) Become a Better You (3) Concurrency (3) Eclipse RCP (3) English (3) Firefox (3) Happy Hacking (3) IBM (3) J2SE Knowledge Series (3) JAX-RS (3) Jetty (3) Restful Web Service (3) Script (3) regex (3) seo (3) .Net (2) Android Studio (2) Apache (2) Apache Procrun (2) Architecture (2) Batch (2) Build (2) Building Scalable Web Sites (2) C# (2) C/C++ (2) CSV (2) Career (2) Cassandra (2) Distributed (2) Fiddler (2) Google Drive (2) Gson (2) Html Parser (2) Http (2) Image Tools (2) JQuery (2) Jersey (2) LDAP (2) Life (2) Logging (2) Software Issues (2) Storage (2) Text Search (2) xml parser (2) AOP (1) Application Design (1) AspectJ (1) Bit Operation (1) Chrome DevTools (1) Cloud (1) Codility (1) Data Mining (1) Data Structure (1) ExceptionUtils (1) Exif (1) Feature Request (1) FindBugs (1) Greasemonkey (1) HTML5 (1) Httpd (1) I18N (1) IBM Java Thread Dump Analyzer (1) JDK Source Code (1) JDK8 (1) JMX (1) Lazy Developer (1) Mac (1) Machine Learning (1) Mobile (1) My Plan for 2010 (1) Netbeans (1) Notes (1) Operating System (1) Perl (1) Problems (1) Product Architecture (1) Programming Life (1) Quality (1) Redhat (1) Redis (1) Review (1) RxJava (1) Solutions logs (1) Team Management (1) Thread Dump Analyzer (1) Troubleshooting (1) Visualization (1) boilerpipe (1) htm (1) ongoing (1) procrun (1) rss (1)

Popular Posts