Skip to content

Introduce IceTipRepositoryStatusModel to avoid multiple commit lookups #1918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: Pharo13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Iceberg-Libgit/IceGitCommit.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Class {
'datetime',
'ancestorIds',
'comment',
'packageNamesCache'
'packageNamesCache',
'projectCache'
],
#category : 'Iceberg-Libgit-Core',
#package : 'Iceberg-Libgit',
Expand Down Expand Up @@ -181,7 +182,8 @@ IceGitCommit >> project [

This is a quick fix of the issue for Pharo 7 release."

^ [ IceProjectReader readProjectFrom: self ]
projectCache ifNotNil: [ ^ projectCache ].
^ [ projectCache := IceProjectReader readProjectFrom: self ]
on: NotFound
do: [ self repository fetch. IceProjectReader readProjectFrom: self ]
]
Expand Down
19 changes: 15 additions & 4 deletions Iceberg-Libgit/IceLibgitRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,11 @@ IceLibgitRepository >> packageLocationFor: anIceSavedPackage [
]

{ #category : 'private - tags' }
IceLibgitRepository >> peelTag: anIceTag [
self handleLibgitError: [ | lgitRef |
lgitRef := (self repositoryHandle lookup: 'refs/tags/', anIceTag name).
^ self lookupCommit: lgitRef targetId hexString ]
IceLibgitRepository >> peelTag: anIceTag [

| id |
id := self tagTargetCommitId: anIceTag.
self handleLibgitError: [ ^ self lookupCommit: id ]
]

{ #category : 'API - project' }
Expand Down Expand Up @@ -866,6 +867,16 @@ IceLibgitRepository >> subdirectoryReference [
^ self location resolve: self subdirectoryPath
]

{ #category : 'private - tags' }
IceLibgitRepository >> tagTargetCommitId: anIceTag [

self handleLibgitError: [
| lgitRef |
lgitRef := self repositoryHandle lookup:
'refs/tags/' , anIceTag name.
^ lgitRef targetId hexString ]
]

{ #category : 'API - tags' }
IceLibgitRepository >> tags [
self handleLibgitError: [
Expand Down
9 changes: 6 additions & 3 deletions Iceberg-TipUI/IceTipRepositoryGroupPanel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ IceTipRepositoryGroupPanel >> initializeRepositoryList [
beResizable;
addColumn: (SpStringTableColumn new
title: 'Repositories';
evaluated: #description;
evaluated: [ :x | x description ];
formatted: [ :each | each descriptionString ];
displayColor: [ :each | each descriptionDecorator color ];
displayBold: [ :each | each descriptionDecorator isBold ];
displayItalic: [ :each | each descriptionDecorator isItalic ];
Expand All @@ -107,7 +108,8 @@ IceTipRepositoryGroupPanel >> initializeRepositoryList [
yourself);
addColumn: (SpStringTableColumn new
title: 'Status';
evaluated: #status;
evaluated: [ :x | x status ];
formatted: [ :each | each statusString ];
displayColor: [ :each | each statusDecorator color ];
displayBold: [ :each | each statusDecorator isBold ];
displayItalic: [ :each | each statusDecorator isItalic ];
Expand All @@ -116,7 +118,8 @@ IceTipRepositoryGroupPanel >> initializeRepositoryList [
yourself);
addColumn: (SpStringTableColumn new
title: 'Branch';
evaluated: #branchName;
evaluated: [ :x | x status ];
formatted: [ :each | each branchName ];
yourself);
actions: self selectionCommandsGroup;
activateOnDoubleClick;
Expand Down
108 changes: 2 additions & 106 deletions Iceberg-TipUI/IceTipRepositoryModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,8 @@ IceTipRepositoryModel >> createSourceDirectory [

{ #category : 'accessing' }
IceTipRepositoryModel >> description [
| text |

text := self displayString.
(self isLibGitAvailable and: [ self entity isModified ])
ifTrue: [ text := '*', text ].
^ text
]

{ #category : 'accessing' }
IceTipRepositoryModel >> descriptionDecorator [

(self isLibGitAvailable and: [ self entity isModified ])
ifTrue: [ ^ IceTipDescriptionDecorator modified ].
^ super descriptionDecorator
^ IceTipRepositoryStatusModel on: self
]

{ #category : 'testing' }
Expand Down Expand Up @@ -431,100 +419,8 @@ IceTipRepositoryModel >> shortCommitId [

{ #category : 'accessing' }
IceTipRepositoryModel >> status [
[
| status incoming outgoing |

self verifyDirectoryStructureIfMissing: [ :message | ^ message asString ].
self isLibGitAvailable ifFalse: [ ^ 'Unknown (No libgit2)' ].

entity workingCopy workingCopyState isUnknownCommitState
ifTrue: [ ^ entity workingCopy workingCopyState description ].
entity workingCopy isDetached
ifTrue: [ ^ 'Detached Working Copy' ].
(entity head isDetached and: [ entity head tags isNotEmpty ])
ifTrue: [ ^ 'Detached HEAD' ].
entity head isDetached
ifTrue: [ ^ 'Detached HEAD' ].

entity workingCopy project isUnborn
ifTrue: [ ^ 'No Project Found' ].

self isLoaded ifFalse: [ ^ 'Not loaded' ].

status := OrderedCollection new.
entity isModified ifTrue: [ status add: 'Uncommitted changes' ].

incoming := self incomingCommits size.
incoming > 0 ifTrue: [ status add: ('{1} incoming' format: { incoming })].

outgoing := self outgoingCommits size.
outgoing > 0 ifTrue: [ status add: ('{1} not published' format: { outgoing })].

status ifEmpty: [ status add: 'Up to date' ].

^ ', ' join: status ]
on: Error
do: [ :e | ^ e description ]
]

{ #category : 'accessing' }
IceTipRepositoryModel >> statusDecorator [

[
self entity isMissing
ifTrue: [ ^ IceTipStatusDecorator error ].
entity workingCopy workingCopyState isUnknownCommitState
ifTrue: [ ^ IceTipStatusDecorator error ].
entity workingCopy isDetached
ifTrue: [ ^ IceTipStatusDecorator error ].
(entity head isDetached and: [ entity head tags isNotEmpty ])
ifTrue: [ ^ IceTipStatusDecorator warning ].
entity head isDetached
ifTrue: [ ^ IceTipStatusDecorator error ].
entity workingCopy project isUnborn
ifTrue: [ ^ IceTipStatusDecorator error ]
]
on: Error
do: [ :e | ^ IceTipStatusDecorator error ].

^ IceTipStatusDecorator none
]

{ #category : 'accessing' }
IceTipRepositoryModel >> statusString [
[
| status incoming outgoing |

self verifyDirectoryStructureIfMissing: [ :message | ^ message asString ].

entity workingCopy workingCopyState isUnknownCommitState
ifTrue: [ ^ entity workingCopy workingCopyState description ].
entity workingCopy isDetached
ifTrue: [ ^ 'Detached Working Copy' ].
(entity head isDetached and: [ entity head tags isNotEmpty ])
ifTrue: [ ^ 'Detached HEAD' ].
entity head isDetached
ifTrue: [ ^ 'Detached HEAD' ].

entity workingCopy project isUnborn
ifTrue: [ ^ 'No Project Found' ].

self isLoaded ifFalse: [ ^ 'Not loaded' ].

status := OrderedCollection new.
entity isModified ifTrue: [ status add: 'Uncommitted changes' ].

incoming := self incomingCommits size.
incoming > 0 ifTrue: [ status add: ('{1} incoming' format: { incoming })].

outgoing := self outgoingCommits size.
outgoing > 0 ifTrue: [ status add: ('{1} not published' format: { outgoing })].

status ifEmpty: [ status add: 'Up to date' ].

^ ', ' join: status ]
on: Error
do: [ :e | ^ e description ]
^ IceTipRepositoryStatusModel on: self
]

{ #category : 'accessing' }
Expand Down
171 changes: 171 additions & 0 deletions Iceberg-TipUI/IceTipRepositoryStatusModel.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
"
I represent the status of a repository at a given time to be shown. I cache all results to avoid multiple lookups.
"
Class {
#name : 'IceTipRepositoryStatusModel',
#superclass : 'IceTipModel',
#instVars : [
'repositoryModel',
'head',
'isMissing',
'workingCopy',
'isDetached',
'isModified',
'project',
'workingCopyState'
],
#category : 'Iceberg-TipUI-Model',
#package : 'Iceberg-TipUI',
#tag : 'Model'
}

{ #category : 'instance creation' }
IceTipRepositoryStatusModel class >> on: aRepositoryModel [

^ self new
repositoryModel: aRepositoryModel;
yourself
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> branchName [

(repositoryModel isLibGitAvailable not or: [ self isMissing ])
ifTrue: [ ^ repositoryModel class unknownBranchLabel ].

^ self head description
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> descriptionDecorator [

(repositoryModel isLibGitAvailable and: [ self isRepositoryModified ])
ifTrue: [ ^ IceTipDescriptionDecorator modified ].
^ IceTipTextDecorator none
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> descriptionString [
| text |

text := repositoryModel displayString.
(repositoryModel isLibGitAvailable and: [ self isRepositoryModified ])
ifTrue: [ text := '*', text ].
^ text
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> entity [

^ repositoryModel entity
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> head [

^ head ifNil: [ head := self entity head ]
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> isDetached [

^ isDetached ifNil: [ isDetached := self workingCopy isDetached ]
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> isMissing [

^ isMissing ifNil: [ isMissing := self entity isMissing ]
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> isModified [

^ isModified ifNil: [ isModified := self workingCopy isModified ]
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> isRepositoryModified [

^ isModified ifNil: [ isModified := self entity isModified ]
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> project [

^ project ifNil: [ project := self workingCopy project ]
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> repositoryModel: anIceTipRepositoryModel [
repositoryModel := anIceTipRepositoryModel
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> statusDecorator [

[
self isMissing ifTrue: [ ^ IceTipStatusDecorator error ].
self workingCopyState isUnknownCommitState ifTrue: [
^ IceTipStatusDecorator error ].
self isDetached ifTrue: [
^ IceTipStatusDecorator error ].
self head isDetached ifTrue: [ ^ IceTipStatusDecorator warning ].
self project isUnborn ifTrue: [
^ IceTipStatusDecorator error ] ]
on: Error
do: [ :e | ^ IceTipStatusDecorator error ].

^ IceTipStatusDecorator none
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> statusString [

| state |
[
| status incoming outgoing |
repositoryModel verifyDirectoryStructureIfMissing: [ :message |
^ message asString ].
repositoryModel isLibGitAvailable ifFalse: [ ^ 'Unknown (No libgit2)' ].

state := self workingCopy workingCopyState.
state isUnknownCommitState ifTrue: [
^ state description ].
self isDetached ifTrue: [ ^ 'Detached Working Copy' ].

self head isDetached ifTrue: [ ^ 'Detached HEAD' ].

self project isUnborn ifTrue: [ ^ 'No Project Found' ].

repositoryModel isLoaded ifFalse: [ ^ 'Not loaded' ].

status := OrderedCollection new.
self entity isModified ifTrue: [ status add: 'Uncommitted changes' ].

incoming := repositoryModel incomingCommits size.
incoming > 0 ifTrue: [
status add: ('{1} incoming' format: { incoming }) ].

outgoing := repositoryModel outgoingCommits size.
outgoing > 0 ifTrue: [
status add: ('{1} not published' format: { outgoing }) ].

status ifEmpty: [ status add: 'Up to date' ].

^ ', ' join: status ]
on: Error
do: [ :e | ^ e description ]
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> workingCopy [

^ workingCopy ifNil: [ workingCopy := self entity workingCopy ]
]

{ #category : 'accessing' }
IceTipRepositoryStatusModel >> workingCopyState [

^ workingCopyState ifNil: [ workingCopyState := self workingCopy workingCopyState ]
]
Loading
Loading