From 40a0d685d578c360d245e98c8ca217953b8b765a Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Sat, 16 Sep 2006 20:29:55 +0200
Subject: [PATCH] better getVersion when working on a darcs tree

getVersion tries to find the date of the latest applied patch from
_darcs/inventory - this patch makes it only read the last 2000 byte
of the file instead of loading the whole file.

darcs-hash:20060916182955-7ad00-5a38de1ae4f1a206a8f62cc88551d4f0bc35340e.gz
---
 inc/common.php | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/inc/common.php b/inc/common.php
index 5372a17d7..016c7922d 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -979,9 +979,14 @@ function getVersion(){
     //official release
     return 'Release '.trim(io_readfile(DOKU_INC.'/VERSION'));
   }elseif(is_dir('_darcs')){
-    //darcs checkout
-    $inv = file('_darcs/inventory');
-    $inv = preg_grep('#\*\*\d{14}[\]$]#',$inv);
+    //darcs checkout - read last 2000 bytes of inventory
+    $sz   = filesize('_darcs/inventory');
+    $seek = max(0,$sz-2000);
+    $fh   = fopen('_darcs/inventory','rb');
+    fseek($fh,$seek);
+    $chunk = fread($fh,2000);
+    fclose($fh);
+    $inv = preg_grep('#\*\*\d{14}[\]$]#',explode("\n",$chunk));
     $cur = array_pop($inv);
     preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches);
     return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3];
-- 
GitLab