Skip to content

Commit

Permalink
rename extended file analysis to TrackedFile. Add TrackedFileVersion.…
Browse files Browse the repository at this point in the history
… Add kumpel visualization for a version. feenkcom/gtoolkit#4140
  • Loading branch information
girba committed Nov 3, 2024
1 parent 28ecd0a commit 3c6420e
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 130 deletions.
129 changes: 0 additions & 129 deletions src/Iceberg-Git-CLI/PureGitExtendedFileAnalysis.class.st

This file was deleted.

2 changes: 1 addition & 1 deletion src/Iceberg-Git-CLI/PureGitFile.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Class {

{ #category : #accessing }
PureGitFile >> analyze [
^ PureGitExtendedFileAnalysis new
^ PureGitTrackedFile new
file: self;
analyze
]
Expand Down
152 changes: 152 additions & 0 deletions src/Iceberg-Git-CLI/PureGitTrackedFile.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
"
I am a collection of PureGitExtendedFileCommits, the result of an analysis of the historic evolution of one file.
"
Class {
#name : #PureGitTrackedFile,
#superclass : #Object,
#instVars : [
'file',
'extendedCommits',
'versions'
],
#category : #'Iceberg-Git-CLI-Pure'
}

{ #category : #operations }
PureGitTrackedFile >> analyze [
self computeOwnership.
self computeVersions
]

{ #category : #accessing }
PureGitTrackedFile >> authorOfTrackedLine: trackedLine [
| firstAppearance |
firstAppearance := trackedLine positionsInVersions findFirst: [ :position | position isZero not ].
^ firstAppearance isZero
ifTrue: [ 'not found' ]
ifFalse: [ (self commits at: firstAppearance) author ]
]

{ #category : #accessing }
PureGitTrackedFile >> commits [
^ extendedCommits
ifNil: [ extendedCommits := self file logPatchReverse toArray wait ]
]

{ #category : #operations }
PureGitTrackedFile >> computeOwnership [
| previous |
self commits do: [ :each |
previous
ifNil: [ each initializeAsFirst ]
ifNotNil: [ each initializeFromParent: previous ].
previous := each ]
]

{ #category : #operations }
PureGitTrackedFile >> computeVersions [
| previous count |
previous := nil.
count := self commits size.
versions := OrderedCollection new.
self commits
doWithIndex: [ :commit :rank |
| newContents line |
rank = 1
ifTrue: [ newContents := commit changesToParent applyToLines: #().
previous := newContents
collectWithIndex: [ :each :index |
PureGitTrackedLine new
line: each;
initializeForNumberOfVersions: count;
positionInVersionAt: rank put: index;
yourself ] ]
ifFalse: [ | oldLineNumber newLineNumber |
oldLineNumber := newLineNumber := 1.
newContents := Array
streamContents: [ :out |
commit changesToParent changeChunks
do: [ :changeChunk |
[ oldLineNumber < changeChunk effectiveOldStart ]
whileTrue: [ line := previous at: oldLineNumber.
line positionInVersionAt: rank put: newLineNumber.
out nextPut: line.
oldLineNumber := oldLineNumber + 1.
newLineNumber := newLineNumber + 1 ].
changeChunk newContentsLines
do: [ :newLine |
line := PureGitTrackedLine new
line: newLine allButFirst;
initializeForNumberOfVersions: count;
positionInVersionAt: rank put: newLineNumber;
yourself.
out nextPut: line.
newLineNumber := newLineNumber + 1 ].
oldLineNumber := oldLineNumber + changeChunk oldCount ].
[ oldLineNumber <= previous size ]
whileTrue: [ line := previous at: oldLineNumber.
line positionInVersionAt: rank put: newLineNumber.
out nextPut: line.
oldLineNumber := oldLineNumber + 1.
newLineNumber := newLineNumber + 1 ] ].
previous := newContents ].
versions
add: (PureGitTrackedFileVersion new
trackedFile: self;
commit: commit;
versionNumber: rank;
lines: previous) ].
^ versions
]

{ #category : #accessing }
PureGitTrackedFile >> file [
^ file
]

{ #category : #accessing }
PureGitTrackedFile >> file: aGitFile [
file := aGitFile
]

{ #category : #'as yet unclassified' }
PureGitTrackedFile >> gtVersionsFor: aView [
<gtView>
^ aView columnedList
title: 'Versions';
items: [ self versions ];
column: 'Index' text: [ :each | each versionNumber ] width: 50;
column: 'Timestamp' text: [ :each | (ZTimestampFormat fromString: '2001-02-03 16:05') format: each commit timestamp ] width: 110;
column: 'Commit' text: [ :each | each commit shortId ] width: 100;
column: 'Author' text: [ :each | each commit author ] width: 100;
column: 'Comment' text: [ :each | each commit comment firstLineWithEllipsis ];
column: 'Delta' text: [ :each | each commit numberOfLinesChangedDescription ] width: 50;
column: 'Lines count' text: [ :each | each lines size ] width: 50
]

{ #category : #accessing }
PureGitTrackedFile >> path [
^ self file path
]

{ #category : #printing }
PureGitTrackedFile >> printOn: stream [
super printOn: stream.
stream nextPut: $(.
stream nextPutAll: self path.
stream nextPut: $)
]

{ #category : #accessing }
PureGitTrackedFile >> uniqueTrackedLines [
| trackedLines |
trackedLines := IdentitySet new.
self versions do: [ :each |
trackedLines addAll: each lines ].
^ trackedLines
]

{ #category : #accessing }
PureGitTrackedFile >> versions [
^ versions
]
82 changes: 82 additions & 0 deletions src/Iceberg-Git-CLI/PureGitTrackedFileVersion.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Class {
#name : #PureGitTrackedFileVersion,
#superclass : #Object,
#instVars : [
'lines',
'versionNumber',
'commit',
'trackedFile'
],
#category : #'Iceberg-Git-CLI-Pure'
}

{ #category : #operations }
PureGitTrackedFileVersion >> commit [
^ commit
]

{ #category : #operations }
PureGitTrackedFileVersion >> commit: aCommit [
commit := aCommit
]

{ #category : #'as yet unclassified' }
PureGitTrackedFileVersion >> gtViewKumpelFor: composite [
<gtView>
^ composite explicit
title: 'Kumpel';
priority: 60;
tooltip: 'Show line history over time';
stencil: [ | container colors |
colors := BrExplicitIdentityNormalizer new
colors: BrGlamorousColors distinctTenLightColors;
defaultColor: Color veryLightGray.
container := BlElement new.
container
constraintsDo: [ :c |
c horizontal matchParent.
c vertical matchParent ].
trackedFile uniqueTrackedLines
do: [ :trackedLine |
| element |
element := trackedLine asKumpelGraphElement.
element
background: (colors value: (trackedFile authorOfTrackedLine: trackedLine)).
element
border: (colors value: (trackedFile authorOfTrackedLine: trackedLine)).
container addChild: element ].
container
addChild: (BlElement new
background: (Color black alpha: 0.3);
zIndex: 100;
size: PureGitTrackedLine versionWidth @ (PureGitTrackedLine lineHeight * (lines size));
relocate: ((versionNumber - 1)
* (PureGitTrackedLine versionWidth + PureGitTrackedLine versionMargin))
@ 0).
container ]
]

{ #category : #'as yet unclassified' }
PureGitTrackedFileVersion >> lines [
^ lines
]

{ #category : #operations }
PureGitTrackedFileVersion >> lines: aCollectionOfTrackedLines [
lines := aCollectionOfTrackedLines
]

{ #category : #operations }
PureGitTrackedFileVersion >> trackedFile: aTrackedFile [
trackedFile := aTrackedFile
]

{ #category : #'as yet unclassified' }
PureGitTrackedFileVersion >> versionNumber [
^ versionNumber
]

{ #category : #operations }
PureGitTrackedFileVersion >> versionNumber: aNumber [
versionNumber := aNumber
]
15 changes: 15 additions & 0 deletions src/Iceberg-Git-CLI/PureGitTrackedLine.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ Class {
#category : #'Iceberg-Git-CLI-Pure'
}

{ #category : #'as yet unclassified' }
PureGitTrackedLine class >> lineHeight [
^ 5
]

{ #category : #'as yet unclassified' }
PureGitTrackedLine class >> versionMargin [
^ 2
]

{ #category : #'as yet unclassified' }
PureGitTrackedLine class >> versionWidth [
^ 10
]

{ #category : #initialization }
PureGitTrackedLine >> initializeForNumberOfVersions: count [
positionInVersions := Array new: count withAll: 0
Expand Down

0 comments on commit 3c6420e

Please sign in to comment.