Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 make getVersion() show the commit date, not checkout date #2443

Open
wants to merge 4 commits into
base: master
from
Open
Diff settings

Always

Just for now

Copy path View file
@@ -74,21 +74,27 @@ function getVersionData(){
$version['type'] = 'Git';
$version['date'] = 'unknown';
$inventory = DOKU_INC.'.git/logs/HEAD';
if(is_file($inventory)){
$sz = filesize($inventory);
$seek = max(0,$sz-2000); // read from back of the file
$fh = fopen($inventory,'rb');
fseek($fh,$seek);
$chunk = fread($fh,2000);
fclose($fh);
$chunk = trim($chunk);
$chunk = @array_pop(explode("\n",$chunk)); //last log line
$chunk = @array_shift(explode("\t",$chunk)); //strip commit msg
$chunk = explode(" ",$chunk);
array_pop($chunk); //strip timezone
$date = date('Y-m-d',array_pop($chunk));
if($date) $version['date'] = $date;
if ($date = shell_exec("git log -1 --pretty=format:'%cd' --date=short")) {
$version['date'] = hsc($date);

This comment has been minimized.

Copy link
@splitbrain

splitbrain Sep 7, 2018

Owner

can we skip the shell access completely and always do it manually?

This comment has been minimized.

Copy link
@micgro42

micgro42 Sep 9, 2018

Author Collaborator

No, because manual may not reliably work either. Git tends to pack objects to save space locally and I'm not sure how to get that specific commit out of such a pack without git itself.

} else if (file_exists(DOKU_INC . '.git/HEAD')) {
// we cannot use git on the shell -- let's do it manually!
$headCommit = trim(file_get_contents(DOKU_INC . '.git/HEAD'));
if (strpos($headCommit, 'ref: ') === 0) {
// it is something like `ref: refs/heads/master`
$pathToHead = substr($headCommit, 5);
$headCommit = trim(file_get_contents(DOKU_INC . '.git/' . $pathToHead));
}
$subDir = substr($headCommit, 0, 2);
$fileName = substr($headCommit, 2);
$gitCommitObject = DOKU_INC . ".git/objects/$subDir/$fileName";
$commit = zlib_decode(file_get_contents($gitCommitObject));

This comment has been minimized.

Copy link
@splitbrain

splitbrain Sep 7, 2018

Owner

zlib may not be available, we need to return an unknown date then

$committerLine = explode("\n", $commit)[3];
$committerData = explode(' ', $committerLine);
end($committerData);
$ts = prev($committerData);
if ($ts && $date = date('Y-m-d', $ts)) {
$version['date'] = $date;
}
}
}else{
global $updateVersion;
ProTip! Use n and p to navigate between commits in a pull request.
You can鈥檛 perform that action at this time.