File tree Expand file tree Collapse file tree 2 files changed +8
-18
lines changed Expand file tree Collapse file tree 2 files changed +8
-18
lines changed Original file line number Diff line number Diff line change @@ -422,30 +422,19 @@ public function getDiff($revisions)
422
422
/**
423
423
* Returns the size of repository, in kilobytes.
424
424
*
425
- * @throws RuntimeException An error occurred while computing size
426
- *
427
425
* @return int A sum, in kilobytes
428
426
*/
429
427
public function getSize ()
430
428
{
431
- $ process = new Process (['du ' , '-skc ' , $ this ->gitDir ]);
432
- $ process ->run ();
433
-
434
- if (!preg_match ('/(\d+)\s+total$/ ' , trim ($ process ->getOutput ()), $ vars )) {
435
- $ message = sprintf ("Unable to parse process output \ncommand: %s \noutput: %s " , $ process ->getCommandLine (), $ process ->getOutput ());
436
-
437
- if (null !== $ this ->logger ) {
438
- $ this ->logger ->error ($ message );
429
+ $ totalBytes = 0 ;
430
+ $ path = realpath ($ this ->gitDir );
431
+ if ($ path && file_exists ($ path )) {
432
+ foreach (new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ path , \FilesystemIterator::SKIP_DOTS )) as $ object ) {
433
+ $ totalBytes += $ object ->getSize ();
439
434
}
440
-
441
- if (true === $ this ->debug ) {
442
- throw new RuntimeException ('unable to parse repository size output ' );
443
- }
444
-
445
- return ;
446
435
}
447
436
448
- return $ vars [ 1 ] ;
437
+ return ( int ) ( $ totalBytes / 1000 + 0.5 ) ;
449
438
}
450
439
451
440
/**
Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ public function testGetBlob_WithExisting_Works($repository)
35
35
public function testGetSize ($ repository )
36
36
{
37
37
$ size = $ repository ->getSize ();
38
- $ this ->assertGreaterThan (70 , $ size , 'Repository is greater than 70KB ' );
38
+ $ this ->assertGreaterThanOrEqual (69 , $ size , 'Repository is at least 69KB ' );
39
+ $ this ->assertLessThan (80 , $ size , 'Repository is less than 80KB ' );
39
40
}
40
41
41
42
public function testIsBare ()
You can’t perform that action at this time.
0 commit comments