From a7fe74504bcc61a6e1499982040add8d25211b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Thu, 5 Mar 2020 18:20:27 +0100 Subject: [PATCH] update extgitgraph --- www/extern/egg/EGGDatabase.php | 28 ++++++++++++++++++++++++---- www/extern/egg/Logger.php | 2 -- www/extern/egg/RemoteSource.php | 8 ++++++++ www/extern/egg/db_init.sql | 24 +++++++++++++++++++++++- www/extern/egg/db_queryyear.sql | 7 ++++--- 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/www/extern/egg/EGGDatabase.php b/www/extern/egg/EGGDatabase.php index 81e0185..a05d7fd 100644 --- a/www/extern/egg/EGGDatabase.php +++ b/www/extern/egg/EGGDatabase.php @@ -6,6 +6,8 @@ require_once 'Utils.php'; class EGGDatabase { + const DB_NAME = ""; + /** @var string */ private $path; @@ -67,7 +69,9 @@ class EGGDatabase public function sql_query_assoc(string $query) { - return $this->pdo->query($query)->fetchAll(PDO::FETCH_ASSOC); + $r = $this->pdo->query($query)->fetchAll(PDO::FETCH_ASSOC); + + return $r; } public function sql_query_assoc_prep(string $query, array $params) @@ -80,7 +84,9 @@ class EGGDatabase } $stmt->execute(); - return $stmt->fetchAll(PDO::FETCH_ASSOC); + $r = $stmt->fetchAll(PDO::FETCH_ASSOC); + + return $r; } public function sql_exec_prep(string $query, array $params) @@ -202,10 +208,15 @@ class EGGDatabase { $strparents = implode(";", $commit->Parents); - $this->sql_exec_prep("INSERT INTO commits ([branch_id], [hash], [author_name], [author_email], [committer_name], [committer_email], [message], [date], [parent_commits]) VALUES (:brid, :sha, :an, :am, :cn, :cm, :msg, :dat, :prt)", + $this->sql_exec_prep("INSERT INTO commits ([branch_id], [hash]) VALUES (:brid, :sha)", [ [":brid", $branch->ID, PDO::PARAM_INT], [":sha", $commit->Hash, PDO::PARAM_STR], + ]); + + $this->sql_exec_prep("INSERT OR IGNORE INTO metadata ([hash], [author_name], [author_email], [committer_name], [committer_email], [message], [date], [parent_commits]) VALUES (:sha, :an, :am, :cn, :cm, :msg, :dat, :prt)", + [ + [":sha", $commit->Hash, PDO::PARAM_STR], [":an", $commit->AuthorName, PDO::PARAM_STR], [":am", $commit->AuthorEmail, PDO::PARAM_STR], [":cn", $commit->CommitterName, PDO::PARAM_STR], @@ -320,6 +331,15 @@ class EGGDatabase } } + public function deleteDanglingCommitdata(string $name) + { + $db = $this->sql_query_assoc_prep("SELECT metadata.hash FROM metadata LEFT JOIN commits WHERE commits.hash IS NULL", []); + + if (count($db) === 0) return; + + $this->logger->proclog("Delete ".count($db)." dangling commits [" . $name . "] from database (no longer linked)"); + } + /** * @param string $source * @param string $name @@ -416,7 +436,7 @@ class EGGDatabase */ public function getAllYears(): array { - $rows = $this->sql_query_assoc("SELECT d FROM (SELECT cast(strftime('%Y', commits.date) as decimal) AS d FROM commits) GROUP BY d ORDER BY d"); + $rows = $this->sql_query_assoc("SELECT d FROM (SELECT cast(strftime('%Y', metadata.date) as decimal) AS d FROM commits LEFT JOIN metadata ON commits.hash = metadata.hash) GROUP BY d ORDER BY d"); $r = []; foreach ($rows as $row) $r []= $row['d']; return $r; diff --git a/www/extern/egg/Logger.php b/www/extern/egg/Logger.php index 4b766a2..2b21b92 100644 --- a/www/extern/egg/Logger.php +++ b/www/extern/egg/Logger.php @@ -84,8 +84,6 @@ class SessionLogger implements ILogger { if (session_status() === PHP_SESSION_DISABLED) return; - if (session_status() !== PHP_SESSION_ACTIVE) session_start(); - if (session_status() !== PHP_SESSION_ACTIVE) session_start(); $_SESSION[$this->sessionvar] .= $text . "\r\n"; session_commit(); } diff --git a/www/extern/egg/RemoteSource.php b/www/extern/egg/RemoteSource.php index bc9dbf6..f5b9868 100644 --- a/www/extern/egg/RemoteSource.php +++ b/www/extern/egg/RemoteSource.php @@ -53,6 +53,8 @@ abstract class StandardGitConnection implements IRemoteSource $repos = $this->listAndUpdateRepositories($db); + $anyChanged = false; + foreach ($repos as $repo) { $branches = $this->listAndUpdateBranches($db, $repo); @@ -83,6 +85,12 @@ abstract class StandardGitConnection implements IRemoteSource } if ($repo_changed) $db->setChangeDateOnRepository($repo); + if ($repo_changed) $anyChanged = true; + } + + if ($anyChanged) + { + $db->deleteDanglingCommitdata($this->name); } $this->postUpdate(); diff --git a/www/extern/egg/db_init.sql b/www/extern/egg/db_init.sql index 839755b..3add702 100644 --- a/www/extern/egg/db_init.sql +++ b/www/extern/egg/db_init.sql @@ -26,7 +26,14 @@ CREATE TABLE "commits" ( "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, "branch_id" INTEGER NOT NULL, - "hash" TEXT NOT NULL, + "hash" TEXT NOT NULL +); + +/*----SPLIT----*/ + +CREATE TABLE "metadata" +( + "hash" TEXT NOT NULL PRIMARY KEY UNIQUE, "author_name" TEXT NOT NULL, "author_email" TEXT NOT NULL, "committer_name" TEXT NOT NULL, @@ -35,3 +42,18 @@ CREATE TABLE "commits" "date" TEXT NOT NULL, "parent_commits" TEXT NOT NULL ); + +/*----SPLIT----*/ + +CREATE VIEW alldata AS + SELECT + metadata.[date], commits.hash, + metadata.author_name, metadata.author_email, metadata.committer_name, metadata.committer_email, metadata.message, metadata.parent_commits, + repositories.source, repositories.name AS repository, + branches.name AS branch, + repositories.url, + repositories.last_update, repositories.last_change + FROM commits + LEFT JOIN metadata ON commits.hash = metadata.hash + LEFT JOIN branches ON commits.branch_id = branches.id + LEFT JOIN repositories ON branches.repo_id = repositories.id \ No newline at end of file diff --git a/www/extern/egg/db_queryyear.sql b/www/extern/egg/db_queryyear.sql index 5d1c04c..9b58f2a 100644 --- a/www/extern/egg/db_queryyear.sql +++ b/www/extern/egg/db_queryyear.sql @@ -1,9 +1,10 @@ SELECT commitdate AS commitdate, COUNT(*) as count FROM ( SELECT - [hash] AS hash, min([author_email]) AS mail1, min([committer_email]) AS mail2, date(min([date])) AS commitdate - FROM COMMITS - GROUP BY hash + commits.[hash] AS hash, min([author_email]) AS mail1, min([committer_email]) AS mail2, date(min([date])) AS commitdate + FROM commits + LEFT JOIN metadata ON commits.hash = metadata.hash + GROUP BY commits.[hash] HAVING (strftime('%Y', commitdate) = :year AND (/*{INDETITY_COND}*/)) ) GROUP BY commitdate