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

Chapter 4. Setting Up Version Control Using Subversion

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

SettingUpaWebDAV/DeltaVEnabledSubversionServer

SettingUpaSecureWebDAV/DeltaVServer

CustomizingSubversionwithHookScripts

InstallingSubversionAsaWindowsService

BackingUpandRestoringaSubversionRepository

UsingSubversioninEclipse

UsingSubversioninNetBeans

UsingSubversioninWindows

DefectTrackingandChangeControl

UsingSubversioninAnt

Conclusion



4.1.AnIntroductiontoSubversion

Whenitcomestoversioncontroltools,youwilloftenbestuck

withwhateverhappenstobeinuseinyourorganization,beit

anopensourcesolutionlikeCVS(seeChapter3)oroneofthe

manycommercialproducts.However,ifyouarefreetochoose

youropensourceversioncontrolsystem(orSCM),Subversion

isprobablyoneofthebestchoicesaround.

Subversion(pronounced"Sub-Version,"forthosewhoare

interestedinsuchdetails)isarelativelynewproductexplicitly

designedtoovercomethehistoricalshortfallsofCVS(see

Chapter3)andbecomethenewstandardinopensource

versioncontroltools.[25]Itisasuperblyengineeredpieceof

software,activelydevelopedandmaintainedbypaidstafffrom

CollabNet.AlthoughitdoeshaveaveryCVS-ishfeeltoit,its

underlyingarchitectureisquitedifferent,andithasanumberof

majorimprovementscomparedtoitsvenerablepredecessor.

[25]VersionControltoolssuchasSubversion,CVS,ClearCase,andsoforthare



oftenreferredtoasSCM(SoftwareConfigurationManagement)tools.Strictly

speaking,mostofthesetoolsareactuallyVersionControltools.Configuration

Managementisabroadertopic,includingdefectandchangecontroland

tracking,traceability,andsoon.



Inthissection,wewillrunthroughsomeofthekey

improvementsofSubversionwhencomparedtoCVS,and,in

doingso,gainsomeinsightintotheSubversionarchitecture

andphilosophy.



4.1.1.RevisionNumbersandAtomicUpdates

PerhapsoneofthemostprofoundchangesbetweenCVSand

Subversionisthewayeachsystemkeepstrackofchanges.

CVSkeepstrackofindividualfileversions.InCVS,whenyou

commitasetofchanges,eachmodifiedfileisupdated

separately.Tagscanbeusedtoidentifyasnapshotofthe

repositoryataparticularpointintime.Thisisillustratedin

Figure4-1.HerewehaveasetoffourJavaclasses.Whenthe

developeraddsthesefilestoCVS,eachwillbeattributeda

versionnumber(1.0).Nowourdevelopermakessome

modificationstoClassB,ClassCandClassD,andcommitsthese

changestoCVS.Eachofthesefileswillbeupdatedonthe

serverandassignedanewversionnumber:1.1.Ourdeveloper

maynowbesohappywiththisversionthatsheaddsatag

called(imaginatively)"Revision_2."Eachfilewillbe"tagged"

withthislabel,makingiteasiertofetchfromtherepositoryata

laterdateorfromanothermachine.

Figure4-1.FileversioningwithCVS



NowthatwecanvisualizehowCVSdoesthings,let'slookat

oneofthemajorweaknessesofthisarchitecture.Suppose

duringacommitthatsomeoneelsestartscommittingchanges

atthesametimeandaconflictoccurs.Inthiscase,someofthe

fileswillhavebeenupdated,butotherswillhavebeenrefused,

whichleavestherepositoryinanunstablestate.Ifyoukillthe

process,switchoffyourmachine,orastreetworkerdrills

throughyourInternetconnection,similarnastythingscan

occur.TheCVSrepositorycanbeleftinanunstablestateuntil

thestreetworkerinquestionrepairsthecableandletsyou

resolveanyconflictsandcompleteyourcommitoperation.

Subversion,bycontrast,keepstrackofrevisions.Arevision(or,

moreprecisely,arevisiontree)isarepresentationofthe

repositorystructureandcontentsatagivenpointintime.

RevisionsarethecornerstoneofapowerfulSubversionfeature:

atomicupdates.UpdatingtheSubversionrepositoryisabitlike

updatingarelationaldatabaseusingtransactions:whenyou



commitasetofchanges,youareguaranteedthateitherallof

yourchangeshavebeenintegratedintotherepository,ornone

atallhave.

Behindthescenes,Subversionstoressuccessive

representationsoftheentirerepositorystructureasawhole

(seeFigure4-2).Eachrevisionisidentifiedbyauniquenumber.

Whenchangesarecommitted,Subversionpreparesanew

repositorystructureincorporatingthechanges.If(andonlyif)

everychangeissuccessfullyintegrated,anewrepositorytree

willbecreatedwithanewrevisionnumber.So,inpractice,

eitherallofyourchangesareupdatedcorrectlyinthe

repository,andyougetanewrevisionnumberincorporating

thesechanges,ornoneare,andyougettofixtheproblemand

tryagain.

Figure4-2.Subversionrevisions



Anoffshootofthisstrategyisthatagivensetofchangescan

beviewedasadistinctbundle.Thisnotionisfrequentamong

commercialSCMsolutionsbutpainfullyabsentfromCVS.

InCVS,youcan(andshould)provideamessageindicatingthe

typeofmodificationthatyouhavemade.Youmightput,for

example,"Fixedbugnumber123"or"Addedsupportforthe

XYWZfiletype."Thisisallwellandgood,butyouhavenoeasy

wayofworkingoutexactlywhichfilesweremodifiedbythis

change,asthemessageisattachedtoeachindividualfile.

NotsoinSubversion.InSubversion,whenyoucommitasetof

changes,thesechangesarerecordedforposterityasasingle

transaction,including(hopefully)anappropriatecomment

describingwhattheywerefor.TheSubversionlogfunction

makesiteasytogetasummaryofthechangesmadeina

particularrevision,andwhytheyweremade,asshownhere:



$svnlog-vr5

--------------------------------------------------------------r5|taronga|2006-05-1913:42:04+1200(Fri,19May2006)|1

Changedpaths:

M/trunk/src/main/java/com/wakaleo/jdpt/javalamp/CIServerPlu

M/trunk/src/main/java/com/wakaleo/jdpt/javalamp/JavaLamp.ja

M/trunk/src/main/java/com/wakaleo/jdpt/javalamp/plugins/Con



Newfeatureadded:projectstatusnowappearsinthemenuforC

--------------------------------------------------------------























4.1.2.FastBranchingandTagging

CVSuserswillbefamiliarwiththepainoftaggingabigproject

underCVS.Becauseeverysinglefilemustbeindividually

tagged,theoperationcanbeverytime-consumingindeed.In

Subversion,tagginganewversionsimplyinvolvescopyingthe



currentrepositoryintoanotherdirectoryontheserver.

Subversiondoesnotactuallycopythewholedirectorycontent

butsimplymakesareferencetotheoriginalversionofthe

data.Thisisextremelyfast,andtakesverylittlediskspace.

Branchingisanotherimportantfunctioninanyversioncontrol

system(seeSection4.12).InSubversion,creatinganew

branchusesexactlythesametechnique:whenyoucreatea

newbranch,Subversionsimplycopiesthecurrentrepository

intoaspecialdirectory.



4.1.3.LightweightNetworkTransactions

Subversionprovidesexcellentnetworkperformance,evenwhen

dealingwithlargebinaryfiles.Subversionstoresalocalcopyof

theoriginalrepositoryfiles,andtransmitsonlythedifference

betweentheoriginalrepositoryrevisionandthelocalchanges.

So,inSubversion,thequantityofdatasentoverthenetworkis

proportionaltothesizeofyourmodifications,nottothesizeof

yourfiles.

Thislocalcopyalsoallowsmanyoperations,suchasstatus,diff,

andrevert,tobedonewithoutaccessingtheserveratall.



4.1.4.HandlingBinaryFiles

CVShandlesbinaryfilesverypoorly.Notonlyaretheysent

overthenetworkintheirtotalityateachupdate,buteach

versionisstoredontheserverinitscompleteform.Thisalone

isenoughtoputyouoffstoringbigWorddocumentsonaCVS

server!Subversion,bycontrast,wasdesignedfromtheground

uptotreatbinaryfileswiththesameefficiencyastext.Indeed,

inSubversion,allfilesareinternallystoredasbinaryfiles,and

onlythebinarydifferencesbetweenrevisionsareactually

storedontheserver.Subversiononlydistinguishesbetween

binaryandtextfilestoavoidtryingtomergebinaryfiles(see

Section4.17.2"inSection4.17).



Chapter4.SettingUpVersionControl

UsingSubversion

AnIntroductiontoSubversion

InstallingSubversion

SubversionRepositoryTypes

SettingUpaSubversionRepository

SettingUpaNewSubversionProject

CheckingOutYourWorkingCopy

ImportingExistingFilesintoSubversion

UnderstandingSubversionRepositoryURLs

WorkingwithYourFiles

SeeingWhereYou'reAt:TheStatusCommand

ResolvingConflicts

UsingTags,Branches,andMerges

RollingBacktoaPreviousRevision

UsingFileLockingwithBinaryFiles

BreakingandStealingLocks

MakingLockedFilesRead-Onlywiththesvn:needs-lock

Property

UsingProperties

ChangeHistoryinSubversion:LoggingandBlaming

SettingUpaSubversionServerwithsvnserve

SettingUpaSecuresvnserveServer



SettingUpaWebDAV/DeltaVEnabledSubversionServer

SettingUpaSecureWebDAV/DeltaVServer

CustomizingSubversionwithHookScripts

InstallingSubversionAsaWindowsService

BackingUpandRestoringaSubversionRepository

UsingSubversioninEclipse

UsingSubversioninNetBeans

UsingSubversioninWindows

DefectTrackingandChangeControl

UsingSubversioninAnt

Conclusion



4.1.AnIntroductiontoSubversion

Whenitcomestoversioncontroltools,youwilloftenbestuck

withwhateverhappenstobeinuseinyourorganization,beit

anopensourcesolutionlikeCVS(seeChapter3)oroneofthe

manycommercialproducts.However,ifyouarefreetochoose

youropensourceversioncontrolsystem(orSCM),Subversion

isprobablyoneofthebestchoicesaround.

Subversion(pronounced"Sub-Version,"forthosewhoare

interestedinsuchdetails)isarelativelynewproductexplicitly

designedtoovercomethehistoricalshortfallsofCVS(see

Chapter3)andbecomethenewstandardinopensource

versioncontroltools.[25]Itisasuperblyengineeredpieceof

software,activelydevelopedandmaintainedbypaidstafffrom

CollabNet.AlthoughitdoeshaveaveryCVS-ishfeeltoit,its

underlyingarchitectureisquitedifferent,andithasanumberof

majorimprovementscomparedtoitsvenerablepredecessor.

[25]VersionControltoolssuchasSubversion,CVS,ClearCase,andsoforthare



oftenreferredtoasSCM(SoftwareConfigurationManagement)tools.Strictly

speaking,mostofthesetoolsareactuallyVersionControltools.Configuration

Managementisabroadertopic,includingdefectandchangecontroland

tracking,traceability,andsoon.



Inthissection,wewillrunthroughsomeofthekey

improvementsofSubversionwhencomparedtoCVS,and,in

doingso,gainsomeinsightintotheSubversionarchitecture

andphilosophy.



4.1.1.RevisionNumbersandAtomicUpdates

PerhapsoneofthemostprofoundchangesbetweenCVSand

Subversionisthewayeachsystemkeepstrackofchanges.

CVSkeepstrackofindividualfileversions.InCVS,whenyou

commitasetofchanges,eachmodifiedfileisupdated

separately.Tagscanbeusedtoidentifyasnapshotofthe

repositoryataparticularpointintime.Thisisillustratedin

Figure4-1.HerewehaveasetoffourJavaclasses.Whenthe

developeraddsthesefilestoCVS,eachwillbeattributeda

versionnumber(1.0).Nowourdevelopermakessome

modificationstoClassB,ClassCandClassD,andcommitsthese

changestoCVS.Eachofthesefileswillbeupdatedonthe

serverandassignedanewversionnumber:1.1.Ourdeveloper

maynowbesohappywiththisversionthatsheaddsatag

called(imaginatively)"Revision_2."Eachfilewillbe"tagged"

withthislabel,makingiteasiertofetchfromtherepositoryata

laterdateorfromanothermachine.

Figure4-1.FileversioningwithCVS



NowthatwecanvisualizehowCVSdoesthings,let'slookat

oneofthemajorweaknessesofthisarchitecture.Suppose

duringacommitthatsomeoneelsestartscommittingchanges

atthesametimeandaconflictoccurs.Inthiscase,someofthe

fileswillhavebeenupdated,butotherswillhavebeenrefused,

whichleavestherepositoryinanunstablestate.Ifyoukillthe

process,switchoffyourmachine,orastreetworkerdrills

throughyourInternetconnection,similarnastythingscan

occur.TheCVSrepositorycanbeleftinanunstablestateuntil

thestreetworkerinquestionrepairsthecableandletsyou

resolveanyconflictsandcompleteyourcommitoperation.

Subversion,bycontrast,keepstrackofrevisions.Arevision(or,

moreprecisely,arevisiontree)isarepresentationofthe

repositorystructureandcontentsatagivenpointintime.

RevisionsarethecornerstoneofapowerfulSubversionfeature:

atomicupdates.UpdatingtheSubversionrepositoryisabitlike

updatingarelationaldatabaseusingtransactions:whenyou



commitasetofchanges,youareguaranteedthateitherallof

yourchangeshavebeenintegratedintotherepository,ornone

atallhave.

Behindthescenes,Subversionstoressuccessive

representationsoftheentirerepositorystructureasawhole

(seeFigure4-2).Eachrevisionisidentifiedbyauniquenumber.

Whenchangesarecommitted,Subversionpreparesanew

repositorystructureincorporatingthechanges.If(andonlyif)

everychangeissuccessfullyintegrated,anewrepositorytree

willbecreatedwithanewrevisionnumber.So,inpractice,

eitherallofyourchangesareupdatedcorrectlyinthe

repository,andyougetanewrevisionnumberincorporating

thesechanges,ornoneare,andyougettofixtheproblemand

tryagain.

Figure4-2.Subversionrevisions



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

Chapter 4. Setting Up Version Control Using Subversion

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

×