Skip to content

Commit 06984a3

Browse files
authored
Merge pull request #160 from aik099/path-removal-propagation-fix
Corrected refs removal upon project removal
2 parents 12cab7d + 6f300ee commit 06984a3

File tree

5 files changed

+173
-1
lines changed

5 files changed

+173
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2727
- When there was a cache miss, then explain why (absent, invalidated, expired) during verbose output.
2828
- Queue SVN-Buddy new repository commit discovery, after a new commit in SVN-Buddy was made.
2929
- The `log` and `merge` commands no longer fails with large (>999) revision lists on SQLite <= 3.32.0.
30+
- The deletion of project wasn't deleting its refs (branches/tags) resulting them to reported as existing.
3031

3132
## [0.7.0] - 2024-04-12
3233
### Added
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
use ConsoleHelpers\DatabaseMigration\MigrationContext;
3+
4+
return function (MigrationContext $context) {
5+
$db = $context->getDatabase();
6+
7+
$sql = 'SELECT Path, RevisionDeleted
8+
FROM Paths
9+
WHERE Path LIKE "%/" AND RevisionDeleted IS NOT NULL';
10+
$deleted_paths = $db->fetchPairs($sql);
11+
12+
if ( !$deleted_paths ) {
13+
return;
14+
}
15+
16+
foreach ( $deleted_paths as $path => $revision ) {
17+
$sql = 'UPDATE Paths
18+
SET RevisionDeleted = :revision
19+
WHERE Path LIKE :path AND RevisionDeleted IS NULL';
20+
$db->perform($sql, array('revision' => $revision, 'path' => $path . '%'));
21+
}
22+
};

src/SVNBuddy/Repository/RevisionLog/RepositoryFiller.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ public function touchPath($path, $revision, array $fields_hash)
239239
throw new \InvalidArgumentException('The "$fields_hash" variable can\'t be empty.');
240240
}
241241

242+
// This is $revision, where $path was deleted.
243+
if ( array_key_exists('RevisionDeleted', $fields_hash)
244+
&& $fields_hash['RevisionDeleted'] !== null
245+
&& substr($path, -1) === '/'
246+
) {
247+
$this->propagateRevisionDeleted($path, $fields_hash['RevisionDeleted']);
248+
}
249+
242250
$path_hash = $this->getPathChecksum($path);
243251
$to_update = $this->propagateRevisionLastSeen($path, $revision);
244252
$to_update[$path_hash] = $fields_hash;
@@ -255,7 +263,7 @@ public function touchPath($path, $revision, array $fields_hash)
255263
}
256264

257265
/**
258-
* Propagates revision last seen.
266+
* Propagates revision last seen upwards in path hierarchy.
259267
*
260268
* @param string $path Path.
261269
* @param string $revision Revision.
@@ -306,6 +314,22 @@ protected function propagateRevisionLastSeen($path, $revision)
306314
return $to_update;
307315
}
308316

317+
/**
318+
* Propagates revision deleted downwards in path hierarchy.
319+
*
320+
* @param string $path Path.
321+
* @param string $revision Revision.
322+
*
323+
* @return void
324+
*/
325+
protected function propagateRevisionDeleted($path, $revision)
326+
{
327+
$sql = 'UPDATE Paths
328+
SET RevisionDeleted = :revision
329+
WHERE Path LIKE :path AND RevisionDeleted IS NULL';
330+
$this->database->perform($sql, array('revision' => $revision, 'path' => $path . '%'));
331+
}
332+
309333
/**
310334
* Returns fields, that needs to be changed for given path.
311335
*

tests/SVNBuddy/Repository/RevisionLog/Plugin/PathsPluginTest.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,85 @@ public function testParsePathSorting()
13261326
);
13271327
}
13281328

1329+
public function testParsePathRemovalPropagated()
1330+
{
1331+
$this->repositoryConnector->getRefByPath(Argument::any())->willReturn(false)->shouldBeCalled();
1332+
1333+
$this->plugin->parse($this->getFixture('svn_log_path_deleted_propagate.xml'));
1334+
1335+
$this->assertTableContent(
1336+
'Paths',
1337+
array(
1338+
array(
1339+
'Id' => '1',
1340+
'Path' => '/path/',
1341+
'PathNestingLevel' => '1',
1342+
'PathHash' => '1753053843',
1343+
'RefName' => '',
1344+
'ProjectPath' => '',
1345+
'RevisionAdded' => '50',
1346+
'RevisionDeleted' => null,
1347+
'RevisionLastSeen' => '200',
1348+
),
1349+
array(
1350+
'Id' => '2',
1351+
'Path' => '/path/folder_a/',
1352+
'PathNestingLevel' => '2',
1353+
'PathHash' => '2557174829',
1354+
'RefName' => '',
1355+
'ProjectPath' => '',
1356+
'RevisionAdded' => '60',
1357+
'RevisionDeleted' => '200',
1358+
'RevisionLastSeen' => '100',
1359+
),
1360+
array(
1361+
'Id' => '3',
1362+
'Path' => '/path/folder_a/file_a.txt',
1363+
'PathNestingLevel' => '2',
1364+
'PathHash' => '2179111923',
1365+
'RefName' => '',
1366+
'ProjectPath' => '',
1367+
'RevisionAdded' => '60',
1368+
'RevisionDeleted' => '100',
1369+
'RevisionLastSeen' => '60',
1370+
),
1371+
array(
1372+
'Id' => '4',
1373+
'Path' => '/path/folder_a/sub_folder_a/',
1374+
'PathNestingLevel' => '3',
1375+
'PathHash' => '1400457329',
1376+
'RefName' => '',
1377+
'ProjectPath' => '',
1378+
'RevisionAdded' => '60',
1379+
'RevisionDeleted' => '200',
1380+
'RevisionLastSeen' => '70',
1381+
),
1382+
array(
1383+
'Id' => '5',
1384+
'Path' => '/path/folder_b/',
1385+
'PathNestingLevel' => '2',
1386+
'PathHash' => '3007723502',
1387+
'RefName' => '',
1388+
'ProjectPath' => '',
1389+
'RevisionAdded' => '60',
1390+
'RevisionDeleted' => null,
1391+
'RevisionLastSeen' => '60',
1392+
),
1393+
array(
1394+
'Id' => '6',
1395+
'Path' => '/path/folder_a/sub_folder_a/sub_file_a.txt',
1396+
'PathNestingLevel' => '3',
1397+
'PathHash' => '2415052021',
1398+
'RefName' => '',
1399+
'ProjectPath' => '',
1400+
'RevisionAdded' => '70',
1401+
'RevisionDeleted' => '200',
1402+
'RevisionLastSeen' => '70',
1403+
),
1404+
)
1405+
);
1406+
}
1407+
13291408
public function testFindNoMatch()
13301409
{
13311410
$this->commitBuilder
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0"?>
2+
<log>
3+
<logentry revision="50">
4+
<author>user</author>
5+
<date>2015-10-13T13:30:16.473960Z</date>
6+
<paths>
7+
<path action="A" kind="dir">/path</path>
8+
</paths>
9+
<msg>message</msg>
10+
</logentry>
11+
<logentry revision="60">
12+
<author>user</author>
13+
<date>2015-10-13T13:30:16.473960Z</date>
14+
<paths>
15+
<path action="A" kind="dir">/path/folder_a</path>
16+
<path action="A" kind="file">/path/folder_a/file_a.txt</path>
17+
<path action="A" kind="dir">/path/folder_a/sub_folder_a</path>
18+
<path action="A" kind="dir">/path/folder_b</path>
19+
</paths>
20+
<msg>message</msg>
21+
</logentry>
22+
<logentry revision="70">
23+
<author>user</author>
24+
<date>2015-10-13T13:30:16.473960Z</date>
25+
<paths>
26+
<path action="A" kind="file">/path/folder_a/sub_folder_a/sub_file_a.txt</path>
27+
</paths>
28+
<msg>message</msg>
29+
</logentry>
30+
<logentry revision="100">
31+
<author>user</author>
32+
<date>2015-10-13T13:30:16.473960Z</date>
33+
<paths>
34+
<path action="D" kind="file">/path/folder_a/file_a.txt</path>
35+
</paths>
36+
<msg>message</msg>
37+
</logentry>
38+
<logentry revision="200">
39+
<author>user</author>
40+
<date>2015-10-13T13:30:16.473960Z</date>
41+
<paths>
42+
<path action="D" kind="dir">/path/folder_a</path>
43+
</paths>
44+
<msg>message</msg>
45+
</logentry>
46+
</log>

0 commit comments

Comments
 (0)