[pacman-dev] pacman: new config to highlight testing packages

Message ID 20190910095352.158387-1-wsdmatty@gmail.com
State New
Headers show
Series
  • [pacman-dev] pacman: new config to highlight testing packages
Related show

Commit Message

Matthew Sexton Sept. 10, 2019, 9:53 a.m. UTC
Only during Install/Upgrade, and not to verbosepkglist

Signed-off-by: Matthew Sexton <wsdmatty@gmail.com>
---
 src/pacman/conf.c        |  2 ++
 src/pacman/conf.h        |  2 ++
 src/pacman/pacman-conf.c |  1 +
 src/pacman/util.c        | 20 ++++++++++++++++----
 4 files changed, 21 insertions(+), 4 deletions(-)

Comments

Morgan Adamiec Sept. 10, 2019, 9:57 a.m. UTC | #1
On Tue, 10 Sep 2019 at 10:54, Matthew Sexton <wsdmatty@gmail.com> wrote:
>
> Only during Install/Upgrade, and not to verbosepkglist
>
> Signed-off-by: Matthew Sexton <wsdmatty@gmail.com>
> ---
>  src/pacman/conf.c        |  2 ++
>  src/pacman/conf.h        |  2 ++
>  src/pacman/pacman-conf.c |  1 +
>  src/pacman/util.c        | 20 ++++++++++++++++----
>  4 files changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/src/pacman/conf.c b/src/pacman/conf.c
> index 2d8518c4..70c8a4f4 100644
> --- a/src/pacman/conf.c
> +++ b/src/pacman/conf.c
> @@ -494,6 +494,8 @@ static int _parse_options(const char *key, char *value,
>                                 config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF;
>                                 enable_colors(config->color);
>                         }
> +               } else if(strcmp(key, "HighlightTesting") == 0) {
> +                       config->highlighttesting = 1;
>                 } else if(strcmp(key, "DisableDownloadTimeout") == 0) {
>                         config->disable_dl_timeout = 1;
>                 } else {
> diff --git a/src/pacman/conf.h b/src/pacman/conf.h
> index f45ed436..51fa5764 100644
> --- a/src/pacman/conf.h
> +++ b/src/pacman/conf.h
> @@ -117,6 +117,8 @@ typedef struct __config_t {
>         unsigned short totaldownload;
>         /* select -Sc behavior */
>         unsigned short cleanmethod;
> +       /* Highlight packages from testing repositories */
> +       unsigned short highlighttesting;
>         alpm_list_t *holdpkg;
>         alpm_list_t *ignorepkg;
>         alpm_list_t *ignoregrp;
> diff --git a/src/pacman/pacman-conf.c b/src/pacman/pacman-conf.c
> index df874029..1e40c138 100644
> --- a/src/pacman/pacman-conf.c
> +++ b/src/pacman/pacman-conf.c
> @@ -260,6 +260,7 @@ static void dump_config(void)
>         show_bool("VerbosePkgLists", config->verbosepkglists);
>         show_bool("DisableDownloadTimeout", config->disable_dl_timeout);
>         show_bool("ILoveCandy", config->chomp);
> +  show_bool("HighlightTesting", config->highlighttesting);
>
>         show_cleanmethod("CleanMethod", config->cleanmethod);
>
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 8f6290db..13ac0f25 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -898,15 +898,27 @@ static void _display_targets(alpm_list_t *targets, int verbose)
>
>         /* form data for both verbose and non-verbose display */
>         for(i = targets; i; i = alpm_list_next(i)) {
> +               unsigned short testing = 0;
> +               const char *repo;
>                 pm_target_t *target = i->data;
> -
> +               alpm_db_t *db = alpm_pkg_get_db(target->install);
> +               if(db) {
> +                       repo = alpm_db_get_name(db);
> +                       if (strcmp(repo, "testing") == 0 || strcmp(repo,"community-testing") == 0) {
> +                               testing = 1;
> +                       }
> +               }
>                 if(verbose) {
>                         rows = alpm_list_add(rows, create_verbose_row(target));
>                 }
> -
>                 if(target->install) {
> -                       pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install),
> -                                       alpm_pkg_get_version(target->install));
> +                       if (testing && config->highlighttesting) {
> +                               pm_asprintf(&str, "%s%s-%s%s", config->color == PM_COLOR_ON ? config->colstr.warn : "**",
> +                                                       alpm_pkg_get_name(target->install), alpm_pkg_get_version(target->install),
> +                                                       config->color == PM_COLOR_ON ? config->colstr.nocolor : "**");
> +                       } else {
> +                               pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install), alpm_pkg_get_version(target->install));
> +                       }
>                 } else if(isize == 0) {
>                         pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove),
>                                         alpm_pkg_get_version(target->remove));
> --
> 2.23.0

Pacman is a general Linux package manager and not specific to Arch
Linux. testing and community-testing are specific to Arch Linux.
Matthew Sexton Sept. 10, 2019, 10:04 a.m. UTC | #2
On Tuesday, September 10, 2019 5:57:19 AM EDT Morgan Adamiec wrote:
> Pacman is a general Linux package manager and not specific to Arch
> Linux. testing and community-testing are specific to Arch Linux.

I struggled with whether to share this patch or not, because my motivation was 
pure laziness. I didn't know whether anyone else would find it useful/usable. 
Without maintaining a list of every 'testing' repo name for every distro, it 
would only be useful for Arch. Thank you for the big-picture perspective I was 
clearly missing. =D
Morten Linderud Sept. 10, 2019, 10:17 a.m. UTC | #3
On Tue, Sep 10, 2019 at 06:04:54AM -0400, Matthew Sexton wrote:
> On Tuesday, September 10, 2019 5:57:19 AM EDT Morgan Adamiec wrote:
> > Pacman is a general Linux package manager and not specific to Arch
> > Linux. testing and community-testing are specific to Arch Linux.
> 
> I struggled with whether to share this patch or not, because my motivation was 
> pure laziness. I didn't know whether anyone else would find it useful/usable. 
> Without maintaining a list of every 'testing' repo name for every distro, it 
> would only be useful for Arch. Thank you for the big-picture perspective I was 
> clearly missing. =D

If you turn it around and add a list instead?

HilightRepositories = testing community-testing
Jan Alexander Steffens Sept. 10, 2019, 10:42 a.m. UTC | #4
On Tue, Sep 10, 2019, 12:17 Morten Linderud <foxboron@archlinux.org> wrote:

> If you turn it around and add a list instead?
>
> HilightRepositories = testing community-testing
>

You could give each [repo] a Color= setting.

>
Matthew Sexton Sept. 10, 2019, 10:53 a.m. UTC | #5
On Tuesday, September 10, 2019 6:42:01 AM EDT Jan Alexander Steffens wrote:
> On Tue, Sep 10, 2019, 12:17 Morten Linderud <foxboron@archlinux.org> wrote:
> > If you turn it around and add a list instead?
> > 
> > HilightRepositories = testing community-testing
> 
> You could give each [repo] a Color= setting.

That seems like it would be a little bit more straightforward to implement. 
Making a list of repos to highlight in the config would involve a bunch of alpm 
back-end stuff. (Basically modelling after an existing list, like IgnorePkg)

Patch

diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 2d8518c4..70c8a4f4 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -494,6 +494,8 @@  static int _parse_options(const char *key, char *value,
 				config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF;
 				enable_colors(config->color);
 			}
+		} else if(strcmp(key, "HighlightTesting") == 0) {
+			config->highlighttesting = 1;
 		} else if(strcmp(key, "DisableDownloadTimeout") == 0) {
 			config->disable_dl_timeout = 1;
 		} else {
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index f45ed436..51fa5764 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -117,6 +117,8 @@  typedef struct __config_t {
 	unsigned short totaldownload;
 	/* select -Sc behavior */
 	unsigned short cleanmethod;
+	/* Highlight packages from testing repositories */
+	unsigned short highlighttesting;
 	alpm_list_t *holdpkg;
 	alpm_list_t *ignorepkg;
 	alpm_list_t *ignoregrp;
diff --git a/src/pacman/pacman-conf.c b/src/pacman/pacman-conf.c
index df874029..1e40c138 100644
--- a/src/pacman/pacman-conf.c
+++ b/src/pacman/pacman-conf.c
@@ -260,6 +260,7 @@  static void dump_config(void)
 	show_bool("VerbosePkgLists", config->verbosepkglists);
 	show_bool("DisableDownloadTimeout", config->disable_dl_timeout);
 	show_bool("ILoveCandy", config->chomp);
+  show_bool("HighlightTesting", config->highlighttesting);
 
 	show_cleanmethod("CleanMethod", config->cleanmethod);
 
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 8f6290db..13ac0f25 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -898,15 +898,27 @@  static void _display_targets(alpm_list_t *targets, int verbose)
 
 	/* form data for both verbose and non-verbose display */
 	for(i = targets; i; i = alpm_list_next(i)) {
+		unsigned short testing = 0;
+		const char *repo;
 		pm_target_t *target = i->data;
-
+		alpm_db_t *db = alpm_pkg_get_db(target->install);
+		if(db) {
+			repo = alpm_db_get_name(db);
+			if (strcmp(repo, "testing") == 0 || strcmp(repo,"community-testing") == 0) {
+				testing = 1;
+			}
+		}
 		if(verbose) {
 			rows = alpm_list_add(rows, create_verbose_row(target));
 		}
-
 		if(target->install) {
-			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install),
-					alpm_pkg_get_version(target->install));
+			if (testing && config->highlighttesting) {
+				pm_asprintf(&str, "%s%s-%s%s", config->color == PM_COLOR_ON ? config->colstr.warn : "**",
+							alpm_pkg_get_name(target->install), alpm_pkg_get_version(target->install),
+							config->color == PM_COLOR_ON ? config->colstr.nocolor : "**");
+			} else {
+				pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install), alpm_pkg_get_version(target->install));
+			}
 		} else if(isize == 0) {
 			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove),
 					alpm_pkg_get_version(target->remove));