--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SVN__SyncWithCVSTask.st Wed Sep 23 18:50:00 2009 +0200
@@ -0,0 +1,322 @@
+"{ Package: 'cvut:stx/goodies/libsvn' }"
+
+"{ NameSpace: SVN }"
+
+CVSTask subclass:#SyncWithCVSTask
+ instanceVariableNames:'cvsWc newFiles obsoleteFiles branchPath'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'SVN-Tasks'
+!
+
+!SyncWithCVSTask class methodsFor:'documentation'!
+
+version_SVN
+ ^'$Id$'
+! !
+
+!SyncWithCVSTask class methodsFor:'accessing'!
+
+cvsRoot
+
+ ^(Smalltalk at:#CVSSourceCodeManager:CVSRoot)
+ ? CVSRoot
+ ? ':pserver:cvs@cvs.smalltalk-x.de:/cvs/stx'
+
+ "Created: / 19-08-2009 / 11:44:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!SyncWithCVSTask class methodsFor:'updating'!
+
+update:pkgs
+ ^ self doFor:pkgs
+
+ "Created: / 28-05-2009 / 11:10:01 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+update:pkgs logOn:log
+ ^ self doFor:pkgs logOn:log
+
+ "Created: / 28-05-2009 / 11:09:55 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+updateJv
+ "Updates repositories at smalltalk.felk.cvut.cz"
+
+ "
+ SVN::SyncWithCVSTask updateJv
+ "
+
+ self
+ update:#(
+ #'stx:libbasic'
+ #'stx:libbasic2'
+ #'stx:libbasic3'
+ #'stx:libtool'
+ )
+ logOn:
+ Filename homeDirectory / 'Projects' / 'SmalltalkX' /
+ ('cvs-sync-log-', (Date today printStringFormat:'%y-%m-%d') , '.txt')
+
+ "Created: / 19-08-2009 / 11:34:31 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 19-08-2009 / 12:49:59 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!SyncWithCVSTask methodsFor:'accessing'!
+
+branchPath
+ ^ branchPath
+!
+
+branchPath:aString
+
+ branchPath := aString.
+
+ "Modified: / 19-08-2009 / 11:17:38 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+package: aString
+
+ super package: aString.
+ (tmpDir construct: 'cvs-working-copy') recursiveMakeDirectory.
+ cvsWc := (tmpDir construct: 'cvs-working-copy') construct: packageDir.
+ cvsRoot := CVSSourceCodeManager getCVSROOTForModule: package.
+
+ "Created: / 28-05-2009 / 09:22:39 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 28-05-2009 / 11:45:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!SyncWithCVSTask methodsFor:'executing'!
+
+do
+ self notify: 'Syncing package ', package.
+ self
+ doCVSCheckout;
+ doCVSFixPackageContent;
+ doSVNCheckout;
+ doUpdate;
+ doSVNCommit;
+ doCleanup.
+ self notify: 'Package ' , package , ' synced'
+
+ "Created: / 02-06-2009 / 18:41:46 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+doCVSFixPackageContent
+
+ self
+ doFixPackageContentIn:cvsWc
+
+ "Created: / 02-06-2009 / 18:51:52 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+doUpdate
+ self
+ doNormalizeVersionMethodIn: workingCopy path doCopy: true;
+ doCopyFiles;
+ doSVNAddFiles: newFiles;
+ doSVNSetSvnKeywordPropertyFor: newFiles;
+ doSVNSetSvnEolStylePropertyFor: newFiles;
+ yourself
+
+ "Created: / 02-06-2009 / 18:59:19 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 19-08-2009 / 11:26:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!SyncWithCVSTask methodsFor:'executing - private'!
+
+doCVSCheckout
+
+ | cvs |
+ cvs := OSProcess new
+ executable: '/usr/bin/cvs';
+ arguments: {
+ '-d'.
+ cvsRoot.
+ 'checkout'.
+ packageDir.
+ };
+ stdout: transcript;
+ stderr: transcript;
+ workdir: (tmpDir construct:'cvs-working-copy').
+ cvs execute.
+ self
+ assert: cvs exitValue = 0
+ message: 'cvs failed to finish properly. Check transcript'.
+
+ "Created: / 02-06-2009 / 17:19:42 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 19-08-2009 / 11:47:59 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+doCopyFiles
+ | cvsFiles svnFilesSeen |
+
+ cvsFiles := cvsWc recursiveDirectoryContents
+ reject: [:e | e asFilename directoryName endsWith: 'CVS' ].
+ svnFilesSeen := Set new.
+ cvsFiles do:
+ [:cvsFileName |
+ | cvsFile svnFile svnFileCopy |
+
+ cvsFile := cvsWc construct: cvsFileName.
+ svnFile := workingCopy path / cvsFileName.
+ svnFileCopy := workingCopy path / (cvsFileName , '~').
+ svnFilesSeen add: svnFile.
+ svnFile exists
+ ifTrue:
+ [ (self is: cvsFile
+ sameAs: (svnFileCopy exists ifTrue: [ svnFileCopy ] ifFalse: [ svnFile ]))
+ ifFalse:
+ [ cvsFile copyTo: svnFile.
+ self notify: 'Updating ' , cvsFileName. ].
+ svnFileCopy exists ifTrue: [ self removeFiles: (Array with: svnFileCopy) ] ]
+ ifFalse:
+ [ newFiles add: svnFile.
+ cvsFile copyTo: svnFile.
+ self notify: 'Updating ' , cvsFileName. ]. ].
+ obsoleteFiles := (workingCopy path recursiveDirectoryContentsAsFilenames
+ reject: [:e | e directory baseName = '.svn' ]) \ svnFilesSeen.
+
+ "Created: / 02-06-2009 / 18:52:07 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 19-08-2009 / 11:27:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+doSVNAddFiles
+ newFiles isEmpty ifTrue: [ ^ self ].
+ (AddCommand new)
+ workingCopy: workingCopy;
+ paths: (newFiles collect: [:e | e pathName ]);
+ execute.
+
+ "Created: / 28-05-2009 / 10:59:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 19-08-2009 / 11:27:46 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+doSVNAddFiles: files
+ files isEmpty ifTrue: [ ^ self ].
+ (AddCommand new)
+ workingCopy: workingCopy;
+ paths: (files collect: [:e | e pathName ]);
+ execute.
+
+ "Created: / 02-06-2009 / 19:39:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 19-08-2009 / 11:27:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!SyncWithCVSTask methodsFor:'initialization'!
+
+initialize
+
+ super initialize.
+ branchPath := '/trunk'.
+ newFiles := Set new.
+ obsoleteFiles := Set new.
+
+ "Created: / 28-05-2009 / 09:08:32 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 19-08-2009 / 12:29:57 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!SyncWithCVSTask methodsFor:'passes'!
+
+pass56_RemoveFiles
+
+ "
+ svnFilesObsolete isEmpty ifTrue:[^self].
+
+ DeleteCommand new
+ workingCopy:svnWc pathName;
+ paths:(svnFilesObsolete collect:[:e|e pathName]);
+ execute.
+ "
+
+ "Created: / 28-05-2009 / 10:59:58 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 28-05-2009 / 17:52:36 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!SyncWithCVSTask methodsFor:'private'!
+
+is: fileA sameAs: fileB
+
+ ^false"/(fileA suffix = 'st' and:[fileB suffix = 'st'])
+ ifTrue: [self isSource: fileA sameAs: fileB]
+ ifFalse:[self isContent: fileA sameAs: fileB]
+
+ "Created: / 28-05-2009 / 19:58:05 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 02-06-2009 / 20:04:30 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+isContent: fileA sameAs: fileB
+
+ ^(
+ (MD5Stream hashValueOfFile: fileA)
+ = (MD5Stream hashValueOfFile: fileB)
+ )
+ ifTrue:[true] ifFalse:["self halt."false]
+
+ "Created: / 28-05-2009 / 22:28:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 03-06-2009 / 11:12:29 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+isSource: fileA sameAs: fileB
+
+ |rejectedVersionMethods changeSetA changeSetB diff |
+
+ rejectedVersionMethods := #( version version_CVS version_SVN ).
+
+ changeSetA := (ChangeSet fromFile: fileA) reject:
+ [:ch|ch isMethodChange
+ and:[ch isForMeta
+ and:[rejectedVersionMethods includes:ch changeSelector]]].
+ changeSetB := (ChangeSet fromFile: fileB) reject:
+ [:ch|ch isMethodChange
+ and:[ch isForMeta
+ and:[rejectedVersionMethods includes:ch changeSelector]]].
+ diff := changeSetA diffSetsAgainst: changeSetB.
+ ^diff isEmpty
+
+ "Created: / 28-05-2009 / 22:27:01 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 02-06-2009 / 20:22:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+removeFiles: files
+
+ files do:
+ [:file|(cvsWc construct: file) remove]
+
+ "Modified: / 02-06-2009 / 19:53:40 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+renameFile:file1 to:file2
+
+ file1 asFilename renameTo: file2 asString
+
+ "Modified: / 02-06-2009 / 19:36:29 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+svnBranchPath
+
+ ^branchPath
+
+ "Created: / 19-08-2009 / 11:16:54 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+svnCommitMessage
+
+ ^'Synchronized with CVS repository at:
+ ', cvsRoot asString
+
+ "Created: / 28-05-2009 / 09:18:02 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+svnRepositoryUrl
+
+ ^ (RepositoryManager repositoryUrlForPackage: package)
+
+ "Modified: / 19-08-2009 / 11:09:37 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!SyncWithCVSTask class methodsFor:'documentation'!
+
+version
+ ^ '$Header$'
+! !