Tải bản đầy đủ - 0 (trang)
Chapter 3. Setting Up Version Control Using CVS

Chapter 3. Setting Up Version Control Using CVS

Tải bản đầy đủ - 0trang

moderndevelopmentpracticesthanCVS.



Chapter3.SettingUpVersionControl

UsingCVS

AnIntroductiontoCVS

SettingUpaCVSRepository

CreatingaNewProjectinCVS

CheckingOutaProject

WorkingwithYourFiles—UpdatingandCommitting

ResolvingaLockedRepository

WorkingwithKeywordSubstitution

WorkingwithBinaryFiles

TagsinCVS

CreatingBranchesinCVS

MergingChangesfromaBranch

ViewingChangeHistory

RevertingChanges

UsingCVSinWindows



3.1.AnIntroductiontoCVS

CVSisavenerableopensourceversioncontrolsystemfirst

releasedinthe1980s,onethathasalonghistoryintheopen

sourcecommunity.Indeed,agreatnumberofopensource

projectsarestillhostedunderCVS.CVSusesaclient-server

architecture,withasourcecoderepositoryresidingonacentral

server.Usersconnecttotheservertodownload(or"checkout,"

touseCVSterminology)acopyoftheprojectsourcecode,

modifyit,andthensubmit(or"checkin")theirchangesbackto

therepository.Severaluserscanworksimultaneouslyonthe



samefile.CVSwillattempttomergethemodificationsofusers

astheycheckintheirchanges.Ifitcannotdosoforsome

reason,theuserhastoresolvetheconflictmanually.Andwhen

thetimecomestomakearelease,userscan"tag"aversionto

beabletoretrieveitreliablylateron.

Forsomeyearsnow,CVShasbeenshowingitsage,andithas

anumberofdeep-seatedarchitecturalflawsandmissing

featuresthatmakeitpoorlyadaptedtoJavadevelopment

projectsandthemoremodernagiledevelopmentpracticesin

general.Forexample,itisverydifficulttorenameormove

directories,whichmakesrefactoringcumbersomeanddifficult.

DirectorystructuresinCVSareveryrigid—onceadded,itis

veryhardtogetridofadirectoryintherepository.Inaddition,

CVSwasdesignedatatimewhenmostapplicationsconsisted

entirelyoftextfiles,sosupportforotherformats,suchas

binaryfiles,islimited.Theimportantnotionofatomiccommits

(seeSection4.1.1"inSection4.1),presentinvirtuallyallother

modernversioncontrolsystems,istotallyabsentfromCVS.

ItshouldbenotedthatSubversion(seeChapter4)was

designedfromthegrounduptoovercomemanyofthe

limitationsofCVS,somethingthatithasdonerather

successfully.Subversionisnowstable,mature,andtechnically

superiortoCVS.Ifyouaregivenachoiceforanewproject,it

wouldbewisetoconsiderSubversionseriously.

Nevertheless,CVSisstillwidelyusedinmanyorganizations,on

websites,andinopensourceprojects,anditisarguablystilla

toolwithwhichyoushouldbefamiliar.Thus,ratherthanbeinga

detailedreference,thischapterisdesignedmorealongthelines

ofasurvivalguideforJavadeveloperswhoneedtouseCVS.



Part2:VersionControlTools

"Yououghttoseethatbirdfromhere,"saidRabbit.

"Unlessit'safish.""Itisn'tafish,it'sabird,"said

Piglet."Soitis,"saidRabbit."Isitastarlingora

blackbird?"saidPooh."That'sthewholequestion,"said

Rabbit."Isitablackbirdorastarling?"

—"KangaandBabyRooCometotheForest,"Winniethe

Pooh,A.A.Milne

Inallthings,itisusefultoknowexactlywhatyouare

dealingwithatanypointintime.Insoftwaredevelopment,

wheresourcecodeischangingperpetually,thisis

particularlyimportant.Thisiswhyversioncontrolsystems

playsuchacrucialroleinmodernsoftwaredevelopment

environments.Theadvantagesofusingsuchasystemare

wellknown.Awell-designedversioncontrolsolution

facilitatesteamworkbyallowingmanydeveloperstowork

onthesameproject(oreventhesamefiles)simultaneously

withoutsteppingoneachother'stoes.Itprovidesacentral

placetostoreyourapplicationsourcecodeaswellasa

reliablehistoryofthechangesthathavebeenmadeover

thelifeoftheproject.Italsoallowsdeveloperstoreturnto

apreviousstableversionofthesourcecodeifneedbe.And

itallowsdeveloperstoidentify(or"tag")aparticular

versionofthesourcecode,suchasforaparticularrelease.

Inmoderndevelopmentenvironments,versioncontrol

systemsareanessentialbuildingbrickformore

sophisticatedtechniquessuchasContinuousIntegration

(seeChaptersChapter5,Chapter6,andChapter7).

InJavaprojects,thetwomostprominentopensource

versioncontrolsystemsare,withoutadoubt,CVSand

Subversion.ThevenerableopensourcetoolCVSiswidely

usedinmanyorganizations.Subversion,itsnatural

successor,israpidlygaininggroundinnewJavaprojects

becauseofitsfeatures,whichareaguablybetteradaptedto



moderndevelopmentpracticesthanCVS.



Chapter3.SettingUpVersionControl

UsingCVS

AnIntroductiontoCVS

SettingUpaCVSRepository

CreatingaNewProjectinCVS

CheckingOutaProject

WorkingwithYourFiles—UpdatingandCommitting

ResolvingaLockedRepository

WorkingwithKeywordSubstitution

WorkingwithBinaryFiles

TagsinCVS

CreatingBranchesinCVS

MergingChangesfromaBranch

ViewingChangeHistory

RevertingChanges

UsingCVSinWindows



3.1.AnIntroductiontoCVS

CVSisavenerableopensourceversioncontrolsystemfirst

releasedinthe1980s,onethathasalonghistoryintheopen

sourcecommunity.Indeed,agreatnumberofopensource

projectsarestillhostedunderCVS.CVSusesaclient-server

architecture,withasourcecoderepositoryresidingonacentral

server.Usersconnecttotheservertodownload(or"checkout,"

touseCVSterminology)acopyoftheprojectsourcecode,

modifyit,andthensubmit(or"checkin")theirchangesbackto

therepository.Severaluserscanworksimultaneouslyonthe



samefile.CVSwillattempttomergethemodificationsofusers

astheycheckintheirchanges.Ifitcannotdosoforsome

reason,theuserhastoresolvetheconflictmanually.Andwhen

thetimecomestomakearelease,userscan"tag"aversionto

beabletoretrieveitreliablylateron.

Forsomeyearsnow,CVShasbeenshowingitsage,andithas

anumberofdeep-seatedarchitecturalflawsandmissing

featuresthatmakeitpoorlyadaptedtoJavadevelopment

projectsandthemoremodernagiledevelopmentpracticesin

general.Forexample,itisverydifficulttorenameormove

directories,whichmakesrefactoringcumbersomeanddifficult.

DirectorystructuresinCVSareveryrigid—onceadded,itis

veryhardtogetridofadirectoryintherepository.Inaddition,

CVSwasdesignedatatimewhenmostapplicationsconsisted

entirelyoftextfiles,sosupportforotherformats,suchas

binaryfiles,islimited.Theimportantnotionofatomiccommits

(seeSection4.1.1"inSection4.1),presentinvirtuallyallother

modernversioncontrolsystems,istotallyabsentfromCVS.

ItshouldbenotedthatSubversion(seeChapter4)was

designedfromthegrounduptoovercomemanyofthe

limitationsofCVS,somethingthatithasdonerather

successfully.Subversionisnowstable,mature,andtechnically

superiortoCVS.Ifyouaregivenachoiceforanewproject,it

wouldbewisetoconsiderSubversionseriously.

Nevertheless,CVSisstillwidelyusedinmanyorganizations,on

websites,andinopensourceprojects,anditisarguablystilla

toolwithwhichyoushouldbefamiliar.Thus,ratherthanbeinga

detailedreference,thischapterisdesignedmorealongthelines

ofasurvivalguideforJavadeveloperswhoneedtouseCVS.



3.2.SettingUpaCVSRepository

CVSisessentiallyaUnixapplication,althoughthereisan

independentforkforWindowscalledCVSNT.Youcanrunthe

CVSclientvirtuallyanywhere,buttheCVSserverismost

commonlyseeninaUnixenvironment.Thefirststepisto

createadirectoryinwhichtheCVSrepositorywillbestored.In

thisexample,wewillplaceitinthe/usr/local/cvsdirectory,

althoughitcangoanywhereyoulike.Forsecurityreasons,itis

alsoagoodideatocreateadedicatedgroupforCVSusers(say,

"cvs"),andtomakeournewdirectorybelongtothisgroup.You

generallyneedtosetupaUnixuseraccountonthismachine

foreachdeveloperthatwillbeusingtherepository.Tobeable

tocheckoutsourcecodefromthisrepository,usersneedread

accessonthesefiles.Tobeabletocommitchanges,usersneed

writeaccess.

TosetupanewCVSrepository,youneedtorunthecvsinit

command.ACVSrepositoryisessentiallystoredasacollection

offiles.Thecvsinitcommandsetsuptheappropriatedirectory

structureandadministrativefiles,whicharestoredina

directorycalledCVSROOT,asshownhere:



#cvs-d/usr/local/cvsinit

#ls/usr/local/cvs/

CVSROOT

#ls/usr/local/cvs/CVSROOT/

checkoutlistcvswrappers,vnotifyposttag,vtaginf

checkoutlist,vEmptydirnotify,vpostwatchtaginf

commitinfohistorypostadminpostwatch,vval-ta

commitinfo,vloginfopostadmin,vpreproxyverify

configloginfo,vpostproxypreproxy,vverify

config,vmodulespostproxy,vrcsinfo

cvswrappersmodules,vposttagrcsinfo,v

ThesearetherawCVSdatafiles.Don'tmesswiththem

directly.



3.3.CreatingaNewProjectinCVS

Whenyoustartworkonanewproject,younaturallywillwant

toputitunderversioncontrolquickly.Importinganempty

directorystructureoraskeletonprojectcontainingonlytext

filesintoCVSisfairlyeasy.Youmayhavecreatedaskeleton

directorystructuremanuallyusingaMavenarchetype(see

Section2.11).

First,youneedtotellCVSwheretolookforyourrepositoryby

definingtheCVSROOTenvironmentvariable.Thisalsowillmake

thingseasierfortheotherCVScommands.Thisvariablepoints

tothedefaultCVSrepositorytobeusedinallCVScommands.

IfyourCVSrepositoryhasbeensetuponthelocalmachinein

/usr/local/cvs,forexample,youmightdosomethinglike

this:

$exportCVSROOT=/usr/local/cvs

Ifyouareaccessinganorganization-wideCVSserveracrossthe

network,youwillprobablyneedtoaccesstherepositoryusing

thepserverprotocol:



$exportCVSROOT=:pserver:john@cvs.mycompany.com:2401/usr/local

Wewilltalkaboutthepserverprotocolabitmorelaterinthis

chapter.

Ifthisrepositorydoesn'tsupportanonymousaccess(whichis

usuallythecasewithanenterpriserepository,forexample),

youwillneedtologinbeforeyoucangoanyfurther:

$cvslogin

Iftheserverauthorizesyoutoaccesstherepository,your

passwordwillbestoredlocallysothatyoudon'tneedtologin

eachtime.



Next,youimportthedirectorystructureusingthecvsimport

command.Theimportcommandtakesthefollowingform:

$cvsimport-m"Initialmessage"projectvendortagreleasetag

Theprojectfieldreferstothedirectorythatyouwanttostorein

CVS.

Youneedtoprovideatextmessagedescribingtheimport.You

caneitherdothisusingthe-moptionorletCVSpromptyoufor

amessagebyopeningthedefaultsystemtexteditor.

Youdon'thavetoworrytoomuchaboutwhatyouputinthe

vendortagandreleasetagfields,astheyareveryrarelyusedin

practice.

Let'slookatanexample.Supposethatourprojectisamodule

ofanonlinestorecalled"ShopCoreApi."Toimportthisproject

intoCVS,justrunthiscommandfromtheprojectrootdirectory,

asillustratedhere:



$cd~/projects/ShopCoreApi

$cvsimport-m"NewProject"ShopCoreApivendortagstart

NShopCoreApi/pom.xml

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/main

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/main/java

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/main/java/

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/main/java/

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/main/java/

NShopCoreApi/src/main/java/com/acme/shop/App.java

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/test

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/test/java

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/test/java/

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/test/java/

cvsimport:Importing/usr/local/cvs/ShopCoreApi/src/test/java/

NShopCoreApi/src/test/java/com/acme/shop/AppTest.java

Noconflictscreatedbythisimport



$ls/usr/local/cvs/

CVSROOTShopCoreApi

























Yousupplyanappropriatelogmessageusingthe-moption,

followedbythedirectorytobeimportedintoCVS.Thefollowing

twoparametersarethevendorname(forexample,your

company)andatagfortheinitialversion.Onceyouaredone,

therewillbeanewdirectoryintheCVSrepository,called

ShopCoreApi,containingyourprojectfilesinaCVSformat:

$ls/usr/local/cvs/

CVSROOTShopCoreApi

$ls/usr/local/cvs/ShopCoreApi/

pom.xml,vsrc

NowyourprojectissafelystoredawayinCVS.You'renotquite

readytouseit,though.ImportingaprojectintoCVSdoesnot

altertheoriginalprojectdirectory,andthisoriginaldirectory

cannotbeusedasaworkingcopy.Itisagoodideatobackup

youroriginaldirectoryforsafekeeping,andtoputit

somewhereoutoftheway.Thisistoavoidconfusionlateron—

youdon'twanttoaccidentallyupdatetheunversionedfiles

insteadoftheCVSones.OnaUnixsystem,forexample,you

coulddosomethinglikethis:

$tarcfzShopCoreApi-backup.tgzShopCoreApi/

$rm-RfShopCoreApi

Then,checkoutanewworkingcopyofyourproject.Wewill

lookathowtodothisinSection3.4.

Ifyouneedtoimportanexistingprojectintotherepository,

thingscangetabitmorecomplicated.Ifyouareworkingona

projectthatcontainsonlytextfiles,theproceduredescribed

abovewillworkfine.However,mostmodernsoftwareprojects



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 3. Setting Up Version Control Using CVS

Tải bản đầy đủ ngay(0 tr)

×