Thursday, May 17, 2012

Notes SVN


NotesSVN

Summary
Repository creation
Start the server
Start the server as a deamon
Installing SubEclipse plugin: Subversion plugin for Eclispe
Check-in project into SVN for first time, from Eclipse
Delete Project and Checkout Project from Eclipse
Other Help
Command Line
Windows - CollabnetSubversion - Upload Google Code
Visual Studio and AnkhSVN
SVN Concept
SVN status Flags
SVN server configuration workflow


Summary
========
Reference:http://svnbook.red-bean.com/en/1.1/svn-book.pdf

Subversion is installed on Fedora distributions:

svn             The command-line client program.
svnversion      reporting the state (in terms of revisions of the items present) of a
                working copy.
svnlook         inspecting a Subversion repository.
svnadmin        creating, tweaking or repairing a Subversion repository.
svndumpfilter   filtering Subversion repository dump streams.
mod_dav_svn     plug-in module for the Apache HTTP Server, used to make your repository
                available to others over a network.
svnserve        custom standalone server program, runnable as a daemon process or invokable by SSH;
                another way to make your repository available to others over a network.

Repository creation
===================

User "svn" created (passwd svn), mmsn's group member (chee, quilici als belong to this group). This account
will host the repository.

Log as svn user.

svnadmin create --fs-type fsfs /home/svn/mmsn
This creates the repository mmsn, that will contain all projects. Note that --fs-type fsfs force s to use fsfs instead of Berkley DB

Importing initial data
======================
0. Login as svn user

1. Create SVN style directory structure, on local machine, for the code to be imported.
$ mkdir tmpdir
$ cd tmpdir
$ mkdir BIS
$ mkdir BIS/trunk
$ mkdir BIS/branches
$ mkdir BIS/tags
$ cd BIS/trunk
$ mkdir bin build config lib src ....
$ cd ../..     i.e. go back up to ..../tmpdir  from ..../tmpdir/BIS/trunk

2. Import files manually or by eclipse
svn import . file:///home/svn/mmsn --message 'Initial import'
Adding         BIS
Adding         BIS/trunk
Adding         BIS/trunk/build
Adding         BIS/trunk/build/build
Adding         BIS/trunk/build/build.bat
Adding  (bin)  BIS/trunk/build/xml-apis.jar
Adding  (bin)  BIS/trunk/build/xercesImpl.jar
Adding         BIS/trunk/build/build.properties
Adding  (bin)  BIS/trunk/build/ant-launcher.jar
Adding  (bin)  BIS/trunk/build/ant.jar
Adding         BIS/trunk/build/build.xml
Adding         BIS/trunk/config
Adding         BIS/trunk/config/log4j.properties
Adding         BIS/trunk/config/bisJalopy.xml
Adding         BIS/trunk/lib
Adding         BIS/trunk/lib/licenses
Adding         BIS/trunk/lib/licenses/log4j.LICENSE
Adding  (bin)  BIS/trunk/lib/log4j-1.2.8.jar
Adding         BIS/trunk/src
Adding         BIS/trunk/bin
Adding         BIS/branches
Adding         BIS/tags


Committed revision 1.

$ cd ..
$ rm -rf tmpdir

$ cd mmsn
$  chmod -R 775 . This gives mmsn's group members r+w+x permissions in the repository

Following is not needed, just kept to remember
=====================================================================
#Start the server
#================
#svnserve -t -r /home/svn/. -t option means that we are going to use ssh to connect svn server, -r should allow to use relative paths
#when invoking the server (-r does not seem to work with -t option !!!!)
#
#Start the server as a deamon
#============================
#create a file under /etc/init.d: svnd
#
# more /etc/init.d/svnd
#!/bin/bash
#
# gdm-bootup-complete     This shell script removes the boot throbber from
#                         the login screen
#
# chkconfig:    5 99 1
# description: This shell script removes the boot throbber from the login screen

# source function library
#. /etc/rc.d/init.d/functions
#
#start() {
#        daemon --user=svn svnserve -t  1> /home/svn/svnd.log 2>&1
#}
#
#stop() {
#        killall -KILL svnserve
#}
#
#case "$1" in
#  start)
#        start
#        ;;
#  stop)
#        stop
#        ;;
#  *)
#         echo $"Usage: $0 {start|stop}"
#        exit 1
# esac
#
# exit 0
#
#Then add the svnd service with chkconfig:
#/sbin/chkconfig --add svnd
#/sbin/chkconfig --level 5 svnd on
#
#
#Change Security Context of some libraries (only on Linux running Fedora or Red Hat with SecureLinux turned on)
#chcon -t texrel_shlib_t /usr/local/lib/libsvn_fs_fs-1.so.0
#chcon -t texrel_shlib_t /usr/local/lib/libsvn_ra_svn-1.so.0
#chcon -t texrel_shlib_t /usr/local/lib/libsvn_repos-1.so.0
#chcon -t texrel_shlib_t /usr/local/lib/libsvn_subr-1.so.0

=====================================================================

Installing SubEclipse plugin: Subversion plugin for Eclispe
============================================================
0. If using a proxy, fill in proxy details at:
    Windows -> Preference -> Install/Update
1. Install plugin from Eclipse:
 a) Help -> Software Updates -> Find and Install -> Search for New Features to Install ->
 New Remote Site -> Fill in URL="http://subclipse.tigris.org/update_1.0.x"
 b) Click finish and follow update instructions.
 c) for deetailed instructions: see  http://subclipse.tigris.org/install.html
2. Change configuration in Eclipse:
   Windows --> Preferences --> Team --> SVN panel, change the SVN interface to JavaSVN(Pure Java)
3. Connect using ssh
   a) Window -> Show View -> Other -> SVN -> SVN Repository
   b) Right click any space within SVN Repository. New -> Repository Location:
   c) Enter: svn+ssh://enrol1/home/svn/mmsn   (repository that is created on the SVN server already)
   d) Choose authenticate by password or Key. If choose Key option, enter the location of the private-key file of the local machine. Ensure public key of local machine has been added to authorized_keys file of the remote machine.
4. SVN through http proxy
   a) Goto where subversion is installed, eg:
      c:\Documents and Settings\<user>\ApplicationData\Subversion\
   b) Edit the file called "servers" and modify the variables fors:
      http-proxy-host
      http-proxy-port
 

Check-in project into SVN for first time, from Eclipse
=======================================================
1. In Eclipse, right click on the project to be deposited into SVN for first time.
2. From the Context menu, select Team -> Share Project


Delete Project and Checkout Project from Eclipse
=================================================
1. Go to Eclipse and click on selected Project (eg. Notes[Notes\trunk]) and close the project
2. Delete contents of the project (Make sure you have a backup of all the files somewhere else)
3. From Eclipse, New->Other->Checkout project from SVN, using location:
      svn+ssh://<host>/home/svn/mmsn
   ... where host is the hostname (e.g. arnold)
4. Select Notes/trunk
5. Checkout using Project Wizard.



Other Help
==========
Check the manual in the Elipse's help section to get started.
Check the help manual for the commands.



Command lines
=============
To checkout the code
svn co svn+ssh://arnold/home/svn/mmsn/BIS/trunk/ BIS
To update
svn update --> check options in the manual

To rename, even when filenames have spaces
svn move svn://localhost/home/svn/QuantAnalytics/second\ text\ file  svn://localhost/home/svn/QuantAnalytics/Seee
svn update



Windows - CollabnetSubversion -  Upload Google Code
====================================================
Create local repository
- svnadmin create c:\svn_repo

Upload first item into local repository
- svn import u:\Notes\file.txt file:////c:/svn_repo/Notes -m "initial creation"

For sync'ing with Google the First Time, click on "reset this repository" in google code -> Source -> Checkout.

Syncing local repository to Google Code repository
 - svnsync init --username <Google User name> https://<webproject>.googlecode.com/svn file:////c:/svn_repo
 >>> Copied properties for revision 0.
 - svnsync sync --username <Google User name> https://<webproject>.googlecode.com/svn
 >>> Transmitting file data .
 >>> Committed revision 1.
 >>> Copied properties for revision 1.



 Visual Studio and AnkhSVN
 ===========================
 Assuming the repository has been created.
 1. Create a new folder in the repository.
    From VS.Net open the Repository Explorer by right click.
    Create a folder called myWeb say, in the repository.
2. To map h:\myWeb, where myWeb already has contents:
   Close any solutions.
   Create new Project -> Other Project Types -> Visual Studio Solutions -> Blank Solutions.
   Name = myWeb
   Location = H:\
   Add to Subversion
3. Fill in the Subversion path.
4. Start adding files.
   Click on the generic "Solution" in Solution Explorer and "Add Existing Items"  


SVN Concept
=============

Repository Vs Working Copy
- files that are edited are Working Copy Files.
- Working Copy is created by "checkout" the files from the Repository

File Status:  Unchanged Vs Locally Changed
- "svn commit" will do nothing if the file is unchanged.
- If Locally Changed, "svn commit" will commit changes to repository unless the file is Out of Date.

File Status:  Current Vs Out Of Date
- If Repository file has changed since last checkout or update, then it is Out of Date.
- "svn update" will merge local file into repository file.

svn checkout <SVN_path>/<Project Dir>
- Warning, the project path including the project name will be copied into the current directory. So ensure the current directory is the Parent of the intended project directory.

svn commit
- Push files to repository

svn update
- Pull filed from repository



SVN status Flags
================
A   The file, directory, or symbolic link item has been scheduled for addition into the repository.
C   The file item is in a state of conflict. That is, changes received from the server during an update overlap with local changes that you have in your working copy (and weren't resolved during the update). You must resolve this conflict before committing your changes to the repository.
D   The file, directory, or symbolic link item has been scheduled for deletion from the repository.
M   The contents of the file item have been modified. If you pass a specific path to svn status, you get information about that item alone:



SVN server configuration workflow
===================================
RHEL5 has got subversin 1.6.11 pre-installed for both i386 and x86_64
To use Subversion with R, the work needs to be organized a Rstudio Projects.

1. To check if the svnserver starts automatically, whether svn is preinstalled for Red Hat, or self install later, type:
  ls -laF /etc/init.d/svnserve
to see if the file exists. This file runs a script to start the daemon.

2. Create svn user and group, type:
sudo useradd svn  - use id svn to check user details
sudo passwd svn   - make password for svn -> "svn"
sudo usermod  -a -G R_POC_TEAM svn    - this puts the user "svn" to the group called R_POC_TEAM.

Ensure that all other user of svn is in the same group called "R_POC_TEAM". To check which groups the users are in, type:
sudo more /etc/passwd

3. Create the SVN repository for all members of group.
- this is done only ONCE, when a new VM and subversion is installed.
- all users and the 'svn' user need to be in the same group. In this example, all these users belong to a group called R_POC_TEAM. If this is not true, make it so.
- Login as svn user.
- create the repository called QA, type:
svnadmin create --fs-type fsfs /home/svn/QA

This creates the repository QA, that will contain all projects. Note that --fs-type fsfs is the preferred filesystem for svn rather than the Berkley DB filesystem (see manual).

4. Check the file /etc/services. If it does not contain the following lines, then add them:
svn    3690/tcp     # Subversion
svn    3690/udp     # Subversion

5. Configuring Authentication and Authorization
- LOGIN AS USER called 'svn'
- go to the QA repository, eg:
    cd /home/svn/QA
- Create a file under ...QA/conf/svnserve.conf, with the following content:
[general]
password=db = passwd
realm = QA realm
anon-access = read
auth-access = write
...... passwd is actually the word "passwd".

- Ensure the file called 'passwd' exist under ...QA/conf/ and that it has the following content:
[users]
harry = harryssecret
sally = sallyssecret

.... where harry and sally are valid users in the linux box.


6. Hide the absolute path of the svn server and provide relative paths to user only.
Edit this file: /etc/rc.d/init.d/svnserve

by adding "-r /home/svn" to the following line if it exist, so that it becomes:
args="--daemon --pid-file=${pidfile} $OPTIONS  -r /home/svn"

Now when the svn server is mentioned, it is done by:
<svn server>/QA   instead of  <svn server>/home/svn/QA


The following information are for references:
- Access SVN. The URL pointing to the repository is:
svn://<HOST>/QA
svn://localhost/QA

- Some svn admin commands: svnadmin, svnlook, svndump, svndumpfilter, svnsync

- svnlook info <repos>      - prints information for the repository at <repos>.
                            The information include author, date, number of lines of log, log message

- sudo killall svnserve     - force termination of any active svnserve services. Also solves the error with message:
                            " svnserve: Can't bind server socket: Address already in use"

- sudo /etc/init.d/svnserve start       - to start svn server once off.

***** How to setup iptables - NOT Needed here
http://articles.slicehost.com/2007/9/5/introduction-to-svnserve

No comments: