Skip to content

Commit

Permalink
Add PureGitMethodVersions [feenkcom/gtoolkit#4147]
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvc committed Nov 5, 2024
1 parent e2ec4e9 commit 928b493
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions src/Iceberg-Git-CLI/PureGitMethodVersions.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"
I hold all modifications to a specific method in a git repository
"
Class {
#name : #PureGitMethodVersions,
#superclass : #PureGitRepositoryObject,
#instVars : [
'method',
'versions'
],
#category : #'Iceberg-Git-CLI-Pure'
}

{ #category : #'instance creation' }
PureGitMethodVersions class >> with: aCompiledMethod [
^ self new
method: aCompiledMethod;
yourself
]

{ #category : #private }
PureGitMethodVersions >> computeVersions [
| packageName organization className selector classPath gitFile snapshots definitions uniqueDefinitions previous |
packageName := method package name.
organization := MCOrganizationDefinition categories: {packageName}.
className := method origin instanceSide name.
selector := method selector.
classPath := packageName , '/' , className , self tonelMethodClassExtension.
gitFile := repository resolveFilePath: repository srcPath , '/' , classPath.
snapshots := gitFile logReverse collect: [ :commit | | snapshot commitDefinitions |
commitDefinitions := TonelParser parseString: commit contentsByFilesystem.
commitDefinitions do: [ :definition |
definition isMethodDefinition ifTrue: [ definition setTimeStamp: commit ] ].
snapshot := MCSnapshot fromDefinitions: commitDefinitions , { organization }.
snapshot ].
definitions := snapshots toArray wait
flatCollect: [ :snapshot |
snapshot definitions
select: [ :definition |
definition isMethodDefinition
and: [ definition className = className
and: [ definition selector = selector ] ] ] ].
uniqueDefinitions := OrderedCollection new.
definitions do: [ :each | uniqueDefinitions addIfNotPresent: each ].
previous := nil.
^ uniqueDefinitions collect: [ :definition | | diff |
diff := GtDiffBuilder
computeDifferencesFrom: (previous ifNil: [ String empty ] ifNotNil: [previous diffSource ])
to: definition diffSource
using: GtSmaCCDiffSplitter forPharo.
previous := definition.
definition -> diff ]
]

{ #category : #private }
PureGitMethodVersions >> findMethodRepository [
| iceRepository |
iceRepository := IceRepository registeredRepositoryIncludingPackage: method package.
iceRepository
ifNil: [ ^ NotFound signal: ('Cannot find the git repository {1} belongs to' format: { method }) ].
^ PureGitCodeRepository on: iceRepository location
]

{ #category : #accessing }
PureGitMethodVersions >> method [
^ method
]

{ #category : #accessing }
PureGitMethodVersions >> method: aCompiledMethod [
method := aCompiledMethod
]

{ #category : #printing }
PureGitMethodVersions >> printOn: aStream [
super printOn: aStream.
aStream nextPut: $(; print: method; nextPut: $)
]

{ #category : #accessing }
PureGitMethodVersions >> repository [
^ repository ifNil: [ repository := self findMethodRepository ]
]

{ #category : #private }
PureGitMethodVersions >> tonelMethodClassExtension [
method isExtension ifTrue: [ ^ '.extension.st' ].
method isFromTrait ifTrue: [ ^ '.trait.set' ].
^ '.class.st'
]

{ #category : #accessing }
PureGitMethodVersions >> versions [
^ versions ifNil: [ versions := self computeVersions ]
]

{ #category : #accessing }
PureGitMethodVersions >> versions: aCollection [
versions := aCollection
]

0 comments on commit 928b493

Please sign in to comment.