Versionshanteringssystem
Föregående
Nästa

Versionshanteringssystem

Versionshantering är konsten att hantera ändringar i information. Det har länge varit ett viktigt verktyg för programerare som vanligtvis använder sin tid till att göra små ändringar i program och sedan ångra dessa ändringar dagen efter. Men versionshanteringssystem är användbara långt utanför mjukvaruutvecklingsvärlden. Överallt där människor använder datorer till att hantera information som ändras ofta finns det utrymme för versionshantering.

Subversion

Subversion är ett versionshanteringssystem som är öppen källkod. Med Subversion kan du spela in hur källkodsfiler och dokumentation ändras. Det hanterar filer och kataloger ändras över tid. Ett träd av filer placeras i ett centralt förråd. Förrådet fungerar ungefär som en vanlig filserver, med skillnaden att det kommer ihåg alla ändringar som någonsin gjorts i filerna eller katalogerna.

Installation

För att komma åt ett Subversion-förråd över HTTP-protokollet måste du installera och konfigurera en webbserver. Apache2 fungerar väl med Subversion. Läs HTTP-underavdelningen i Apache2-avdelningen för att installera och konfigurera Apache2. För att komma åt Subversionförrådet med HTTPS-protokollet måste du installera och konfigurera ett digitalt certifikat till din webbserver. Läs HTTPS-underavdelningen av Apache2-avdelningen för att installera och konfigurera det digitala certifikatet.

För att installera Subversion, kör följande kommando från en terminalprompt:

sudo apt-get install subversion libapache2-svn

Serverkonfiguration

Det här steget förutsätter att du har installerat ovan nämnda paket på ditt system. Den här avdelningen förklarar hur du skapar ett Subversionförråd och hur du kommer åt projektet.

Skapa Subversionförrådet

Subversionförrådet kan du skapa med följande kommando, som du skriver i en terminalprompt:

svnadmin create /sökväg/till/projektkatalogen

Åtkomstmetoder

Subversionförråd går att komma åt ("check out") på många sätt - på den lokala hårddisken eller över olika nätverksprotokoll. Förrådets plats är dock alltid en URL. Den här tabellen beskriver hur olika URL-scheman går att använda med de tillgängliga åtkomstmetoderna.

Tabell 4.1. Åtkomstmetoder

Schema

Åtkomstmetod

file://

direkt förrådtillgång (på den lokala hårddisken)

http://

Kom åt det via WebDAV-protokollet från en Subversion-medveten Apache2-webbserver

https://

Som http://, men med SSL-kryptering

svn://

Kom åt det via ett specialprotokoll från en svnserve-server

svn+ssh://

Som svn://, men genom en SSH-tunnel

I den här avdelningen ska vi konfigurera Subversion så att alla dessa åtkomstmetoder fungerar. Här kommer vi bara att gå igenom det grundläggande. För mer avancerad användning, läs svn-boken.

Direkt förrådsåtkomst (file://)

Det här är det enklaste sättet att komma åt Subversion. Det kräver ingen att någon Subversionserver körs. Den här metoden används för att komma åt Subverson från samma dator. Syntaxet på kommandot, som du skriver i en terminalprompt, är som följer:

svn co file:///sökväg/till/projektkatalogen

eller

svn co file://localhost/sökväg/till/projektkatalogen

Notera

Om du inte skriver något värddatornamn är det tre snedstreck (///) - två för protokollet (file, i det här fallet) och ett för början av sökvägen. Om du skriver ett värddatornamn måste du använda två snedstreck (//).

Förrådsrättigheterna beror på filsystemsrättigheterna. Om användaren har läs- och skrivrättigheter kan han komma åt filer från och lägga upp filer till förrådet.

Tillgång via WebDAV-protokollet (http://)

För att komma åt Subversionförråd via WebDAV-protokollet måste du konfigurera din Apache2-webbserver. Du måste lägga till följande rader till filen /etc/apache2/apache2.conf:

 <Location /svn>
  DAV svn
  SVNPath /path/to/repos
  AuthType Basic
  AuthName "Your repository name"
  AuthUserFile /etc/subversion/passwd
  <LimitExcept GET PROPFIND OPTIONS REPORT>
  Require valid-user
  </LimitExcept>
  </Location> 

När du har gjort det måste du skapa filen /etc/subversion/passwd. Den här filen innehåller användarautentiseringsdetaljer. För att lägga till en post, dvs lägga till en användare, kan du köra följande kommando i en terminalprompt:

htpasswd2 /etc/subversion/passwd användarnamn

Det här kommandot kommer be dig skriva in ett lösenord. När du skrivit in lösenordet läggs användaren till. För att komma åt förrådet kör du nu följande kommando:

              
                
                  svn co http://servernamn/svn
                
              
            

Varning

Lösenordet överförs i klartext. Om du är rädd för att någon ska komma över ditt lösenord bör du använda SSL-kryptering. För fler detaljer, läs nästa avdelning.

Tillgång via WebDAV-protokolet via SSL-kryptering (https://)

Att komma åt ett Subversionförråd via WebDAV-protokollet med SSL-kryptering (https://) är likandant som att komma åt http:// med den enda skillnaden att du måste installera och konfigurera det digitala certifikatet på din Apache2-server.

You can install a digital certificate issued by a signing authority like Verisign. Alternatively, you can install your own self-signed certificate.

This step assumes you have installed and configured a digital certificate in your Apache 2 web server. Now, to access the Subversion repository, please refer to the above section! The access methods are exactly the same, except the protocol. You must use https:// to access the Subversion repository.

Access via custom protocol (svn://)

Once the Subversion repository is created, you can configure the access control. You can edit the /path/to/repos/project/conf/svnserve.conf file to configure the access control. For example, to set up authentication, you can uncomment the following lines in the configuration file:

# [general]
# password-db = passwd

After uncommenting the above lines, you can maintain the user list in the passwd file. So, edit the file passwd in the same directory and add the new user. The syntax is as follows:

username = password

For more details, please refer to the file.

Now, to access Subversion via the svn:// custom protocol, either from the same machine or a different machine, you can run svnserver using svnserve command. The syntax is as follows:

$ svnserve -d --foreground -r /path/to/repos
# -d -- daemon mode
# --foreground -- run in foreground (useful for debugging)
# -r -- root of directory to serve

For more usage details, please refer to:
$ svnserve --help

Once you run this command, Subversion starts listening on default port (3690). To access the project repository, you must run the following command from a terminal prompt:

svn co svn://hostname/project project --username user_name

Based on server configuration, it prompts for password. Once you are authenticated, it checks out the code from Subversion repository. To synchronize the project repository with the local copy, you can run the update sub-command. The syntax of the command, entered at a terminal prompt, is as follows:

cd project_dir ; svn update

For more details about using each Subversion sub-command, you can refer to the manual. For example, to learn more about the co (checkout) command, please run the following command from a terminal prompt:

              
                
                  svn co help
                
              
            
Access via custom protocol with SSL encryption (svn+ssh://)

The configuration and server process is same as in the svn:// method. For details, please refer to the above section. This step assumes you have followed the above step and started the Subversion server using svnserve command.

It is also assumed that the ssh server is running on that machine and that it is allowing incoming connections. To confirm, please try to login to that machine using ssh. If you can login, everything is perfect. If you cannot login, please address it before continuing further.

The svn+ssh:// protocol is used to access the Subversion repository using SSL encryption. The data transfer is encrypted using this method. To access the project repository (for example with a checkout), you must use the following command syntax:

svn co svn+ssh://hostname/var/svn/repos/project

Notera

You must use the full path (/path/to/repos/project) to access the Subversion repository using this access method.

Based on server configuration, it prompts for password. You must enter the password you use to login via ssh. Once you are authenticated, it checks out the code from the Subversion repository.

CVS Server

CVS is a version control system. You can use it to record the history of source files.

Installation

At a terminal prompt, enter the following command to install cvs:

sudo apt-get install cvs

After you install cvs, you should install xinetd to start/stop the cvs server. At the prompt, enter the following command to install xinetd:

sudo apt-get install xinetd

Konfiguration

Once you install cvs, the repository will be automatically initialized. By default, the repository resides under the /var/lib/cvs directory. You can change this path by running following command:

cvs -d /your/new/cvs/repo init

Once the initial repository is set up, you can configure xinetd to start the CVS server. You can copy the following lines to the /etc/xinetd/cvspserver file.

service cvspserver
{
     port = 2401
     socket_type = stream
     protocol = tcp
     user = root
     wait = no
     type = UNLISTED
     server = /usr/bin/cvs
     server_args = -f --allow-root /var/lib/cvs pserver
     disable = no
}

Notera

Be sure to edit the repository if you have changed the default repository (/var/lib/cvs) directory.

Once you have configured xinetd you can start the cvs server by running following command:

sudo /etc/init.d/xinetd start

You can confirm that the CVS server is running by issuing the following command:

sudo netstat -tap | grep cvs

When you run this command, you should see the following line or something similar:

tcp        0      0 *:cvspserver            *:* LISTEN 

From here you can continue to add users, add new projects, and manage the CVS server.

Varning

CVS allows the user to add users independently of the underlying OS installation. Probably the easiest way is to use the Linux Users for CVS, although it has potential security issues. Please refer to the CVS manual for details.

Add Projects

This section explains how to add new project to the CVS repository. Create the directory and add necessary document and source files to the directory. Now, run the following command to add this project to CVS repository:

cd your/project
cvs import -d :pserver:username@hostname.com:/var/lib/cvs -m "Importing my project to CVS repository" . new_project start

Tips

You can use the CVSROOT environment variable to store the CVS root directory. Once you export the CVSROOT environment variable, you can avoid using -d option to above cvs command.

The string new_project is a vendor tag, and start is a release tag. They serve no purpose in this context, but since CVS requires them, they must be present.

Varning

When you add a new project, the CVS user you use must have write access to the CVS repository (/var/lib/cvs). By default, the src group has write access to the CVS repository. So, you can add the user to this group, and he can then add and manage projects in the CVS repository.

Referenser

Subversion Home Page

Subversion Book

CVS Manual

Föregående
Nästa
Hem