[Ilugc] write lock in CVS

  • From: nallu.ignacius@xxxxxxxxx (nallu ignacius)
  • Date: Thu Jun 23 00:24:21 2005

Dear friends,

In my office also people were saying non-sense stuffs[afraid of conflicts 
so, no need to move from VSS to CVS].
Don't worry we can achieve reserved edit feature in cvs[cvs is client side - 
All users must follow these simple rules inorder to implement pure reserved 
edit].Usage of locks is not needed at all. Just the edit notification "cvs 
edit" is enough to implement reserved edit.
Server:
Host either cvs or cvsnt server. We have a cvs server [cvs 1.11.18].

Command-line clients:
1.Just install cvsnt for Windows[installer]/linux[RPM] and start working.
2. All users must have a .cvsrc file in their HOME directory containing text 
"edit -c"
3. Always do "cvs edit -c <filename>" immediately do "cvs update <filename>" 
[Replicating VSS behaviour "checkout"]. After this edit and commit your file 
as "cvs commit <filename>".


Windows clients Wincvs:
1. All users must have the "checkout read only" option in their general 
options tab enabled .
2. All users must have a .cvsrc file in their HOME directory containing text 
"edit -c"
3. All users must have a copy of updateedit.py in their 
WINCVSINSTALLDIR\macros folder
4. FOR RESERVED EDDITING A FILE:All users must use updateedit.py to 
"Reserved edit" a file. copy the below given content as updateedit.py and 
save it in WINCVSINSTALLDIR\macros folder.Assign a shortcut for the 
macro.All users must use that short cut to automatically 
checkeditors+update+edit the file.
5.No <http://5.No> one should remove the read-only option for files in 
sandbox[checkedout local copy] and do nasty things.[VSS is absolutely 
different from CVS]


<++++++++++Start of Content of updateedit.py+++++++++>
from cvsgui.ColorConsole import *
from cvsgui.CvsEntry import *
from cvsgui.Macro import *
from os import *

"""
CvsGui Macro "Update and Edit"

Binds the following tree cvs commands for the selected files together:
- Editors of selection
- Update selection
- Edit selection
The second an third command are only performed if there is no output by the 
first command.
"""

class UpdateEdit(Macro):
def __init__(self):
Macro.__init__(self,'Update and Edit',MACRO_SELECTION,0,'Q-SOFT')

def OnCmdUI(self,cmdui):
self.sel=App.GetSelection()
enabled=0
for entry in self.sel:
enabled=enabled or entry.IsFile()
cmdui.Enable(enabled)

def Run(self):
console=ColorConsole()
try:
#Collect files
olddir=getcwd()
files=[]
if (len(self.sel)<>1)or(self.sel[0].GetFullName()<>olddir):
for entry in self.sel:
if entry.IsFile():
if entry.GetPath()==olddir:
files.append(entry.GetName())
else:
relpath=entry.GetPath()
relpath=relpath[len(olddir)+1:]+os.sep
files.append(relpath+entry.GetName())
#
# search for editors
#
# filenames='Affected files: '
# for filename in files:
# filenames=filenames+'"'+filename+'" '
# console<<kNormal<<filenames<<'\n'
console<<kNormal<<'Looking for editors:\n'
#prepare and show command
command='cvs editors '
for filename in files:
command=command+'"'+filename+'" '
console<<command<<'(in Directory "' << olddir << '")\n'<<kRed
#run command and ahow results (errors in red)
cvs=Cvs(1,0)
code,out,err=cvs.Run('editors',*files)
if code==0:
if out<>None:
console<<out
if err<>None:
console<<err<<'\n'
else:
console<<'Error (Code='<<code<<'): '<<err<<'\n'
if (code<>0)or((out<>None)and(out<>''))or((err<>None)and(err<>'')):
console<<kRed<<kBold<<kItalic<<'\nError: The selected has editors. - Update 
and edit cancelled.\n\n'
else:
#
# run update
#
console<<kNormal<<'Updating selected:\n'
#prepare and show command
command='cvs update '
for filename in files:
command=command+'"'+filename+'" '
console<<command<<'(in Directory "' << olddir << '")\n'
#run command and ahow results (errors in red)
cvs=Cvs(1,0)
code,out,err=cvs.Run('update',*files)
if code==0:
if out<>None:
console<<kBlue<<out
if err<>None:
console<<kRed<<err<<'\n'
else:
console<<kRed<<'Error (Code='<<code<<'): '<<err<<'\n'
#
# set to edit
#
console<<kNormal<<'Editing selected:\n'
#prepare and show command
command='cvs edit '
for filename in files:
command=command+'"'+filename+'" '
console<<command<<'(in Directory "' << olddir << '")\n'
#run command and ahow results (errors in red)
cvs=Cvs(1,0)
code,out,err=cvs.Run('edit',*files)
if code==0:
if out<>None:
console<<kBlue<<out
if err<>None:
console<<kRed<<err<<'\n'
else:
console<<kRed<<'Error (Code='<<code<<'): '<<err<<'\n'
finally:
console<<kNormal<<'Done\n\n'
del console

UpdateEdit()
<++++++++++End of Content of updateedit.py+++++++++>

Linux clients[gcvs]:
1. compile and install cvsnt for linux.
2.compile and install gcvs.
3.Map the cvsnt binary[cvs] in the option for cvs command.
4.All users must have the "checkout read only" option in their general 
options tab enabled .
5.All users must have a .cvsrc file in their HOME directory containing text 
"edit -c"
6.FOR RESERVED EDDITING A FILE: There is a TCL script called "Edit safely" 
in macros menu which does "cvs editors+update+edit" [use this option alone 
to reserved edit]
7.FOR COMMITING: After this just edit the content of your file and commit.
8.No <http://8.No> one should remove the read-only option for files in 
sandbox[checkedout local copy] and do nasty things.[VSS is absolutely 
different from CVS]

Eclipse IDE's cvs component:
1.Eclipse IDE comes with inbuilt cvs support- A very good frontent 
indeed[Annotations,differences,recover deleted files,etc., are very good]. 
2.Configure your eclipse: Windows-->preferences
In team-->CVS-->Wath/Edit : Check "Configure rojects to use Watch/Editon 
checkout"
: "Before a CVS edit notification is sent to the server" select the option 
"Always prompt"
3.The only drawback is that if a guy is already editing a file, and if you 
right click the file and click team-->edit Eclipse prompts that the guy is 
editing it and will ask you whether to send cvs edit notification or not. 
Just click
cancel and try later.
4.Similarly you have to manually update the file before editing.

In our office we are using wincvs in windows clients and Eclipse in linux as 
well as windows.
visit http://geocities.com/ignacius_n/ ;
In the files section there are documents prepared by me[will be really 
helpful]. 
http://geocities.com/ignacius_n/files/index.html
1.It <http://1.It> contains the tool vss2cvs a perl utility to move VSS 
repository to CVS repository. 
2.Documents for configuring cvs server in normal mode and secured mode.
3.Documents for configuring CVSROOT - cvs administration files through gcvs.
4.Setup and work in gcvs with good screenshots.

N.Nallu Ignacius

Other related posts: