Skip to content
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

Adding progress bar to long Git operations #891

Merged
merged 6 commits into from
Jun 27, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ libgit: spec
baseline: 'LibGit'
with: [
spec
repository: 'github://pharo-vcs/libgit2-pharo-bindings:v1.4.0';
repository: 'github://pharo-vcs/libgit2-pharo-bindings:v1.5.0';
loads: 'default' ].
spec
project: 'LibGit-Tests'
Expand Down
11 changes: 9 additions & 2 deletions Iceberg-Libgit.package/IceGitClone.class/instance/execute.st
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
actions
execute

| repo cloneOptions |
| repo cloneOptions checkoutOptions callbacks |
location exists
ifTrue: [ IceCloneLocationAlreadyExists signalFor: location ].

[location ensureCreateDirectory.

repo := LGitRepository on: location.
cloneOptions := LGitCloneOptions withCredentialsProvider: (IceCredentialsProvider defaultForRemoteUrl: url).
cloneOptions checkoutOptions checkoutStrategy: LGitCheckoutStrategyEnum git_checkout_force.

"Keeping references, because if not the GC take them."
checkoutOptions := cloneOptions checkoutOptions.
callbacks := cloneOptions fetchOptions callbacks.
callbacks transferProgress: IceGitTransferProgress new.

checkoutOptions checkoutStrategy: LGitCheckoutStrategyEnum git_checkout_force.
checkoutOptions progressCallback: IceGitCheckoutProgress new.

repo clone: url options: cloneOptions.

Expand Down
17 changes: 13 additions & 4 deletions Iceberg-Libgit.package/IceGitLocalBranch.class/instance/pushTo..st
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
API-remotes
pushTo: aRemote

repository
handleLibgitError: [ | gitRemote |
gitRemote := (LGitRemote of: self repositoryHandle named: aRemote name) lookup.
[ gitRemote
[
| pushProgress |
pushProgress := IcePushTransferProgress new.
gitRemote
pushWithRefSpec:
(LGitRefSpec new
source: self fullname;
destination: self fullname;
yourself)
pushOptions:
(LGitPushOptions defaults
callbacks: (LGitRemoteCallbacks withProvider: (IceCredentialsProvider defaultForRemote: aRemote));
callbacks: ((LGitRemoteCallbacks withProvider: (IceCredentialsProvider defaultForRemote: aRemote))
pushTransferProgress: pushProgress;
yourself );
yourself).

"Push tags!"
self tags
do: [ :tag |
do: [ :tag |
| tagProgress |
gitRemote
pushWithRefSpec:
(LGitRefSpec new
Expand All @@ -25,7 +32,9 @@ pushTo: aRemote
yourself)
pushOptions:
(LGitPushOptions defaults
callbacks: (LGitRemoteCallbacks withProvider: (IceCredentialsProvider defaultForRemote: aRemote));
callbacks: ((LGitRemoteCallbacks withProvider: (IceCredentialsProvider defaultForRemote: aRemote))
pushTransferProgress: pushProgress;
yourself);
yourself) ] ]
on: LGit_GIT_ENONFASTFORWARD
do: [ :e |
Expand Down
3 changes: 2 additions & 1 deletion Iceberg-Libgit.package/IceGitRemote.class/instance/fetch.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ fetch
localRepository handleLibgitError: [
[ (LGitRemote of: self repositoryHandle named: self name)
lookup;
fetchWithCredentials: (IceCredentialsProvider defaultForRemote: self) ]
fetchWithCredentials: (IceCredentialsProvider defaultForRemote: self)
andProgressCallback: IceGitTransferProgress new ]
on: LGitAbstractError
do: [ :e | e acceptError: (IceLibgitErrorVisitor onContext: self) ].

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
API-accessing
setHead: anIceGitCommitish

"Need to keep the reference, if not it is garbage collected. As the options are only passed to a FFI call"
| progress |
progress := IceGitCheckoutProgress new.

self handleLibgitError: [
self repositoryHandle
checkout: anIceGitCommitish gitRef
options:
(LGitCheckoutOptions defaults
checkoutStrategy: LGitCheckoutStrategyEnum git_checkout_force;
progressCallback: progress;
yourself) ]
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ basicExecute
| dialog |
dialog := IceTipLocalRepositoryPanel new
location: (self repository location ifNil: [ self defaultLocation ]);
subdirectory: (self repository subdirectory ifNil: [ self defaultSubdirectory ]);
yourself.
dialog openDialogWithSpec
okAction: [
[
dialog validate.
self repositoryModel
updateLocation: dialog location
subdirectory: dialog subdirectory.
self repositoryModel updateLocation: dialog location.
true ]
on: AssertionFailure
do: [ :e |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
actions
updateLocation: aReference subdirectory: aString
updateLocation: aReference

"change location"
self entity
location: aReference;
subdirectory: aString.
self entity location: aReference.
"force refresh packages"
self entity workingCopy project: self entity project.

Expand Down
Empty file.
5 changes: 5 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/changed.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
events
changed

current >= max ifTrue: [ ^ Job jobAnnouncer announce: (JobEnd on: self) ].
Job jobAnnouncer announce: (JobChange on: self)
3 changes: 3 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/current..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
current: anInteger
current := anInteger
3 changes: 3 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/end.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
events
end
Job jobAnnouncer announce: (JobEnd on: self)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
events
ensureStarted
started ifFalse: [ self start ]
4 changes: 4 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/initialize.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
initialization
initialize
super initialize.
started := false
3 changes: 3 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/max..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
max: anInteger
max := anInteger
3 changes: 3 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/min..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
min: anInteger
min := anInteger
3 changes: 3 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/owner.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
owner
^ nil
3 changes: 3 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/progress.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
progress
^ min >= max ifTrue: [ 1 ] ifFalse: [ (current - min) / (max - min) ]
5 changes: 5 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/start.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
events
start
started := true.

Job jobAnnouncer announce: (JobStart on: self)
3 changes: 3 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/title..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
title: aString
title := aString
3 changes: 3 additions & 0 deletions Iceberg.package/IceExternalJob.class/instance/title.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
title
^ title
17 changes: 17 additions & 0 deletions Iceberg.package/IceExternalJob.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"commentStamp" : "",
"super" : "Object",
"category" : "Iceberg-Progress",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"title",
"started",
"min",
"max",
"current"
],
"name" : "IceExternalJob",
"type" : "normal"
}
Empty file.
12 changes: 12 additions & 0 deletions Iceberg.package/IceGitCheckoutProgress.class/instance/block.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
accessing
block
^ [ :path :completed :total :payload |
job ensureStarted.

job min: 0.
job max: total.
job current: completed.
job title: ('Checking out... ({1}/{2})' format: { completed. total}).

job changed.
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
initialization
initialize
super initialize.

job := IceExternalJob new
title: 'Checking out...';
yourself.

self initializeBlock.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialization
initializeBlock
self signature: self class fnSpec block: self block.
13 changes: 13 additions & 0 deletions Iceberg.package/IceGitCheckoutProgress.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "LGitCheckoutProgressCallback",
"category" : "Iceberg-Progress",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"job"
],
"name" : "IceGitCheckoutProgress",
"type" : "normal"
}
Empty file.
16 changes: 16 additions & 0 deletions Iceberg.package/IceGitTransferProgress.class/instance/block.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
accessing
block
^ [ :stats :payload |
| gitStats |
gitStats := LGitTransferProgress fromHandle: stats.
job ensureStarted.

job min: 0.
job max: gitStats prim_total_objects.
job current: gitStats prim_received_objects.
job title: ('Fetching Git objects... ({1}/{2})' format: { gitStats prim_received_objects. gitStats prim_total_objects}).

job changed.

0
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
accessing
initialize
super initialize.

job := IceExternalJob new
title: 'Fetching Git objects...';
yourself.

self initializeBlock.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialize - release
initializeBlock
self signature: self class fnSpec block: self block.
13 changes: 13 additions & 0 deletions Iceberg.package/IceGitTransferProgress.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "LGitTransferProgressCallback",
"category" : "Iceberg-Progress",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"job"
],
"name" : "IceGitTransferProgress",
"type" : "normal"
}
Empty file.
14 changes: 14 additions & 0 deletions Iceberg.package/IcePushTransferProgress.class/instance/block.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
accessing
block
^ [ :current :total :bytes :payload |
job ensureStarted.

job min: 0.
job max: total.
job current: current.
job title: ((self title, ' ({1}/{2})') format: { current. total}).

job changed.

0
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
accessing
initialize
super initialize.

job := IceExternalJob new
title: self title;
yourself.

self initializeBlock.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialization
initializeBlock
self signature: self class fnSpec block: self block.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
title
^ 'Pushing...'
13 changes: 13 additions & 0 deletions Iceberg.package/IcePushTransferProgress.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "LGitPushTransferProgressCallback",
"category" : "Iceberg-Progress",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"job"
],
"name" : "IcePushTransferProgress",
"type" : "normal"
}
4 changes: 3 additions & 1 deletion Iceberg.package/IceRepository.class/instance/fetch.st
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
API-remotes
fetch
"Fetch all commits and branches from all remotes"
self remotes do: [ :each | each fetch ]

self remotes do: [ :each | each fetch ]
displayingProgress: [ :each | 'Remote: ' , each name asString ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ refreshProjectFromRepository
project := (referenceCommit isCollection
ifTrue: [ referenceCommit first ]
ifFalse: [ referenceCommit ]) project.
self refreshProject
self refreshProject.

^ project
Loading