diff --git a/www/extern/egg/EGGDatabase.php b/www/extern/egg/EGGDatabase.php index 87574d7..34b4a53 100644 --- a/www/extern/egg/EGGDatabase.php +++ b/www/extern/egg/EGGDatabase.php @@ -461,4 +461,29 @@ class EGGDatabase foreach ($rows as $row) $r []= $row['d']; return $r; } + + /** + * @return Commit[] + */ + public function getCommits(Branch $branch): array + { + $rows = $this->sql_query_assoc("SELECT metadata.*, commits.id AS commitid FROM commits LEFT JOIN metadata WHERE commits.branch_id = :bid", [[":bid", $branch->ID, PDO::PARAM_INT]]); + $r = []; + foreach ($rows as $row) + { + $c = new Commit(); + $c->ID = $row['commitid']; + $c->Branch = $branch; + $c->Hash = $row['hash']; + $c->AuthorName = $row['author_name']; + $c->AuthorEmail = $row['author_email']; + $c->CommitterName = $row['committer_name']; + $c->CommitterEmail = $row['committer_email']; + $c->Message = $row['message']; + $c->Date = $row['date']; + $c->Parents = $row['parent_commits']; + $r []= $c; + } + return $r; + } } \ No newline at end of file diff --git a/www/extern/egg/RemoteSource.php b/www/extern/egg/RemoteSource.php index ca519ff..2ff9f19 100644 --- a/www/extern/egg/RemoteSource.php +++ b/www/extern/egg/RemoteSource.php @@ -233,9 +233,10 @@ abstract class StandardGitConnection implements IRemoteSource if ($branch->HeadFromAPI === null) return []; $target = $branch->Head; + $targetFound = false; $next_sha = [ $branch->HeadFromAPI ]; - $visited = [ ]; + $visited = array_map(function(Commit $m):string{return $m->Hash;}, $db->getCommits($branch)); $json = $this->queryCommits($repo->Name, $branch->Name, $next_sha[0]); @@ -260,18 +261,24 @@ abstract class StandardGitConnection implements IRemoteSource if (in_array($sha, $visited)) continue; $visited []= $sha; - if ($sha === $target && count($next_sha) === 0) + if ($sha === $target) $targetFound = true; + + if ($targetFound && count($next_sha) === 0) { if (count($newcommits) === 0) { $this->logger->proclog("Found no new commits for: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] (HEAD at {" . substr($branch->HeadFromAPI, 0, 8) . "})"); return []; } + else + { + $this->logger->proclog("Added " . count($newcommits) . " new commits for: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] (HEAD moved from {" . substr($branch->Head, 0, 8) . "} to {" . substr($branch->HeadFromAPI, 0, 8) . "})"); - $db->insertNewCommits($this->name, $repo, $branch, $newcommits); - $db->setBranchHead($branch, $branch->HeadFromAPI); + $db->insertNewCommits($this->name, $repo, $branch, $newcommits); + $db->setBranchHead($branch, $branch->HeadFromAPI); - return $newcommits; + return $newcommits; + } } $commit = new Commit(); @@ -299,7 +306,7 @@ abstract class StandardGitConnection implements IRemoteSource $json = $this->queryCommits($repo->Name, $branch->Name, $next_sha[0]); } - $this->logger->proclog("HEAD pointer in Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] no longer matches. Re-query all " . count($newcommits) . " commits (old HEAD := {".substr($branch->Head, 0, 8)."})"); + $this->logger->proclog("HEAD pointer in Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] no longer matches. Re-query all " . count($newcommits) . " commits (old HEAD := {".substr($branch->Head, 0, 8)."}, missing: [" . join(", ", array_map(function($p){return substr($p, 0, 8);}, $next_sha)) . "] )"); $db->deleteAllCommits($branch); diff --git a/www/extern/egg/db_init.sql b/www/extern/egg/db_init.sql index 3add702..7fe07d0 100644 --- a/www/extern/egg/db_init.sql +++ b/www/extern/egg/db_init.sql @@ -56,4 +56,17 @@ CREATE VIEW alldata AS 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 + LEFT JOIN repositories ON branches.repo_id = repositories.id; + +/*----SPLIT----*/ + +CREATE VIEW allbranches AS + SELECT + repositories.source, repositories.name AS repository, + branches.name AS branch, + repositories.url, + repositories.last_update, repositories.last_change, + (SELECT COUNT(*) FROM commits WHERE branch_id = branches.id) AS commit_count + FROM branches + LEFT JOIN repositories ON branches.repo_id = repositories.id; +