<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE artikkel PUBLIC "-//infoweb.ntnu.no//DTD Infoweb 1.0//NO"
"http://infoweb.ntnu.no/infoweb.dtd">

<artikkel spraak="en">
<tittel>CVS - the command line tool</tittel>
<forfatter>janpetar</forfatter>
<sammendrag>Short intro to the commmand line tool for CVS</sammendrag>

<hoveddel>

<os2>Getting ready for using CVS</os2>

<avsnitt>
  CVS can be used on NTNU's login servers, linuxlogin.stud.ntnu.no (or just login.stud.ntnu.no). The first thing that must be done
  when you wish to use CVS is to create a so-called <uthev>CVS root</uthev>. It is under this that all
  data will be stored. Let's say you wish to create a CVS root in a folder called
  <kommando>cvs</kommando>, located in your home area. You start by creating the folder:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~$ mkdir cvs
  </konsoll>
</avsnitt>

<avsnitt>
  You can then create the CVS root in this folder with the following command:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~$ cvs -d ~grip/cvs init
  </konsoll>
</avsnitt>

<avsnitt>
  The argument <kommando>-d ~grip/cvs</kommando> indicates where the CVS root is located (substitute   <kommando>grip</kommando>
  with your own user name). If you wish to not have to write this argument in all commands before the project is created, you may
  enter:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~$ export CVSROOT=~grip/cvs
  </konsoll>
</avsnitt>

<avsnitt>
  This will create an environment varable, <kommando>CVSROOT</kommando>, with the path of the CVS root
  as it's value.
</avsnitt>

<os2>Creating a project</os2>

<avsnitt>
  Everything is now ready to start creating projects for storing in CVS. Let's say there is a folder
  called <kommando>java</kommando>, with a programming project in, for which you wish to use CVS. You
  then enter the <kommando>java</kommando> folder and create the CVS project with all the files and 
  subfolders:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~$ cd java
    gaupe:~/java$ cvs import -m "A little java project" javaproject example start
    N javaproject/a_file.java
    N javaproject/testfile.java

    No conflicts created by this import
  </konsoll>
</avsnitt>

<avsnitt>
  You should get a response similar to the one above, which indicates that the listed files have been
  added in a so-called CVS repository for the project, which is a place under the CVS root where the
  project data is stored. The name of the repository is, in the example above, specified to be
  <kommando>javaproject</kommando>. If you wish to, you may now delete the entire
  <kommando>java</kommando> folder, as everything is stored in CVS.
</avsnitt>

<os2>Working with the project</os2>

<avsnitt>
  This is all good, but we wish to work with the files, and make changes, create new and delete old
  files. What you need to do is to go to a folder where you wish to place a working copy of the files, 
  and enter:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~$ cvs checkout javaproject
    cvs checkout: Updating javaproject
    U javaproject/a_file.java
    U javaproject/testfile.java
  </konsoll>
</avsnitt>

<avsnitt>
  A copy of the java project will now appear in the folder <kommando>javaproject</kommando>. This is a
  local copy, with which you may do whatever you want. You may change the files, delete files, create new
  files etc. The nice thing is that this does not change what is in the CVS repository at all. When you
  feel that you have done something useful, like having made some changes to
  <kommando>testfile.java</kommando>, you may <uthev>update the repository</uthev> with the changes, by
  entering:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~/javaproject$ cvs commit -m "Made a new print method" testfile.java
    Checking in testfile.java;
    /home/homej/gr/grip/cvs/javaproject/testfile.java,v  --  testfile.java
    new revision: 1.2; previous revision: 1.1
    done
  </konsoll>
</avsnitt>

<avsnitt>
  The file has now been stored in the repository with the comment in quotation marks, but has been given
  a new version number. Thereby, the old version is not overwritten, but can be retrieved again if you
  decide to revert back to it.

  To <uthev>compare a local file with the one in the
  repository</uthev>, you may enter:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~/javaproject$ cvs status a_file.java
    ===================================================================
    File: a_file.java       Status: Locally Modified
    
       Working revision:    1.1.1.1 Tue Jan 28 19:30:38 2003
       Repository revision: 1.1.1.1 /home/homej/gr/grip/cvs/javaproject/a_file.java,v
       Sticky Tag:          (none)
       Sticky Date:         (none)
       Sticky Options:      (none)
  </konsoll>
</avsnitt>

<avsnitt>
  You can then see if the version you are working with is up to date, or if it is older or has been
  changed compared to the one in the repository. In the status field above, you can see that this file
  has been changed since it was last synchronized with the repository. If you wish to <uthev>update your
  local copy</uthev>, you may enter:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~/javaproject$ cvs update a_file.java
    M a_file.java
  </konsoll>
</avsnitt>

<avsnitt>
  To <uthev>add a new file</uthev> that you have created, you have to enter two commands:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~/javaproject$ cvs add another_file.java
    cvs add: scheduling file `another_file.java' for addition
    cvs add: use 'cvs commit' to add this file permanently
    
    gaupe:~/javaproject$ cvs commit -m "Another file" another_file.java
    RCS file: /home/homej/gr/grip/cvs/javaproject/another_file.java,v
    done
    Checking in another_file.java;
    /home/homej/gr/grip/cvs/javaproject/another_file.java,v  --  another_file.java
    initial revision: 1.1
    done
  </konsoll>
</avsnitt>

<avsnitt>
  You may <uthev>remove a file</uthev> from the repository by entering:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~/javaproject$ cvs remove another_file.java
    cvs remove: scheduling `another_file.java' for removal
    cvs remove: use 'cvs commit' to remove this file permanently
    
    gaupe:~/javaprosjekt$ cvs commit -m "Removed a useless file" another_file.java
    Removing another_file.java;
    /home/homej/gr/grip/cvs/javaproject/another_file.java,v  --  another_file.java
    new revision: delete; previous revision: 1.1
    done
  </konsoll>
</avsnitt>

<os2>Reviewing the log of a file</os2>

<avsnitt>
  For a detailed overview over the history of a file, you may enter:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~/javaproject$ cvs log testfile.java

    RCS file: /home/homej/gr/grip/cvs/javaproject/testfile.java,v
    Working file: testfile.java
    head: 1.2
    branch:
    locks: strict
    access list:
    symbolic names:
            start: 1.1.1.1
	         eksempel: 1.1.1
    keyword substitution: kv
    total revisions: 3;     selected revisions: 3
    description:
    ----------------------------
    revision 1.2
    date: 2003/01/28 19:45:54;  author: grip;  state: Exp;  lines: +1 -1
    Made a new print method
    ----------------------------
    revision 1.1
    date: 2003/01/28 19:45:20;  author: grip;  state: Exp;
    branches:  1.1.1;
    Initial revision
    ----------------------------
    revision 1.1.1.1
    date: 2003/01/28 19:45:20;  author: grip;  state: Exp;  lines: +0 -0
    A little java project
    =============================================================================
  </konsoll>
</avsnitt>

<os2>CVS with several users</os2>

<avsnitt>
  If you use CVS in a project with several users, each user works on his or her own, local copy of the
  project, but up against the same CVS repository. Therefore, everyone involved needs the correct access
  to it. If you have a common area that can be used for this purpose, it is natural to create the CVS
  root here. If you, for instance, have been given the area
  <kommando>/home/prosjekt/sif8005/sif8005_204</kommando>, you should exchange the commands in the
  section <kursiv>Getting ready for CVS</kursiv> with the following:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:~$ cd /home/prosjekt/sif8005/sif8005_204     
    gaupe:/home/prosjekt/sif8005/sif8005_204$ mkdir cvs     
    gaupe:/home/prosjekt/sif8005/sif8005_204$ export CVSROOT=/home/prosjekt/sif8005/sif8005_204/cvs
    gaupe:/home/prosjekt/sif8005/sif8005_204$ cvs init
  </konsoll>
</avsnitt>

<avsnitt>
  Note that, by setting the environment variable first, you may skip the extra argument to <kommando>cvs
  init</kommando>. Also note that everyone involved needs to set this environment variable before they
  check out their local copy (see the section <kursiv>Working with the project</kursiv>).
</avsnitt>

<avsnitt>
  You must also make sure to set the permissions on the CVS repository such that everyone involved has
  access. If there is a particular group created for the project, for instance
  <kommando>prog204</kommando>, you must make sure that the repository is owned by this
  group, and that the group has the right permissions. After the project has been created (again we
  assume it has the name <kommando>javaproject</kommando>), the following commands will to the trick:
</avsnitt>

<avsnitt>
  <konsoll>
    gaupe:/home/prosjekt/sif8005/sif8005_204$ cd cvs
    gaupe:/home/prosjekt/sif8005/sif8005_204/cvs$ chgrp -R prog204 javaproject 
    gaupe:/home/prosjekt/sif8005/sif8005_204/cvs$ chmod -R g+r javaproject 
    gaupe:/home/prosjekt/sif8005/sif8005_204/cvs$ find javaproject -depth -type d -exec chmod g+wx {} \;
  </konsoll>
</avsnitt>

<avsnitt>
  What happens here is that the files are made to belong to the group <kommando>prog204</kommando>.
  Then the group is given read permission on all the files and subfolders in the repository, and finally the
  group is given write permission on all the folders in the repository. When it comes to the write permission, it is
  the folders that are essential, not the files themselves.
</avsnitt>

<os2>Other functionality</os2>

<avsnitt>
  The functionality of CVS goes far beyond what is presented here. For help on the usage of a certain
  command, type <kommando>cvs -H command</kommando>, where command is the command you wish to get help
  on. You can also get an introduction and help by typing <kommando>man cvs</kommando>
</avsnitt>
</hoveddel>
</artikkel>