Skip to content

Commit

Permalink
Use externalFetchAndPush more
Browse files Browse the repository at this point in the history
* Use externalFetchAndPush for cloning (which calls fetchFrom:, not fetchFromAll:)
* Catch ConnectionClosed when fetching
  • Loading branch information
MariusDoe committed Apr 22, 2024
1 parent 3d8e9f6 commit 70aaedb
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
git porcelain
fetchFrom: aRemoteName
| remote url fetchSpec packFile protocol remoteRefs wantRefs wantSignatures packFileData |
remote := self unitOfWork remoteNamed: aRemoteName.
url := remote url ifNil: [(GitRemoteUndefined remote: remote) signal: 'No URL configured.'].
fetchSpec := remote fetchSpecs
ifEmpty: [GitFetchSpec
fromString: '+refs/heads/*:refs/remotes/', aRemoteName, '/*'
forRemote: remote]
ifNotEmpty: [:fetchSpecs | fetchSpecs first].
self flag: #todo. "regard all fetch specs, not just the first one"
protocol := GitAbstractProtocol url: url.
protocol
remote: remote;
withOpenConnection:
[remoteRefs := protocol refs.
wantRefs := remoteRefs keys select: [:each | fetchSpec remoteRefPattern match: each].
wantRefs ifEmpty: [^ (GitNothingToFetch from: remote) signal ifNil: [Dictionary new]].
wantSignatures := wantRefs collect: [:each | remoteRefs at: each].
packFileData := protocol wantAll: wantSignatures.
packFile := GitPackFile readFrom: packFileData readStream].
packFile repository: repository.
packFile unpack.
wantRefs do:
[:each | self unitOfWork
updateRef: (remote trackingRefOf: each)
to: (remoteRefs at: each)].
GitFeatureFlags pruneWhenFetching ifTrue: [
self
pruneRefs: fetchSpec
keep: (wantRefs collect: [:each | fetchSpec trackingRefOf: each])].
^ protocol refs
^ GitFeatureFlags externalFetchAndPush
ifTrue: [self fetchAllExternalFrom: aRemoteName]
ifFalse: [[self fetchInternalFrom: aRemoteName]
on: ConnectionClosed
do: [:exception |
self
handleConnectionClosed: exception
whileTryingTo: 'fetch'
ifRetry: [self fetchFrom: aRemoteName]]].
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
git porcelain
fetchFromAll: aCollectionOfRemoteNames
GitFeatureFlags externalFetchAndPush
ifTrue: [aCollectionOfRemoteNames do: [:each | self fetchAllExternalFrom: each]]
ifFalse: [aCollectionOfRemoteNames do: [:each | self fetchFrom: each]]
aCollectionOfRemoteNames do: [:each | self fetchFrom: each].
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
git porcelain
fetchInternalFrom: aRemoteName
| remote url fetchSpec packFile protocol remoteRefs wantRefs wantSignatures packFileData |
remote := self unitOfWork remoteNamed: aRemoteName.
url := remote url ifNil: [(GitRemoteUndefined remote: remote) signal: 'No URL configured.'].
fetchSpec := remote fetchSpecs
ifEmpty: [GitFetchSpec
fromString: '+refs/heads/*:refs/remotes/', aRemoteName, '/*'
forRemote: remote]
ifNotEmpty: [:fetchSpecs | fetchSpecs first].
self flag: #todo. "regard all fetch specs, not just the first one"
protocol := GitAbstractProtocol url: url.
protocol
remote: remote;
withOpenConnection:
[remoteRefs := protocol refs.
wantRefs := remoteRefs keys select: [:each | fetchSpec remoteRefPattern match: each].
wantRefs ifEmpty: [^ (GitNothingToFetch from: remote) signal ifNil: [Dictionary new]].
wantSignatures := wantRefs collect: [:each | remoteRefs at: each].
packFileData := protocol wantAll: wantSignatures.
packFile := GitPackFile readFrom: packFileData readStream].
packFile repository: repository.
packFile unpack.
wantRefs do:
[:each | self unitOfWork
updateRef: (remote trackingRefOf: each)
to: (remoteRefs at: each)].
GitFeatureFlags pruneWhenFetching ifTrue: [
self
pruneRefs: fetchSpec
keep: (wantRefs collect: [:each | fetchSpec trackingRefOf: each])].
^ protocol refs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
git porcelain
handleConnectionClosed: aConnectionClosed ifRetry: aBlock
handleConnectionClosed: aConnectionClosed whileTryingTo: aString ifRetry: aBlock
| preference |
preference := Preferences
pragmaPreferenceFor: GitFeatureFlags
getter: #externalFetchAndPush.
(self confirm:
'Pushing failed with the internal git implementation. ' asText,
'Do you want to try to automatically push using the git commandline? ',
('{1}ing failed with the internal git implementation. ' asText,
'Do you want to try to automatically {2} using the git commandline? ',
'This will enable ',
('a preference' asText
addAttribute: (PluggableTextAttribute evalBlock: [preference open]);
yourself),
' to remember your decision.')
' to remember your decision.' format: {aString capitalized. aString}))
ifFalse: [aConnectionClosed pass]
ifTrue: [
preference preferenceValue: true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ push: aCollectionOfBranchNamesAndAssociations toRemote: remoteName
do: [:exception |
self
handleConnectionClosed: exception
whileTryingTo: 'push'
ifRetry: [self push: aCollectionOfBranchNamesAndAssociations toRemote: remoteName]]]
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
"externalGitDo:" : "mad 12/20/2023 19:11",
"externalPush:toRemote:" : "mad 12/20/2023 19:11",
"fetchAllExternalFrom:" : "mad 4/22/2024 20:09",
"fetchFrom:" : "mad 4/7/2024 18:44",
"fetchFromAll:" : "tobe 10/15/2022 07:55",
"fetchFrom:" : "mad 4/22/2024 17:34",
"fetchFromAll:" : "mad 4/22/2024 17:25",
"fetchInternalFrom:" : "mad 4/22/2024 17:24",
"filesystemOn:" : "CamilloBruni 8/30/2012 14:06",
"flushCaches" : "jr 7/2/2017 19:12",
"gitStoreOn:" : "CamilloBruni 9/2/2012 12:33",
"handleConnectionClosed:ifRetry:" : "mad 12/18/2023 17:59",
"handleConnectionClosed:whileTryingTo:ifRetry:" : "mad 4/22/2024 17:21",
"handleTerminalCommandTemplateCharacter:from:into:withCommand:" : "mad 4/3/2024 16:18",
"head" : "jr 8/13/2020 23:10",
"headReference" : "jr 3/4/2020 00:47",
Expand All @@ -30,7 +31,7 @@
"orphanedHead" : "jr 1/29/2017 22:52",
"performTerminalCommandTemplateReplacement:in:" : "mad 4/3/2024 16:18",
"pruneRefs:keep:" : "mad 4/7/2024 14:44",
"push:toRemote:" : "mad 12/18/2023 17:54",
"push:toRemote:" : "mad 4/22/2024 17:21",
"pushToRemote:deleteRemoteBranches:" : "jr 1/2/2017 10:18",
"pushToRemote:update:deleteRemoteBranches:" : "jr 7/23/2020 00:43",
"pushToUpstreamBranchOf:ifNone:" : "jr 3/4/2020 00:49",
Expand Down

0 comments on commit 70aaedb

Please sign in to comment.