From a0c305ec1b70c0d5a8aad8a1d3b2477bc3a15bbe Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 27 Jul 2018 09:31:58 +0200 Subject: git_url() new --- buildmaster/build-list.php | 16 +++++----- buildmaster/todos.php | 6 +++- lib/helper.php | 74 +++++++++++++++++++++++++++++++++++++++++++++- packages/pkginfo.php | 13 ++++---- 4 files changed, 92 insertions(+), 17 deletions(-) diff --git a/buildmaster/build-list.php b/buildmaster/build-list.php index 1b4466f..2ff9b92 100644 --- a/buildmaster/build-list.php +++ b/buildmaster/build-list.php @@ -1,6 +1,7 @@ "IF(`ba_q`.`uses_modification`," . "CONCAT(" . - "\"\"," . + "\"\"," . "`ba_q`.`mod_git_revision`," . "\"\"" . ")," . diff --git a/buildmaster/todos.php b/buildmaster/todos.php index e3d7319..bf77f08 100644 --- a/buildmaster/todos.php +++ b/buildmaster/todos.php @@ -1,5 +1,7 @@ fetch_assoc()) { print "TODO #" . $row["id"] . ""; print " - "; - print "" . $row["file"] . "(line " . $row["line"] . ")"; + print "" . $row["file"] . "(line " . $row["line"] . ")"; print ":
\n"; print str_replace("\\n","
\n",$row["description"]); print "
\n"; diff --git a/lib/helper.php b/lib/helper.php index 41951c7..732b52a 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -83,4 +83,76 @@ function format_time_duration($val) { $result ); return $result; -} +}; + +function git_url($repository,$type,$commit,$path,$line = null,$commit_is_hash = null) { + global $git_available; + # TODO: we might want to cache this value (with memcached ?) + if (!isset($git_available)) { + $git_available = + preg_match( + "/ 200 OK$/", + get_headers("https://git.archlinux32.org/archlinux32/packagess")[0] + ) == 1; + } + if (!isset($commit_is_hash)) + $commit_is_hash = preg_match("/^[0-9a-f]{40}$/",$commit)==1; + if ($git_available) { + if (isset($line)) + $line = "#L" . $line; + else + $line = ""; + if ($commit_is_hash) + $commit = "commit/" . $commit; + else + $commit = "branch/" . $commit; + switch ($type) { + case "tree": + return + "https://git.archlinux32.org/archlinux32/" . + $repository . + "/src/" . + $commit . + "/" . + $path . + $line; + case "log": + return + "https://git.archlinux32.org/archlinux32/" . + $repository . + "/commits/" . + $commit . + "/" . + $path . + $line; + } + + } else { + if (isset($line)) + $line = "#n" . $line; + else + $line = ""; + if ($commit_is_hash) + $commit = "?id=" . $commit; + else + $commit = "?h=" . $commit; + switch ($type) { + case "tree": + return + "https://git2.archlinux32.org/Archlinux32/" . + $repository . + "/tree/" . + $path . + $commit . + $line; + case "log": + return + "https://git2.archlinux32.org/Archlinux32/" . + $repository . + "/log/" . + $path . + $commit . + $line; + } + }; +}; diff --git a/packages/pkginfo.php b/packages/pkginfo.php index b910266..3fa1e77 100644 --- a/packages/pkginfo.php +++ b/packages/pkginfo.php @@ -1,6 +1,7 @@ \n"; - print " Archlinux32's Source Files /\n"; - print " Archlinux32's Changes\n"; -- cgit v1.2.3