From 8589f8074d6ea3e0ac22c0ed9a1b6a9353bd11a4 Mon Sep 17 00:00:00 2001 From: Tudor Girba Date: Mon, 4 Nov 2024 22:00:13 +0100 Subject: [PATCH] improved lineSequence algorithm (still not complete) feenkcom/gtoolkit#4140 --- .../PureGitTrackedFile.class.st | 9 +++++--- .../PureGitTrackedLine.class.st | 22 ++++++++++++++++++- .../PureGitTrackedLineSequence.class.st | 2 +- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Iceberg-Git-CLI/PureGitTrackedFile.class.st b/src/Iceberg-Git-CLI/PureGitTrackedFile.class.st index 8e560cb..bfb1779 100644 --- a/src/Iceberg-Git-CLI/PureGitTrackedFile.class.st +++ b/src/Iceberg-Git-CLI/PureGitTrackedFile.class.st @@ -118,12 +118,15 @@ PureGitTrackedFile >> file: aGitFile [ PureGitTrackedFile >> lineSequences [ | sequences lines | sequences := OrderedCollection new. - lines := self uniqueTrackedLines asOrderedCollection. + lines := self uniqueTrackedLines + sorted: [ :a :b | + a startVersion < b startVersion + or: [ a startVersion = b startVersion + and: [ a positionInStartVersion < b positionInStartVersion ] ] ]. sequences add: (PureGitTrackedLineSequence new addLine: lines first). lines allButFirst do: [ :each | - (sequences last lines first startVersion = each startVersion - and: [ sequences last lines first endVersion = each endVersion ]) + sequences last endVersion = each endVersion ifTrue: [ sequences last addLine: each ] ifFalse: [ sequences add: (PureGitTrackedLineSequence new addLine: each) ] ]. ^ sequences diff --git a/src/Iceberg-Git-CLI/PureGitTrackedLine.class.st b/src/Iceberg-Git-CLI/PureGitTrackedLine.class.st index 502d1a4..83f98cb 100644 --- a/src/Iceberg-Git-CLI/PureGitTrackedLine.class.st +++ b/src/Iceberg-Git-CLI/PureGitTrackedLine.class.st @@ -33,10 +33,19 @@ PureGitTrackedLine >> endVersion [ self positionsInVersions reverse doWithIndex: [ :each :index | (end isZero and: each isZero not) - ifTrue: [ end := self positionsInVersions size - index ] ]. + ifTrue: [ end := self positionsInVersions size - index + 1 ] ]. ^ end ] +{ #category : #'as yet unclassified' } +PureGitTrackedLine >> gtPositionsInVersionsFor: aView [ + + ^ aView list + title: 'Positions'; + priority: 50; + items: [ self positionsInVersions ] +] + { #category : #initialization } PureGitTrackedLine >> initializeForNumberOfVersions: count [ positionInVersions := Array new: count withAll: 0 @@ -52,6 +61,16 @@ PureGitTrackedLine >> line: aString [ line := aString ] +{ #category : #'as yet unclassified' } +PureGitTrackedLine >> positionInEndVersion [ + ^ self positionInVersionAt: self endVersion +] + +{ #category : #'as yet unclassified' } +PureGitTrackedLine >> positionInStartVersion [ + ^ self positionInVersionAt: self startVersion +] + { #category : #accessing } PureGitTrackedLine >> positionInVersionAt: index [ ^ positionInVersions at: index @@ -75,6 +94,7 @@ PureGitTrackedLine >> printOn: stream [ nextPutAll: line; nextPut: $); space; + nextPutAll: 'ver. '; nextPutAll: self startVersion asString; nextPutAll: '-'; nextPutAll: self endVersion asString diff --git a/src/Iceberg-Git-CLI/PureGitTrackedLineSequence.class.st b/src/Iceberg-Git-CLI/PureGitTrackedLineSequence.class.st index cff51a8..d6a0dd5 100644 --- a/src/Iceberg-Git-CLI/PureGitTrackedLineSequence.class.st +++ b/src/Iceberg-Git-CLI/PureGitTrackedLineSequence.class.st @@ -21,7 +21,7 @@ PureGitTrackedLineSequence >> endVersion [ PureGitTrackedLineSequence >> gtDisplayOn: stream [ stream nextPutAll: self lines size asString; - nextPutAll: ' lines '; + nextPutAll: ' lines in ver. '; nextPutAll: self startVersion asString; nextPutAll: '-'; nextPutAll: self endVersion asString