From 70aaedb94905e23de67534139fa2ef17f76e7e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20D=C3=B6rbandt?= Date: Mon, 22 Apr 2024 20:08:07 +0200 Subject: [PATCH] Use externalFetchAndPush more * Use externalFetchAndPush for cloning (which calls fetchFrom:, not fetchFromAll:) * Catch ConnectionClosed when fetching --- .../instance/fetchFrom..st | 39 +++++-------------- .../instance/fetchFromAll..st | 4 +- .../instance/fetchInternalFrom..st | 32 +++++++++++++++ ...onnectionClosed.whileTryingTo.ifRetry..st} | 8 ++-- .../instance/push.toRemote..st | 1 + .../methodProperties.json | 9 +++-- 6 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchInternalFrom..st rename src/FileSystem-Git.package/FileSystemGitRepository.class/instance/{handleConnectionClosed.ifRetry..st => handleConnectionClosed.whileTryingTo.ifRetry..st} (57%) diff --git a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchFrom..st b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchFrom..st index 9dcc5cb77..8e3c5dd23 100644 --- a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchFrom..st +++ b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchFrom..st @@ -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 \ No newline at end of file + ^ GitFeatureFlags externalFetchAndPush + ifTrue: [self fetchAllExternalFrom: aRemoteName] + ifFalse: [[self fetchInternalFrom: aRemoteName] + on: ConnectionClosed + do: [:exception | + self + handleConnectionClosed: exception + whileTryingTo: 'fetch' + ifRetry: [self fetchFrom: aRemoteName]]]. \ No newline at end of file diff --git a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchFromAll..st b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchFromAll..st index 2a58482d1..13b0d50ad 100644 --- a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchFromAll..st +++ b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchFromAll..st @@ -1,5 +1,3 @@ git porcelain fetchFromAll: aCollectionOfRemoteNames - GitFeatureFlags externalFetchAndPush - ifTrue: [aCollectionOfRemoteNames do: [:each | self fetchAllExternalFrom: each]] - ifFalse: [aCollectionOfRemoteNames do: [:each | self fetchFrom: each]] \ No newline at end of file + aCollectionOfRemoteNames do: [:each | self fetchFrom: each]. \ No newline at end of file diff --git a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchInternalFrom..st b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchInternalFrom..st new file mode 100644 index 000000000..d49c9c45e --- /dev/null +++ b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/fetchInternalFrom..st @@ -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 \ No newline at end of file diff --git a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/handleConnectionClosed.ifRetry..st b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/handleConnectionClosed.whileTryingTo.ifRetry..st similarity index 57% rename from src/FileSystem-Git.package/FileSystemGitRepository.class/instance/handleConnectionClosed.ifRetry..st rename to src/FileSystem-Git.package/FileSystemGitRepository.class/instance/handleConnectionClosed.whileTryingTo.ifRetry..st index 757d517b7..1c4230366 100644 --- a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/handleConnectionClosed.ifRetry..st +++ b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/handleConnectionClosed.whileTryingTo.ifRetry..st @@ -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. diff --git a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/push.toRemote..st b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/push.toRemote..st index 6581837f2..54a7592a9 100644 --- a/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/push.toRemote..st +++ b/src/FileSystem-Git.package/FileSystemGitRepository.class/instance/push.toRemote..st @@ -13,4 +13,5 @@ push: aCollectionOfBranchNamesAndAssociations toRemote: remoteName do: [:exception | self handleConnectionClosed: exception + whileTryingTo: 'push' ifRetry: [self push: aCollectionOfBranchNamesAndAssociations toRemote: remoteName]]] \ No newline at end of file diff --git a/src/FileSystem-Git.package/FileSystemGitRepository.class/methodProperties.json b/src/FileSystem-Git.package/FileSystemGitRepository.class/methodProperties.json index b742165de..83653d33a 100644 --- a/src/FileSystem-Git.package/FileSystemGitRepository.class/methodProperties.json +++ b/src/FileSystem-Git.package/FileSystemGitRepository.class/methodProperties.json @@ -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", @@ -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",