[aur-dev] [PATCH] Group package dependencies by their type
Sort dependencies by type, implements feature request in FS#40888 Dependencies are fetched like before and a sort is applied on dependencies type if $deps array is not empty. Display is adjusted accordingly. diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 7f01d2f..0d1824e 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -26,8 +26,19 @@ $urlpath = URL_DIR . substr($row['BaseName'], 0, 2) . "/" . $row['BaseName']; $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); -$deps = pkg_dependencies($row["ID"]); $requiredby = pkg_required($row["Name"]); +$deps = pkg_dependencies($row["ID"]); +if (count($deps) > 0) { + + // extract dependencies + $dep_types = array_map(function ($a) { return $a[1]; }, $deps); + asort($dep_types); + // reconstruct deps array using the new order + $sorted_deps = Array(); + foreach(array_keys($dep_types) as $t) { + $sorted_deps[] = $deps[$t]; + } +} $rels = pkg_relations($row["ID"]); $rels_c = $rels_p = $rels_r = array(); @@ -333,7 +344,7 @@ if ($row["PackagerUID"]): <h3><?= __('Dependencies') . " (" . count($deps) . ")"?></h3> <?php if (count($deps) > 0): ?> <ul id="pkgdepslist"> -<?php while (list($k, $darr) = each($deps)): ?> +<?php while (list($k, $darr) = each($sorted_deps)): ?> <li><?= pkg_depend_link($darr[0], $darr[1], $darr[2], $darr[3]); ?></li> <?php endwhile; ?> </ul> -- Mathieu (matael) Gaborit mat.gaborit@gmx.com Merci de ne m'imprimer que si nécessaire Please don't print this unless it's necessary
On Sat, 09 Aug 2014 at 21:28:03, Mathieu Gaborit wrote:
Sort dependencies by type, implements feature request in FS#40888
Dependencies are fetched like before and a sort is applied on dependencies type if $deps array is not empty. Display is adjusted accordingly. [...]
I like the suggestions but the implementation has some flaws. For example, checkdepends appear before (regular) dependencies and packages with the same dependency type are not sorted alphabetically (note that PHP's sort functions are not stable). How about the following patch? -- >8 -- web/template/pkg_details.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 7f01d2f..8a3cbcc 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -29,6 +29,16 @@ $grps = pkg_groups($row["ID"]); $deps = pkg_dependencies($row["ID"]); $requiredby = pkg_required($row["Name"]); +usort($deps, function($x, $y) { + if ($x[1] == "depends" && $y[1] != "depends") { + return -1; + } + if ($y[1] == "depends" && $x[1] != "depends") { + return 1; + } + return $x[1] == $y[1] ? strcmp($x[0], $y[0]) : strcmp($x[1], $y[1]); +}); + $rels = pkg_relations($row["ID"]); $rels_c = $rels_p = $rels_r = array(); foreach ($rels as $rel) { -- 2.0.4
This patch is better. At least, it does sort alphabetically the dependencies of the same type. As I'm not familiar with PHP, I though about u(a)sort after the patch...
On Sat, 09 Aug 2014 at 22:21:53, Lukas Fleischer wrote:
I like the suggestions but the implementation has some flaws. For example, checkdepends appear before (regular) dependencies and packages with the same dependency type are not sorted alphabetically (note that PHP's sort functions are not stable). How about the following patch?
-- >8 --
web/template/pkg_details.php | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 7f01d2f..8a3cbcc 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -29,6 +29,16 @@ $grps = pkg_groups($row["ID"]); $deps = pkg_dependencies($row["ID"]); $requiredby = pkg_required($row["Name"]);
+usort($deps, function($x, $y) { + if ($x[1] == "depends" && $y[1] != "depends") { + return -1; + } + if ($y[1] == "depends" && $x[1] != "depends") { + return 1; + } + return $x[1] == $y[1] ? strcmp($x[0], $y[0]) : strcmp($x[1], $y[1]); +}); + $rels = pkg_relations($row["ID"]); $rels_c = $rels_p = $rels_r = array(); foreach ($rels as $rel) {
-- Mathieu (matael) Gaborit mat.gaborit@gmx.com Merci de ne m'imprimer que si nécessaire Please don't print this unless it's necessary
Implements FS#40888. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/template/pkg_details.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 7f01d2f..8a3cbcc 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -29,6 +29,16 @@ $grps = pkg_groups($row["ID"]); $deps = pkg_dependencies($row["ID"]); $requiredby = pkg_required($row["Name"]); +usort($deps, function($x, $y) { + if ($x[1] == "depends" && $y[1] != "depends") { + return -1; + } + if ($y[1] == "depends" && $x[1] != "depends") { + return 1; + } + return $x[1] == $y[1] ? strcmp($x[0], $y[0]) : strcmp($x[1], $y[1]); +}); + $rels = pkg_relations($row["ID"]); $rels_c = $rels_p = $rels_r = array(); foreach ($rels as $rel) { -- 2.0.4
participants (2)
-
Lukas Fleischer
-
Mathieu Gaborit