From eaf7c78d13273c4fbebeab2f908ecbb645cc22fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20D=C3=B6rbandt?= Date: Tue, 28 Nov 2023 19:16:38 +0100 Subject: [PATCH] Implement moved image handling --- .../instance/handleMovedImage.st | 3 --- .../instance/handleMovedImageFrom.to..st | 26 +++++++++++++++++++ .../instance/imageHash.st | 6 +++-- .../instance/refsBaseName.st | 2 +- .../instance/refsBaseNameForHash..st | 3 +++ .../methodProperties.json | 7 ++--- 6 files changed, 38 insertions(+), 9 deletions(-) delete mode 100644 src/Squot.package/SqueakWorkingCopy.class/instance/handleMovedImage.st create mode 100644 src/Squot.package/SqueakWorkingCopy.class/instance/handleMovedImageFrom.to..st create mode 100644 src/Squot.package/SqueakWorkingCopy.class/instance/refsBaseNameForHash..st diff --git a/src/Squot.package/SqueakWorkingCopy.class/instance/handleMovedImage.st b/src/Squot.package/SqueakWorkingCopy.class/instance/handleMovedImage.st deleted file mode 100644 index 4d84d847d..000000000 --- a/src/Squot.package/SqueakWorkingCopy.class/instance/handleMovedImage.st +++ /dev/null @@ -1,3 +0,0 @@ -image-hash -handleMovedImage - self flag: #todo. \ No newline at end of file diff --git a/src/Squot.package/SqueakWorkingCopy.class/instance/handleMovedImageFrom.to..st b/src/Squot.package/SqueakWorkingCopy.class/instance/handleMovedImageFrom.to..st new file mode 100644 index 000000000..6a0a1a35c --- /dev/null +++ b/src/Squot.package/SqueakWorkingCopy.class/instance/handleMovedImageFrom.to..st @@ -0,0 +1,26 @@ +image-hash +handleMovedImageFrom: oldHash to: newHash + | doMove oldPrefix newPrefix oldRefs | + doMove := (UIManager default + chooseFrom: {'I copied it.'. 'I moved it.'} + title: + 'The image is not where it used to be. Did you move or copy it?', String cr, + 'If in doubt, choose copy.') + = 2. + oldPrefix := self refsBaseNameForHash: oldHash. + newPrefix := self refsBaseNameForHash: newHash. + self withUnitOfWork: [ + oldRefs := self allReferences select: [:each | each startsWith: oldPrefix]. + oldRefs do: [:oldRef | | newRef | + newRef := newPrefix, (oldRef allButFirst: oldPrefix size). + self unitOfWork + perform: (doMove ifTrue: [#moveRef:to:] ifFalse: [#copyRef:to:]) + with: oldRef + with: newRef]. + self allReferences do: [:each | | ref target | + ref := self unitOfWork ref: each. + ((ref name startsWith: newPrefix) + and: [ref isSymbolic] + and: [(target := ref targetRef) startsWith: oldPrefix]) + ifTrue: [ + self unitOfWork updateSymbolicRef: ref name toRef: newPrefix, (target allButFirst: oldPrefix size) message: nil]]]. \ No newline at end of file diff --git a/src/Squot.package/SqueakWorkingCopy.class/instance/imageHash.st b/src/Squot.package/SqueakWorkingCopy.class/instance/imageHash.st index aa3d7b51b..fc058a8de 100644 --- a/src/Squot.package/SqueakWorkingCopy.class/instance/imageHash.st +++ b/src/Squot.package/SqueakWorkingCopy.class/instance/imageHash.st @@ -1,7 +1,9 @@ image-hash imageHash - | hash | + | hash lastHash | hash := self basicImageHash. - hash ~= self lastImageHash ifTrue: [self handleMovedImage]. + lastHash := self lastImageHash. self lastImageHash: hash. + hash ~= lastHash ifTrue: [ + self handleMovedImageFrom: lastHash to: hash]. ^ hash \ No newline at end of file diff --git a/src/Squot.package/SqueakWorkingCopy.class/instance/refsBaseName.st b/src/Squot.package/SqueakWorkingCopy.class/instance/refsBaseName.st index de3cb035c..92e91aa04 100644 --- a/src/Squot.package/SqueakWorkingCopy.class/instance/refsBaseName.st +++ b/src/Squot.package/SqueakWorkingCopy.class/instance/refsBaseName.st @@ -1,3 +1,3 @@ refs refsBaseName - ^ 'refs/squeak/', self imageHash, '/' \ No newline at end of file + ^ self refsBaseNameForHash: self imageHash \ No newline at end of file diff --git a/src/Squot.package/SqueakWorkingCopy.class/instance/refsBaseNameForHash..st b/src/Squot.package/SqueakWorkingCopy.class/instance/refsBaseNameForHash..st new file mode 100644 index 000000000..bf24f7134 --- /dev/null +++ b/src/Squot.package/SqueakWorkingCopy.class/instance/refsBaseNameForHash..st @@ -0,0 +1,3 @@ +refs +refsBaseNameForHash: aString + ^ 'refs/squeak/', aString, '/' \ No newline at end of file diff --git a/src/Squot.package/SqueakWorkingCopy.class/methodProperties.json b/src/Squot.package/SqueakWorkingCopy.class/methodProperties.json index cde52ed1f..4f2dcb999 100644 --- a/src/Squot.package/SqueakWorkingCopy.class/methodProperties.json +++ b/src/Squot.package/SqueakWorkingCopy.class/methodProperties.json @@ -62,14 +62,14 @@ "gitInitialize" : "mad 6/4/2023 13:42", "handleCredentialsDuring:" : "mad 9/18/2023 14:13", "handleCredentialsDuring:ifCanceled:" : "mad 10/17/2023 12:11", - "handleMovedImage" : "mad 6/9/2023 19:05", + "handleMovedImageFrom:to:" : "mad 11/28/2023 19:12", "headCommit" : "mad 6/3/2023 15:35", "headCommitHash" : "mad 6/3/2023 15:34", "headFSCommit" : "mad 10/21/2023 23:43", "headRef" : "mad 6/4/2023 13:26", "headRefBasename" : "mad 10/16/2023 22:47", "headRefName" : "mad 10/16/2023 22:47", - "imageHash" : "mad 6/9/2023 19:06", + "imageHash" : "mad 11/28/2023 18:18", "initialRemoteRefNameFor:" : "mad 9/18/2023 13:58", "initialize" : "mad 9/18/2023 12:52", "initializeHead" : "mad 6/10/2023 14:59", @@ -105,7 +105,8 @@ "pushRef:" : "mad 9/18/2023 20:07", "refChanged:" : "mad 9/15/2023 11:05", "refName:" : "mad 6/3/2023 14:17", - "refsBaseName" : "mad 6/3/2023 14:16", + "refsBaseName" : "mad 11/28/2023 15:33", + "refsBaseNameForHash:" : "mad 11/28/2023 15:32", "refsForCommit:" : "mad 9/11/2023 16:54", "refsForCommits" : "mad 9/11/2023 16:36", "refsForCommits:" : "mad 9/11/2023 16:36",