Change Set File Out problem Problem 2
Eric Arseneau
earseneau at exobox.com
Wed Nov 15 04:49:44 UTC 2000
Yet another. This mail is quite long and involved, so read at your own
peril ;-)
Problem 2:
---------------
I have two definitions of a class that get filed out. One at the beginning
and one at the end. The first is my original class definition, the last is
the final one I had. Is this done on purpose. If it is, then can I turn it
off. It creates change sets that are not as clean as they should be.
Especially if I create some code, file it out, then file it in later into
another image to compare how it works. If I had created the classes by hand
again, then I don't get the same result. I do not believe this to be a good
thing.
I have not found a test scenario for this, but here is a description from
inspecting the following code:
ChangeSet>>fileOutOn: stream
"Write out all the changes the receiver knows about"
| classList |
(self isEmpty and: [stream isKindOf: FileStream])
ifTrue: [self notify: 'Warning: no changes to file out'].
classList _ ChangeSet superclassOrder: self changedClasses
asOrderedCollection.
"First put out rename, max classDef and comment changes."
>> classList do: [:aClass | self fileOutClassDefinition: aClass on:
stream].
"Then put out all the method changes"
classList do: [:aClass | self fileOutChangesFor: aClass on: stream].
"Finally put out removals, final class defs and reorganization if
any"
>> classList reverseDo: [:aClass | self fileOutPSFor: aClass on:
stream].
self classRemoves asSortedCollection do:
[:aClassName | stream nextChunkPut: 'Smalltalk
removeClassNamed: #', aClassName; cr].
The first >> shows you where the first class definition comes from. This
class definition will either be the definition of the class itself, or a
merge of the current and prior definitions of the class, as per my Problem 1
description.
Then the second >>, the fileOutPSFor:on: checks to see if there has been a
change in the class definition, and whether the class definition that was
first filed matches the current one. If they do not match, then a new class
definition is put out.
The only thing I can see this for is for image segments, isolated change
sets and such. The problem is that I should not have a change set be
dirtied up by these artifacts unless I am using such mechanisms. In order
to get rid of these two problems I have had to do the following within our
group:
ChangeSet>>fatDefForClass: class
| newDef oldDef oldStrm newStrm outStrm oldVars newVars addedVars |
newDef _ class definition.
"EAT: It's unclear why this code does what it does. But for us it
causes a problem, so I get rid of it.
The problem is that if change set record has a prior
definition, which happens if I file in a new
class. Then removing instance variables becomes a no-op,
since the code below will merge the
old and new inst vars together."
true ifTrue: [
^newDef].
oldDef _ (self changeRecorderFor: class) priorDefinition.
oldDef ifNil: [^ newDef].
oldDef = newDef ifTrue: [^ newDef].
oldStrm _ ReadStream on: oldDef.
newStrm _ ReadStream on: newDef.
outStrm _ WriteStream on: (String new: newDef size * 2).
"Merge inst vars from old and new defs..."
oldStrm upToAll: 'instanceVariableNames:'; upTo: $'.
outStrm nextPutAll: (newStrm upToAll: 'instanceVariableNames:');
nextPutAll: 'instanceVariableNames:';
nextPutAll: (newStrm upTo: $'); nextPut: $'.
oldVars _ (oldStrm upTo: $') findTokens: Character separators.
newVars _ (newStrm upTo: $') findTokens: Character separators.
addedVars _ oldVars asSet addAll: newVars; removeAll: oldVars;
asOrderedCollection.
oldVars , addedVars do: [:var | outStrm nextPutAll: var; space].
outStrm nextPut: $'.
class isMeta ifFalse:
["Merge class vars from old and new defs..."
oldStrm upToAll: 'classVariableNames:'; upTo: $'.
outStrm nextPutAll: (newStrm upToAll:
'classVariableNames:'); nextPutAll: 'classVariableNames:';
nextPutAll: (newStrm upTo: $'); nextPut: $'.
oldVars _ (oldStrm upTo: $') findTokens: Character
separators.
newVars _ (newStrm upTo: $') findTokens: Character
separators.
addedVars _ oldVars asSet addAll: newVars; removeAll:
oldVars; asOrderedCollection.
oldVars , addedVars do: [:var | outStrm nextPutAll: var;
space].
outStrm nextPut: $'].
outStrm nextPutAll: newStrm upToEnd.
The fix is really ugly, but until I can get a better understanding of what
is going on, I can't see how to do this differently. Any help would be
appreciated.
More information about the Squeak-dev
mailing list
|