diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cf1407..c62ae5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - When there was a cache miss, then explain why (absent, invalidated, expired) during verbose output. - Queue SVN-Buddy new repository commit discovery, after a new commit in SVN-Buddy was made. - The `log` and `merge` commands no longer fails with large (>999) revision lists on SQLite <= 3.32.0. +- The deletion of project wasn't deleting its refs (branches/tags) resulting them to reported as existing. ## [0.7.0] - 2024-04-12 ### Added diff --git a/migrations/20241019_1708_propagate_path_revision_deleted.php b/migrations/20241019_1708_propagate_path_revision_deleted.php new file mode 100644 index 0000000..6e5166e --- /dev/null +++ b/migrations/20241019_1708_propagate_path_revision_deleted.php @@ -0,0 +1,22 @@ +getDatabase(); + + $sql = 'SELECT Path, RevisionDeleted + FROM Paths + WHERE Path LIKE "%/" AND RevisionDeleted IS NOT NULL'; + $deleted_paths = $db->fetchPairs($sql); + + if ( !$deleted_paths ) { + return; + } + + foreach ( $deleted_paths as $path => $revision ) { + $sql = 'UPDATE Paths + SET RevisionDeleted = :revision + WHERE Path LIKE :path AND RevisionDeleted IS NULL'; + $db->perform($sql, array('revision' => $revision, 'path' => $path . '%')); + } +}; diff --git a/src/SVNBuddy/Repository/RevisionLog/RepositoryFiller.php b/src/SVNBuddy/Repository/RevisionLog/RepositoryFiller.php index 5850c49..d1dbce5 100644 --- a/src/SVNBuddy/Repository/RevisionLog/RepositoryFiller.php +++ b/src/SVNBuddy/Repository/RevisionLog/RepositoryFiller.php @@ -239,6 +239,14 @@ public function touchPath($path, $revision, array $fields_hash) throw new \InvalidArgumentException('The "$fields_hash" variable can\'t be empty.'); } + // This is $revision, where $path was deleted. + if ( array_key_exists('RevisionDeleted', $fields_hash) + && $fields_hash['RevisionDeleted'] !== null + && substr($path, -1) === '/' + ) { + $this->propagateRevisionDeleted($path, $fields_hash['RevisionDeleted']); + } + $path_hash = $this->getPathChecksum($path); $to_update = $this->propagateRevisionLastSeen($path, $revision); $to_update[$path_hash] = $fields_hash; @@ -255,7 +263,7 @@ public function touchPath($path, $revision, array $fields_hash) } /** - * Propagates revision last seen. + * Propagates revision last seen upwards in path hierarchy. * * @param string $path Path. * @param string $revision Revision. @@ -306,6 +314,22 @@ protected function propagateRevisionLastSeen($path, $revision) return $to_update; } + /** + * Propagates revision deleted downwards in path hierarchy. + * + * @param string $path Path. + * @param string $revision Revision. + * + * @return void + */ + protected function propagateRevisionDeleted($path, $revision) + { + $sql = 'UPDATE Paths + SET RevisionDeleted = :revision + WHERE Path LIKE :path AND RevisionDeleted IS NULL'; + $this->database->perform($sql, array('revision' => $revision, 'path' => $path . '%')); + } + /** * Returns fields, that needs to be changed for given path. * diff --git a/tests/SVNBuddy/Repository/RevisionLog/Plugin/PathsPluginTest.php b/tests/SVNBuddy/Repository/RevisionLog/Plugin/PathsPluginTest.php index 7b2bfb0..a86e5d3 100644 --- a/tests/SVNBuddy/Repository/RevisionLog/Plugin/PathsPluginTest.php +++ b/tests/SVNBuddy/Repository/RevisionLog/Plugin/PathsPluginTest.php @@ -1326,6 +1326,85 @@ public function testParsePathSorting() ); } + public function testParsePathRemovalPropagated() + { + $this->repositoryConnector->getRefByPath(Argument::any())->willReturn(false)->shouldBeCalled(); + + $this->plugin->parse($this->getFixture('svn_log_path_deleted_propagate.xml')); + + $this->assertTableContent( + 'Paths', + array( + array( + 'Id' => '1', + 'Path' => '/path/', + 'PathNestingLevel' => '1', + 'PathHash' => '1753053843', + 'RefName' => '', + 'ProjectPath' => '', + 'RevisionAdded' => '50', + 'RevisionDeleted' => null, + 'RevisionLastSeen' => '200', + ), + array( + 'Id' => '2', + 'Path' => '/path/folder_a/', + 'PathNestingLevel' => '2', + 'PathHash' => '2557174829', + 'RefName' => '', + 'ProjectPath' => '', + 'RevisionAdded' => '60', + 'RevisionDeleted' => '200', + 'RevisionLastSeen' => '100', + ), + array( + 'Id' => '3', + 'Path' => '/path/folder_a/file_a.txt', + 'PathNestingLevel' => '2', + 'PathHash' => '2179111923', + 'RefName' => '', + 'ProjectPath' => '', + 'RevisionAdded' => '60', + 'RevisionDeleted' => '100', + 'RevisionLastSeen' => '60', + ), + array( + 'Id' => '4', + 'Path' => '/path/folder_a/sub_folder_a/', + 'PathNestingLevel' => '3', + 'PathHash' => '1400457329', + 'RefName' => '', + 'ProjectPath' => '', + 'RevisionAdded' => '60', + 'RevisionDeleted' => '200', + 'RevisionLastSeen' => '70', + ), + array( + 'Id' => '5', + 'Path' => '/path/folder_b/', + 'PathNestingLevel' => '2', + 'PathHash' => '3007723502', + 'RefName' => '', + 'ProjectPath' => '', + 'RevisionAdded' => '60', + 'RevisionDeleted' => null, + 'RevisionLastSeen' => '60', + ), + array( + 'Id' => '6', + 'Path' => '/path/folder_a/sub_folder_a/sub_file_a.txt', + 'PathNestingLevel' => '3', + 'PathHash' => '2415052021', + 'RefName' => '', + 'ProjectPath' => '', + 'RevisionAdded' => '70', + 'RevisionDeleted' => '200', + 'RevisionLastSeen' => '70', + ), + ) + ); + } + public function testFindNoMatch() { $this->commitBuilder diff --git a/tests/SVNBuddy/Repository/RevisionLog/Plugin/fixtures/paths/svn_log_path_deleted_propagate.xml b/tests/SVNBuddy/Repository/RevisionLog/Plugin/fixtures/paths/svn_log_path_deleted_propagate.xml new file mode 100644 index 0000000..3a6fd86 --- /dev/null +++ b/tests/SVNBuddy/Repository/RevisionLog/Plugin/fixtures/paths/svn_log_path_deleted_propagate.xml @@ -0,0 +1,46 @@ + + + + user + 2015-10-13T13:30:16.473960Z + + /path + + message + + + user + 2015-10-13T13:30:16.473960Z + + /path/folder_a + /path/folder_a/file_a.txt + /path/folder_a/sub_folder_a + /path/folder_b + + message + + + user + 2015-10-13T13:30:16.473960Z + + /path/folder_a/sub_folder_a/sub_file_a.txt + + message + + + user + 2015-10-13T13:30:16.473960Z + + /path/folder_a/file_a.txt + + message + + + user + 2015-10-13T13:30:16.473960Z + + /path/folder_a + + message + +