mercurial/HGWorkingCopyFile.st
changeset 54 66045198bfbc
parent 39 10e693b3e034
child 61 fd129d0c603e
--- a/mercurial/HGWorkingCopyFile.st	Thu Nov 15 01:42:14 2012 +0000
+++ b/mercurial/HGWorkingCopyFile.st	Thu Nov 15 01:44:36 2012 +0000
@@ -60,6 +60,32 @@
     "Created: / 24-09-2012 / 13:46:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!HGWorkingCopyFile methodsFor:'enumerating-contents'!
+
+directoryContentsAsFilenamesDo:aBlock
+    "evaluate aBlock for each file in the directory represented by the receiver.
+     The block is invoked with a filename-argument.
+     The enumerations order is undefined - i.e. usually NOT sorted by
+     filenames (but by creation time - on some systems).
+     This excludes entries for '.' or '..'.
+     NoOp for non-existing directories; however, this behavior
+     may be changed in the near future, to raise an exception instead.
+     So users of this method better test for existing directory before.
+     Notice: this enumerates fileName objects; see also
+     #directoryContentsDo:, which enumerates strings."
+
+    self directoryContentsDo:[:entry |
+        aBlock value:(self construct:entry).
+    ]
+
+    "
+     '.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName].
+    "
+
+    "Modified: / 18.9.1997 / 18:42:23 / stefan"
+    "Modified: / 23.12.1999 / 20:56:35 / cg"
+! !
+
 !HGWorkingCopyFile methodsFor:'initialization'!
 
 setWorkingCopy: aHGWorkingCopy path: aStringOrFilename
@@ -106,6 +132,50 @@
     "Created: / 24-09-2012 / 23:25:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!HGWorkingCopyFile methodsFor:'operations'!
+
+moveTo: destination
+    "Make sure that this entry is tracked by Mercurial"
+
+    self isTracked ifTrue:[
+        HGCommand mv
+            workingDirectory: filename directory;
+            source: filename pathName;
+            destination: destination pathName;
+            execute.
+    ].
+    filename moveTo: destination pathName
+
+    "Created: / 15-11-2012 / 00:23:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+remove
+    "Make sure that this entry is tracked by Mercurial"
+
+    self isTracked ifTrue:[
+        HGCommand remove
+            workingDirectory: filename directory;
+            paths: { filename baseName }
+            execute
+    ].
+    filename remove
+
+    "Created: / 15-11-2012 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+track
+    "Make sure that this entry is tracked by Mercurial"
+
+    self isUntracked ifTrue:[
+        HGCommand add
+            workingDirectory: filename directory;
+            paths: { filename baseName };
+            execute.
+    ]
+
+    "Created: / 15-11-2012 / 00:08:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !HGWorkingCopyFile methodsFor:'printing & storing'!
 
 printOn:aStream
@@ -122,6 +192,80 @@
     "Modified: / 17-10-2012 / 13:51:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!HGWorkingCopyFile methodsFor:'reading-directories'!
+
+directoryContentsAsFilenames
+    "return the contents of the directory as a collection of filenames.
+     This excludes any entries for '.' or '..'.
+     Returns nil for non-existing directories; however, this behavior
+     may be changed in the near future, to raise an exception instead.
+     So users of this method better test for existing directory before.
+     Notice: 
+        this returns the file-names as fileName instances; 
+        see also #directoryContents, which returns strings."
+
+    |names|
+
+    names := filename directoryContents.
+    names isNil ifTrue:[^ nil].
+    ^ names collect:[:entry | self construct:entry].
+
+    "
+     '.' asFilename directoryContentsAsFilenames   
+     '/XXXdoesNotExist' asFilename directoryContentsAsFilenames
+    "
+
+    "Modified: / 15-11-2012 / 01:13:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+directoryContentsAsFilenamesMatching: patternOrCollectionOfThose
+
+    "
+        Same as directoryContentsAsFilenames, but returns only files
+        that matches given patterns. This uses String>>matches:
+        for pattern matching
+    "
+
+    |names|
+
+    names := filename directoryContentsMatching: patternOrCollectionOfThose .
+    names isNil ifTrue:[^ nil].
+    ^ names asOrderedCollection collect:[:entry | self construct:entry].
+
+    "
+    '/etc' asFilename
+        directoryContentsAsFilenamesMatching: 'pass*'
+
+    '/etc' asFilename
+            directoryContentsAsFilenamesMatching: #('pass*' 'nsswitch.conf')
+    "
+
+    "Created: / 03-06-2009 / 09:57:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 15-11-2012 / 01:13:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+recursiveDirectoryContentsAsFilenames
+    "return the contents of the directory and all subdirectories
+     as a collection of filenames.
+     This excludes any entries for '.' or '..'.
+     Returns nil for non-existing directories; however, this behavior
+     may be changed in the near future, to raise an exception instead.
+     So users of this method better test for existing directory before.
+     Notice: 
+        this returns the file-names as fileName instances; 
+        see also #recursiveDirectoryContents, which returns strings.
+
+     Warning: this may take a long time to execute."
+
+    |names|
+
+    names := filename recursiveDirectoryContents.
+    names isNil ifTrue:[^ nil].
+    ^ names collect:[:entry | self construct:entry].
+
+    "Created: / 15-11-2012 / 01:11:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !HGWorkingCopyFile methodsFor:'testing'!
 
 isAdded
@@ -136,6 +280,15 @@
     "Modified: / 23-10-2012 / 11:13:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+isCleanOrIgnored
+    | s |
+
+    s := self status.
+    ^s isClean or:[s isIgnored]
+
+    "Created: / 15-11-2012 / 01:25:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 isIgnored
     ^ self status isIgnored
 
@@ -164,10 +317,47 @@
     ^ self status isRemoved
 
     "Modified: / 23-10-2012 / 11:13:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isTracked
+    | s |
+
+    s := self status.
+    ^s isNotTracked not and:[s isIgnored not and:[s isRemoved not]]
+
+    "Created: / 15-11-2012 / 00:11:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isUntracked
+    "An alias for not-tracked"
+    ^ self isNotTracked
+
+    "Created: / 14-11-2012 / 23:56:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isUntrackedOrIgnored
+    | s |
+
+    s := self status.
+    ^s isNotTracked or:[s isIgnored]
+
+    "Created: / 15-11-2012 / 01:23:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isUnversioned
+    "An alias for not-tracked"
+    ^ self isNotTracked
+
+    "Created: / 14-11-2012 / 23:56:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGWorkingCopyFile class methodsFor:'documentation'!
 
+version_HG
+    "Never, ever change this method. Ask JV or CG why"
+    ^thisContext method mclass theNonMetaclass instVarNamed: #revision
+!
+
 version_SVN
     ^ '$Id::                                                                                                                        $'
 ! !