Optimization: speed up commit by performing `hg status` and `hg add` on multiple files at once
...instead of dealing with each file separately. This makes commit
faster as lot less hg commands are required to generate and track
build support files.
--- a/common/SCMAbstractFileoutLikeTask.st Mon Feb 13 21:36:41 2017 +0100
+++ b/common/SCMAbstractFileoutLikeTask.st Thu Feb 23 20:07:40 2017 +0000
@@ -174,17 +174,13 @@
| wcroot containers |
ActivityNotification notify:'Adding new containers'.
- containers := self containersToFileOutFor: package.
wcroot := package temporaryWorkingCopyRoot.
- containers do:[:nm|
- | entry |
-
- entry := wcroot / nm.
- entry track.
- ]
+ containers := (self containersToFileOutFor: package)
+ collect:[ :e | wcroot / e ].
+ self temporaryWorkingCopy track: containers.
"Created: / 22-02-2014 / 22:49:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 11-06-2015 / 06:39:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 28-02-2017 / 21:45:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
doCompileCopyrightMethods
@@ -503,23 +499,22 @@
supportFile writingFileDo:[:s|
s nextPutAll:supportFileContents
].
- actuallyGeneratedFiles add: supportFileName.
+ actuallyGeneratedFiles add: (package temporaryWorkingCopyRoot / supportFileName).
]
]
].
"Now, copy them over the old files"
- actuallyGeneratedFiles do:[:supportFileName |
- | supportFile supportFileTmp |
+ actuallyGeneratedFiles do:[:supportFile |
+ | supportFileTmp |
- supportFile := package temporaryWorkingCopyRoot / supportFileName.
- supportFileTmp := package temporaryWorkingCopyRoot / (supportFileName , '.tmp').
-
+ supportFileTmp := temporaryWorkingCopy pathName asFilename / (supportFile pathNameRelative , '.tmp').
supportFileTmp moveTo: supportFile.
- supportFile track.
].
+ "Finally make sure all generated files are tracked"
+ temporaryWorkingCopy track: actuallyGeneratedFiles.
"Created: / 21-02-2014 / 23:16:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 21-01-2015 / 07:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 23-02-2017 / 16:27:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
doUpdateCode
--- a/mercurial/HGCommand.st Mon Feb 13 21:36:41 2017 +0100
+++ b/mercurial/HGCommand.st Thu Feb 23 20:07:40 2017 +0000
@@ -179,7 +179,7 @@
!
HGCommand subclass:#status
- instanceVariableNames:'path'
+ instanceVariableNames:'paths'
classVariableNames:''
poolDictionaries:''
privateIn:HGCommand
@@ -2631,12 +2631,16 @@
!HGCommand::status methodsFor:'accessing'!
-path
- ^ path
+paths
+ ^ paths
+
+ "Created: / 23-02-2017 / 14:18:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-path:aString
- path := aString.
+paths:aCollection
+ paths := aCollection.
+
+ "Created: / 23-02-2017 / 14:18:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!HGCommand::status methodsFor:'private'!
@@ -2645,9 +2649,10 @@
"Called to get command specific options"
stream nextPut:'-A'.
- path notNil ifTrue:[stream nextPut: path]
+ paths notNil ifTrue:[stream nextPutAll: paths]
"Created: / 23-10-2012 / 11:09:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 23-02-2017 / 14:18:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
parseOutput:stream
--- a/mercurial/HGRepositoryObject.st Mon Feb 13 21:36:41 2017 +0100
+++ b/mercurial/HGRepositoryObject.st Thu Feb 23 20:07:40 2017 +0000
@@ -18,6 +18,8 @@
"
"{ Package: 'stx:libscm/mercurial' }"
+"{ NameSpace: Smalltalk }"
+
Object subclass:#HGRepositoryObject
instanceVariableNames:'repository'
classVariableNames:''
--- a/mercurial/HGWorkingCopy.st Mon Feb 13 21:36:41 2017 +0100
+++ b/mercurial/HGWorkingCopy.st Thu Feb 23 20:07:40 2017 +0000
@@ -242,6 +242,31 @@
root
^ root
+!
+
+statusesOf: workingCopyFiles
+ "Return a dictionary mapping `workingCopyFiles` to their actual
+ status (unmodified, modified, added, missing. removed...)"
+
+ | relativePathNames cmd out statuses |
+
+ statuses := Dictionary new.
+ workingCopyFiles notEmpty ifTrue:[
+ relativePathNames := workingCopyFiles collect:[ :e | e pathNameRelative ].
+ cmd := HGCommand status.
+ cmd workingDirectory: repository pathName.
+ cmd paths: relativePathNames.
+ out := repository execute: cmd.
+ self assert: out size == workingCopyFiles size.
+
+ workingCopyFiles do:[:each |
+ statuses at: each put: (out detect:[:pair | pair second = each pathNameRelative]) first.
+ ].
+ ].
+ ^ statuses
+
+ "Created: / 23-02-2017 / 14:38:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 23-02-2017 / 20:03:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!HGWorkingCopy methodsFor:'accessing-private'!
@@ -413,6 +438,26 @@
"Modified: / 03-03-2013 / 22:59:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+track: workingCopyFiles
+ "Make sure that all `workingCopyFiles` are tracked by the working copy
+ so subsequent #commit: would commit them to the repository."
+
+ | statuses workingCopyFilesToAdd |
+
+ statuses := self statusesOf: workingCopyFiles.
+ workingCopyFilesToAdd := workingCopyFiles select:[:e | (statuses at: e) isNotTracked ].
+ workingCopyFilesToAdd notEmpty ifTrue:[
+ repository execute:
+ (HGCommand add
+ workingDirectory: repository pathName;
+ paths: (workingCopyFilesToAdd collect:[ :e| e pathNameRelative ]);
+ yourself)
+ ].
+
+ "Created: / 23-02-2017 / 15:11:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 23-02-2017 / 16:29:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
update
"Update the working copy to the latest rev in current branch"
--- a/mercurial/HGWorkingCopyFile.st Mon Feb 13 21:36:41 2017 +0100
+++ b/mercurial/HGWorkingCopyFile.st Thu Feb 23 20:07:40 2017 +0000
@@ -181,18 +181,13 @@
!
status
- | cmd statuses |
+ | statuses |
- cmd := HGCommand status.
- cmd workingDirectory: filename directory.
- cmd path: filename pathName.
- statuses := self repository execute: cmd.
- self assert: statuses size == 1.
- self assert: statuses first second = filename baseName.
- ^statuses first first.
+ statuses := wc statusesOf: (Array with: self).
+ ^ statuses at: self.
"Created: / 24-09-2012 / 22:27:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 03-03-2013 / 23:04:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 23-02-2017 / 14:39:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
workingCopy
@@ -372,18 +367,17 @@
!
track
- "Make sure that this entry is tracked by Mercurial"
+ <resource: #obsolete>
+ "Make sure that this entry is tracked by Mercurial.
- self isUntracked ifTrue:[
- self repository execute:
- (HGCommand add
- workingDirectory: filename directory;
- paths: { filename baseName };
- yourself)
- ]
+ This method is obsolete, please use HGWorkingCopy >> track: instead
+ as it allows to track multiple files at once (making tools a little
+ faster)"
+ wc track: (Array with: self)
"Created: / 15-11-2012 / 00:08:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 03-03-2013 / 23:04:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 23-02-2017 / 15:11:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (format): / 23-02-2017 / 16:31:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!HGWorkingCopyFile methodsFor:'printing & storing'!