FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 07-21-2011, 06:39 PM
Benedikt Morbach
 
Default Hook new optdepend structures up

No new behaviour introduced, everything should work exactly as before.
---
lib/libalpm/be_local.c | 11 ++++++++-
lib/libalpm/be_package.c | 5 ++-
lib/libalpm/be_sync.c | 7 +++++-
lib/libalpm/package.c | 7 ++++-
src/pacman/package.c | 11 ++++++++-
src/pacman/util.c | 51 ++++++++++++++++++++++++++++++++++++----------
6 files changed, 72 insertions(+), 20 deletions(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 70f242d..7e4812b 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -610,7 +610,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
info->depends = alpm_list_add(info->depends, _alpm_splitdep(line));
}
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(info->optdepends);
+ /* Different than the rest because of the _alpm_splitoptdep call. */
+ while(1) {
+ READ_NEXT();
+ if(strlen(line) == 0) break;
+ info->optdepends = alpm_list_add(info->optdepends, _alpm_splitoptdep(line));
+ }
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_STORE_ALL(info->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
@@ -800,7 +805,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->optdepends) {
fputs("%OPTDEPENDS%
", fp);
for(lp = info->optdepends; lp; lp = lp->next) {
- fprintf(fp, "%s
", (char *)lp->data);
+ char *optstring = alpm_optdep_compute_string(lp->data);
+ fprintf(fp, "%s
", optstring);
+ free(optstring);
}
fprintf(fp, "
");
}
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 46bdaed..438960c 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -35,7 +35,7 @@
#include "log.h"
#include "handle.h"
#include "package.h"
-#include "deps.h" /* _alpm_splitdep */
+#include "deps.h" /* _alpm_splitdep _alpm_splitoptdep */

/**
* Open a package changelog for reading. Similar to fopen in functionality,
@@ -192,7 +192,8 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
alpm_depend_t *dep = _alpm_splitdep(ptr);
newpkg->depends = alpm_list_add(newpkg->depends, dep);
} else if(strcmp(key, "optdepend") == 0) {
- newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr));
+ alpm_optdepend_t *optdep = _alpm_splitoptdep(ptr);
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
} else if(strcmp(key, "conflict") == 0) {
newpkg->conflicts = alpm_list_add(newpkg->conflicts, strdup(ptr));
} else if(strcmp(key, "replaces") == 0) {
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index daed01f..3a0c2b4 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -555,7 +555,12 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
pkg->depends = alpm_list_add(pkg->depends, _alpm_splitdep(line));
}
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(pkg->optdepends);
+ /* Different than the rest because of the _alpm_splitoptdep call. */
+ while(1) {
+ READ_NEXT();
+ if(strlen(line) == 0) break;
+ pkg->optdepends = alpm_list_add(pkg->optdepends, _alpm_splitoptdep(line));
+ }
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_STORE_ALL(pkg->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index ae9b9a9..a64d613 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -502,7 +502,9 @@ alpm_pkg_t *_alpm_pkg_dup(alpm_pkg_t *pkg)
for(i = pkg->depends; i; i = alpm_list_next(i)) {
newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
}
- newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
+ for(i = pkg->optdepends; i; i = alpm_list_next(i)) {
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, _alpm_optdep_dup(i->data));
+ }
newpkg->conflicts = alpm_list_strdup(pkg->conflicts);
newpkg->provides = alpm_list_strdup(pkg->provides);
for(i = pkg->deltas; i; i = alpm_list_next(i)) {
@@ -551,7 +553,8 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
alpm_list_free(pkg->backup);
alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
alpm_list_free(pkg->depends);
- FREELIST(pkg->optdepends);
+ alpm_list_free_inner(pkg->optdepends, (alpm_list_fn_free)_alpm_optdep_free);
+ alpm_list_free(pkg->optdepends);
FREELIST(pkg->conflicts);
FREELIST(pkg->provides);
alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index afbac6b..6e6d379 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -53,7 +53,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
const char *label;
double size;
const alpm_list_t *i;
- alpm_list_t *requiredby = NULL, *depstrings = NULL;
+ alpm_list_t *depstrings = NULL, *optstrings = NULL, *requiredby = NULL;

if(pkg == NULL) {
return;
@@ -87,6 +87,12 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep));
}

+ /* turn optdepends list into a text list */
+ for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = (alpm_optdepend_t *)alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
if(extra || from == PKG_FROM_LOCALDB) {
/* compute this here so we don't get a pause in the middle of output */
requiredby = alpm_pkg_compute_requiredby(pkg);
@@ -104,7 +110,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
list_display(_("Provides :"), alpm_pkg_get_provides(pkg));
list_display(_("Depends On :"), depstrings);
- list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
+ list_display_linebreak(_("Optional Deps :"), optstrings);
if(extra || from == PKG_FROM_LOCALDB) {
list_display(_("Required By :"), requiredby);
}
@@ -158,6 +164,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
printf("
");

FREELIST(depstrings);
+ FREELIST(optstrings);
FREELIST(requiredby);
}

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 7065abd..14dcf94 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -974,32 +974,61 @@ void print_packages(const alpm_list_t *packages)
}
}

-/* Helper function for comparing strings using the
+/* Helper function for comparing optdepends using the
* alpm "compare func" signature */
-int str_cmp(const void *s1, const void *s2)
+int opt_cmp(const void *o1, const void *o2)
{
- return strcmp(s1, s2);
+ char *str1 = alpm_optdep_compute_string((alpm_optdepend_t*)o1);
+ char *str2 = alpm_optdep_compute_string((alpm_optdepend_t*)o2);
+ int ret = strcmp(str1, str2);
+
+ free(str1);
+ free(str2);
+
+ return ret;
}

void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
{
- alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
- alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
- alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
- if(optdeps) {
+ alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
+
+ old = alpm_pkg_get_optdepends(oldpkg);
+ new = alpm_pkg_get_optdepends(newpkg);
+ optdeps = alpm_list_diff(new,old,opt_cmp);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = (alpm_optdepend_t *)alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("New optional dependencies for %s
"), alpm_pkg_get_name(newpkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
alpm_list_free(optdeps);
+ FREELIST(optstrings);
}

void display_optdepends(alpm_pkg_t *pkg)
{
- alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
- if(optdeps) {
+ alpm_list_t *i, *optdeps, *optstrings = NULL;
+
+ optdeps = alpm_pkg_get_optdepends(pkg);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = (alpm_optdepend_t *)alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("Optional dependencies for %s
"), alpm_pkg_get_name(pkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
+ FREELIST(optstrings);
}

static void display_repo_list(const char *dbname, alpm_list_t *list)
--
1.7.6
 
Old 07-21-2011, 07:30 PM
Dan McGee
 
Default Hook new optdepend structures up

On Thu, Jul 21, 2011 at 1:39 PM, Benedikt Morbach
<benedikt.morbach@googlemail.com> wrote:
> No new behaviour introduced, everything should work exactly as before.
> ---
> *lib/libalpm/be_local.c * | * 11 ++++++++-
> *lib/libalpm/be_package.c | * *5 ++-
> *lib/libalpm/be_sync.c * *| * *7 +++++-
> *lib/libalpm/package.c * *| * *7 ++++-
> *src/pacman/package.c * * | * 11 ++++++++-
> *src/pacman/util.c * * * *| * 51 ++++++++++++++++++++++++++++++++++++----------
> *6 files changed, 72 insertions(+), 20 deletions(-)
>
> diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
> index 70f242d..7e4812b 100644
> --- a/lib/libalpm/be_local.c
> +++ b/lib/libalpm/be_local.c
> @@ -610,7 +610,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
> * * * * * * * * * * * * * * * * * * * *info->depends = alpm_list_add(info->depends, _alpm_splitdep(line));
> * * * * * * * * * * * * * * * *}
> * * * * * * * * * * * *} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
> - * * * * * * * * * * * * * * * READ_AND_STORE_ALL(info->optdepends);
> + * * * * * * * * * * * * * * * /* Different than the rest because of the _alpm_splitoptdep call. */
> + * * * * * * * * * * * * * * * while(1) {
> + * * * * * * * * * * * * * * * * * * * READ_NEXT();
> + * * * * * * * * * * * * * * * * * * * if(strlen(line) == 0) break;
> + * * * * * * * * * * * * * * * * * * * info->optdepends = alpm_list_add(info->optdepends, _alpm_splitoptdep(line));
> + * * * * * * * * * * * * * * * }
> * * * * * * * * * * * *} else if(strcmp(line, "%CONFLICTS%") == 0) {
> * * * * * * * * * * * * * * * *READ_AND_STORE_ALL(info->conflicts);
> * * * * * * * * * * * *} else if(strcmp(line, "%PROVIDES%") == 0) {
> @@ -800,7 +805,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
> * * * * * * * *if(info->optdepends) {
> * * * * * * * * * * * *fputs("%OPTDEPENDS%
", fp);
> * * * * * * * * * * * *for(lp = info->optdepends; lp; lp = lp->next) {
> - * * * * * * * * * * * * * * * fprintf(fp, "%s
", (char *)lp->data);
> + * * * * * * * * * * * * * * * char *optstring = alpm_optdep_compute_string(lp->data);
> + * * * * * * * * * * * * * * * fprintf(fp, "%s
", optstring);
> + * * * * * * * * * * * * * * * free(optstring);
> * * * * * * * * * * * *}
> * * * * * * * * * * * *fprintf(fp, "
");
> * * * * * * * *}
> diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
> index 46bdaed..438960c 100644
> --- a/lib/libalpm/be_package.c
> +++ b/lib/libalpm/be_package.c
> @@ -35,7 +35,7 @@
> *#include "log.h"
> *#include "handle.h"
> *#include "package.h"
> -#include "deps.h" /* _alpm_splitdep */
> +#include "deps.h" /* _alpm_splitdep _alpm_splitoptdep */
Use a comma if you update this comment, but really you can just kill
the comment bit completely.

>
> */**
> ** Open a package changelog for reading. Similar to fopen in functionality,
> @@ -192,7 +192,8 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
> * * * * * * * * * * * * * * * *alpm_depend_t *dep = _alpm_splitdep(ptr);
> * * * * * * * * * * * * * * * *newpkg->depends = alpm_list_add(newpkg->depends, dep);
> * * * * * * * * * * * *} else if(strcmp(key, "optdepend") == 0) {
> - * * * * * * * * * * * * * * * newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr));
> + * * * * * * * * * * * * * * * alpm_optdepend_t *optdep = _alpm_splitoptdep(ptr);
> + * * * * * * * * * * * * * * * newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
> * * * * * * * * * * * *} else if(strcmp(key, "conflict") == 0) {
> * * * * * * * * * * * * * * * *newpkg->conflicts = alpm_list_add(newpkg->conflicts, strdup(ptr));
> * * * * * * * * * * * *} else if(strcmp(key, "replaces") == 0) {
> diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
> index daed01f..3a0c2b4 100644
> --- a/lib/libalpm/be_sync.c
> +++ b/lib/libalpm/be_sync.c
> @@ -555,7 +555,12 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
> * * * * * * * * * * * * * * * * * * * *pkg->depends = alpm_list_add(pkg->depends, _alpm_splitdep(line));
> * * * * * * * * * * * * * * * *}
> * * * * * * * * * * * *} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
> - * * * * * * * * * * * * * * * READ_AND_STORE_ALL(pkg->optdepends);
> + * * * * * * * * * * * * * * * /* Different than the rest because of the _alpm_splitoptdep call. */
> + * * * * * * * * * * * * * * * while(1) {
> + * * * * * * * * * * * * * * * * * * * READ_NEXT();
> + * * * * * * * * * * * * * * * * * * * if(strlen(line) == 0) break;
> + * * * * * * * * * * * * * * * * * * * pkg->optdepends = alpm_list_add(pkg->optdepends, _alpm_splitoptdep(line));
> + * * * * * * * * * * * * * * * }
> * * * * * * * * * * * *} else if(strcmp(line, "%CONFLICTS%") == 0) {
> * * * * * * * * * * * * * * * *READ_AND_STORE_ALL(pkg->conflicts);
> * * * * * * * * * * * *} else if(strcmp(line, "%PROVIDES%") == 0) {
> diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
> index ae9b9a9..a64d613 100644
> --- a/lib/libalpm/package.c
> +++ b/lib/libalpm/package.c
> @@ -502,7 +502,9 @@ alpm_pkg_t *_alpm_pkg_dup(alpm_pkg_t *pkg)
> * * * *for(i = pkg->depends; i; i = alpm_list_next(i)) {
> * * * * * * * *newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
> * * * *}
> - * * * newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
> + * * * for(i = pkg->optdepends; i; i = alpm_list_next(i)) {
> + * * * * * * * newpkg->optdepends = alpm_list_add(newpkg->optdepends, _alpm_optdep_dup(i->data));
> + * * * }
> * * * *newpkg->conflicts *= alpm_list_strdup(pkg->conflicts);
> * * * *newpkg->provides * = alpm_list_strdup(pkg->provides);
> * * * *for(i = pkg->deltas; i; i = alpm_list_next(i)) {
> @@ -551,7 +553,8 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
> * * * *alpm_list_free(pkg->backup);
> * * * *alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
> * * * *alpm_list_free(pkg->depends);
> - * * * FREELIST(pkg->optdepends);
> + * * * alpm_list_free_inner(pkg->optdepends, (alpm_list_fn_free)_alpm_optdep_free);
> + * * * alpm_list_free(pkg->optdepends);
> * * * *FREELIST(pkg->conflicts);
> * * * *FREELIST(pkg->provides);
> * * * *alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
> diff --git a/src/pacman/package.c b/src/pacman/package.c
> index afbac6b..6e6d379 100644
> --- a/src/pacman/package.c
> +++ b/src/pacman/package.c
> @@ -53,7 +53,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
> * * * *const char *label;
> * * * *double size;
> * * * *const alpm_list_t *i;
> - * * * alpm_list_t *requiredby = NULL, *depstrings = NULL;
> + * * * alpm_list_t *depstrings = NULL, *optstrings = NULL, *requiredby = NULL;
>
> * * * *if(pkg == NULL) {
> * * * * * * * *return;
> @@ -87,6 +87,12 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
> * * * * * * * *depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep));
> * * * *}
>
> + * * * /* turn optdepends list into a text list */
> + * * * for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) {
> + * * * * * * * alpm_optdepend_t *optdep = (alpm_optdepend_t *)alpm_list_getdata(i);
> + * * * * * * * optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
> + * * * }
> +
> * * * *if(extra || from == PKG_FROM_LOCALDB) {
> * * * * * * * */* compute this here so we don't get a pause in the middle of output */
> * * * * * * * *requiredby = alpm_pkg_compute_requiredby(pkg);
> @@ -104,7 +110,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
> * * * *list_display(_("Groups * * * * :"), alpm_pkg_get_groups(pkg));
> * * * *list_display(_("Provides * * * :"), alpm_pkg_get_provides(pkg));
> * * * *list_display(_("Depends On * * :"), depstrings);
> - * * * list_display_linebreak(_("Optional Deps *:"), alpm_pkg_get_optdepends(pkg));
> + * * * list_display_linebreak(_("Optional Deps *:"), optstrings);
> * * * *if(extra || from == PKG_FROM_LOCALDB) {
> * * * * * * * *list_display(_("Required By * *:"), requiredby);
> * * * *}
> @@ -158,6 +164,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
> * * * *printf("
");
>
> * * * *FREELIST(depstrings);
> + * * * FREELIST(optstrings);
> * * * *FREELIST(requiredby);
> *}
>
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 7065abd..14dcf94 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -974,32 +974,61 @@ void print_packages(const alpm_list_t *packages)
> * * * *}
> *}
>
> -/* Helper function for comparing strings using the
> +/* Helper function for comparing optdepends using the
> ** alpm "compare func" signature */
> -int str_cmp(const void *s1, const void *s2)
> +int opt_cmp(const void *o1, const void *o2)
> *{
> - * * * return strcmp(s1, s2);
> + * * * char *str1 = alpm_optdep_compute_string((alpm_optdepend_t*)o1);
> + * * * char *str2 = alpm_optdep_compute_string((alpm_optdepend_t*)o2);
> + * * * int ret = strcmp(str1, str2);
> +
> + * * * free(str1);
> + * * * free(str2);
> +
> + * * * return ret;
Something feels a bit off with this logic. Wouldn't we really just
want to compare by the name portion? Even if we want to compare by
more, we can just do it with three fallthrough strcmp()s which is a
bit better than having to compute and free these strings over and
over. e.g.:

int ret;
alpm od *od1 = o1;
alpm_od *od2 = o2;

ret = strcmp(od1->name, od2->name);
if(!ret && od1->version && od2->version) {
ret = strcmp(od1->version, od2->version);
}
if(!ret && od1->desc && od2->desc) {
ret = strcmp(od1->desc, od2->desc);
}
return ret;

> *}
>
> *void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
> *{
> - * * * alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
> - * * * alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
> - * * * alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
> - * * * if(optdeps) {
> + * * * alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
> +
> + * * * old = alpm_pkg_get_optdepends(oldpkg);
> + * * * new = alpm_pkg_get_optdepends(newpkg);
> + * * * optdeps = alpm_list_diff(new,old,opt_cmp);
Since we're changing this line, can you fix the coding style and use
spaces after commas please?

> +
> + * * * /* turn optdepends list into a text list */
> + * * * for(i = optdeps; i; i = alpm_list_next(i)) {
> + * * * * * * * alpm_optdepend_t *optdep = (alpm_optdepend_t *)alpm_list_getdata(i);
No need for the cast here, it is implied in C.

> + * * * * * * * optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
> + * * * }
> +
> + * * * if(optstrings) {
> * * * * * * * *printf(_("New optional dependencies for %s
"), alpm_pkg_get_name(newpkg));
> - * * * * * * * list_display_linebreak(" * ", optdeps);
> + * * * * * * * list_display_linebreak(" * ", optstrings);
> * * * *}
> +
> * * * *alpm_list_free(optdeps);
> + * * * FREELIST(optstrings);
> *}
>
> *void display_optdepends(alpm_pkg_t *pkg)
> *{
> - * * * alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
> - * * * if(optdeps) {
> + * * * alpm_list_t *i, *optdeps, *optstrings = NULL;
> +
> + * * * optdeps = alpm_pkg_get_optdepends(pkg);
> +
> + * * * /* turn optdepends list into a text list */
> + * * * for(i = optdeps; i; i = alpm_list_next(i)) {
> + * * * * * * * alpm_optdepend_t *optdep = (alpm_optdepend_t *)alpm_list_getdata(i);
Same as above, no need for casting.

> + * * * * * * * optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
> + * * * }
> +
> + * * * if(optstrings) {
> * * * * * * * *printf(_("Optional dependencies for %s
"), alpm_pkg_get_name(pkg));
> - * * * * * * * list_display_linebreak(" * ", optdeps);
> + * * * * * * * list_display_linebreak(" * ", optstrings);
> * * * *}
> +
> + * * * FREELIST(optstrings);
> *}
>
> *static void display_repo_list(const char *dbname, alpm_list_t *list)
> --
> 1.7.6
>
>
>
 
Old 07-25-2011, 08:31 PM
Benedikt Morbach
 
Default Hook new optdepend structures up

No new behaviour introduced, everything should work exactly as before.

Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com>
---
lib/libalpm/be_local.c | 11 ++++++-
lib/libalpm/be_package.c | 5 ++-
lib/libalpm/be_sync.c | 7 ++++-
lib/libalpm/package.c | 7 +++-
src/pacman/package.c | 11 ++++++-
src/pacman/util.c | 73 ++++++++++++++++++++++++++++++++++++++-------
6 files changed, 93 insertions(+), 21 deletions(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 261ad87..401bc64 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -610,7 +610,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
info->depends = alpm_list_add(info->depends, _alpm_splitdep(line));
}
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(info->optdepends);
+ /* Different than the rest because of the _alpm_splitoptdep call. */
+ while(1) {
+ READ_NEXT();
+ if(strlen(line) == 0) break;
+ info->optdepends = alpm_list_add(info->optdepends, _alpm_splitoptdep(line));
+ }
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_STORE_ALL(info->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
@@ -822,7 +827,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->optdepends) {
fputs("%OPTDEPENDS%
", fp);
for(lp = info->optdepends; lp; lp = lp->next) {
- fprintf(fp, "%s
", (char *)lp->data);
+ char *optstring = alpm_optdep_compute_string(lp->data);
+ fprintf(fp, "%s
", optstring);
+ free(optstring);
}
fprintf(fp, "
");
}
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 0edaa5a..2cf3e46 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -35,7 +35,7 @@
#include "log.h"
#include "handle.h"
#include "package.h"
-#include "deps.h" /* _alpm_splitdep */
+#include "deps.h"

/**
* Open a package changelog for reading. Similar to fopen in functionality,
@@ -192,7 +192,8 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
alpm_depend_t *dep = _alpm_splitdep(ptr);
newpkg->depends = alpm_list_add(newpkg->depends, dep);
} else if(strcmp(key, "optdepend") == 0) {
- newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr));
+ alpm_optdepend_t *optdep = _alpm_splitoptdep(ptr);
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
} else if(strcmp(key, "conflict") == 0) {
newpkg->conflicts = alpm_list_add(newpkg->conflicts, strdup(ptr));
} else if(strcmp(key, "replaces") == 0) {
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 07356f0..2b6f98e 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -555,7 +555,12 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
pkg->depends = alpm_list_add(pkg->depends, _alpm_splitdep(line));
}
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(pkg->optdepends);
+ /* Different than the rest because of the _alpm_splitoptdep call. */
+ while(1) {
+ READ_NEXT();
+ if(strlen(line) == 0) break;
+ pkg->optdepends = alpm_list_add(pkg->optdepends, _alpm_splitoptdep(line));
+ }
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_STORE_ALL(pkg->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index fd3d0c6..1d30503 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -503,7 +503,9 @@ alpm_pkg_t *_alpm_pkg_dup(alpm_pkg_t *pkg)
for(i = pkg->depends; i; i = alpm_list_next(i)) {
newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
}
- newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
+ for(i = pkg->optdepends; i; i = alpm_list_next(i)) {
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, _alpm_optdep_dup(i->data));
+ }
newpkg->conflicts = alpm_list_strdup(pkg->conflicts);
newpkg->provides = alpm_list_strdup(pkg->provides);
for(i = pkg->deltas; i; i = alpm_list_next(i)) {
@@ -557,7 +559,8 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
alpm_list_free(pkg->backup);
alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
alpm_list_free(pkg->depends);
- FREELIST(pkg->optdepends);
+ alpm_list_free_inner(pkg->optdepends, (alpm_list_fn_free)_alpm_optdep_free);
+ alpm_list_free(pkg->optdepends);
FREELIST(pkg->conflicts);
FREELIST(pkg->provides);
alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 45afded..7b1442e 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -53,7 +53,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
const char *label;
double size;
const alpm_list_t *i;
- alpm_list_t *requiredby = NULL, *depstrings = NULL;
+ alpm_list_t *depstrings = NULL, *optstrings = NULL, *requiredby = NULL;

if(pkg == NULL) {
return;
@@ -87,6 +87,12 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep));
}

+ /* turn optdepends list into a text list */
+ for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
if(extra || from == PKG_FROM_LOCALDB) {
/* compute this here so we don't get a pause in the middle of output */
requiredby = alpm_pkg_compute_requiredby(pkg);
@@ -104,7 +110,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
list_display(_("Provides :"), alpm_pkg_get_provides(pkg));
list_display(_("Depends On :"), depstrings);
- list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
+ list_display_linebreak(_("Optional Deps :"), optstrings);
if(extra || from == PKG_FROM_LOCALDB) {
list_display(_("Required By :"), requiredby);
}
@@ -158,6 +164,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
printf("
");

FREELIST(depstrings);
+ FREELIST(optstrings);
FREELIST(requiredby);
}

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 7065abd..ca1646c 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -974,32 +974,81 @@ void print_packages(const alpm_list_t *packages)
}
}

-/* Helper function for comparing strings using the
- * alpm "compare func" signature */
-int str_cmp(const void *s1, const void *s2)
+/* Helper function for comparing optdepends using the
+ * alpm "compare func" signature. */
+int opt_cmp(const void *o1, const void *o2)
{
- return strcmp(s1, s2);
+ const alpm_optdepend_t *od1 = o1;
+ const alpm_optdepend_t *od2 = o2;
+ int ret;
+
+ ret = strcmp(od1->depend->name, od2->depend->name);
+ if (ret == 0) {
+ ret = od1->depend->mod - od2->depend->mod;
+ }
+ if ((ret == 0) && (od1->depend->version != od2->depend->version)) {
+ if (od1->depend->version && od2->depend->version) {
+ ret = strcmp(od1->depend->version, od2->depend->version);
+ } else if (!od1->depend->version && od2->depend->version) {
+ return -1;
+ } else if (od1->depend->version && !od2->depend->version) {
+ return 1;
+ }
+ }
+ if ((ret == 0) && (od1->description != od2->description)) {
+ if (od1->description && od2->description) {
+ ret = strcmp(od1->description, od2->description);
+ } else if (!od1->description && od2->description) {
+ return -1;
+ } else if (od1->description && !od2->description) {
+ return 1;
+ }
+ }
+
+ return ret;
}

void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
{
- alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
- alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
- alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
- if(optdeps) {
+ alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
+
+ old = alpm_pkg_get_optdepends(oldpkg);
+ new = alpm_pkg_get_optdepends(newpkg);
+ optdeps = alpm_list_diff(new, old, opt_cmp);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("New optional dependencies for %s
"), alpm_pkg_get_name(newpkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
alpm_list_free(optdeps);
+ FREELIST(optstrings);
}

void display_optdepends(alpm_pkg_t *pkg)
{
- alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
- if(optdeps) {
+ alpm_list_t *i, *optdeps, *optstrings = NULL;
+
+ optdeps = alpm_pkg_get_optdepends(pkg);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("Optional dependencies for %s
"), alpm_pkg_get_name(pkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
+ FREELIST(optstrings);
}

static void display_repo_list(const char *dbname, alpm_list_t *list)
--
1.7.6
 
Old 08-01-2011, 06:31 PM
Benedikt Morbach
 
Default Hook new optdepend structures up

No new behaviour introduced, everything should work exactly as before.

Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com>
---
lib/libalpm/be_local.c | 11 ++++++-
lib/libalpm/be_package.c | 5 ++-
lib/libalpm/be_sync.c | 7 ++++-
lib/libalpm/package.c | 7 +++-
src/pacman/package.c | 11 ++++++-
src/pacman/util.c | 73 ++++++++++++++++++++++++++++++++++++++-------
6 files changed, 93 insertions(+), 21 deletions(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 261ad87..401bc64 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -610,7 +610,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
info->depends = alpm_list_add(info->depends, _alpm_splitdep(line));
}
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(info->optdepends);
+ /* Different than the rest because of the _alpm_splitoptdep call. */
+ while(1) {
+ READ_NEXT();
+ if(strlen(line) == 0) break;
+ info->optdepends = alpm_list_add(info->optdepends, _alpm_splitoptdep(line));
+ }
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_STORE_ALL(info->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
@@ -822,7 +827,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->optdepends) {
fputs("%OPTDEPENDS%
", fp);
for(lp = info->optdepends; lp; lp = lp->next) {
- fprintf(fp, "%s
", (char *)lp->data);
+ char *optstring = alpm_optdep_compute_string(lp->data);
+ fprintf(fp, "%s
", optstring);
+ free(optstring);
}
fprintf(fp, "
");
}
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 0edaa5a..2cf3e46 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -35,7 +35,7 @@
#include "log.h"
#include "handle.h"
#include "package.h"
-#include "deps.h" /* _alpm_splitdep */
+#include "deps.h"

/**
* Open a package changelog for reading. Similar to fopen in functionality,
@@ -192,7 +192,8 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
alpm_depend_t *dep = _alpm_splitdep(ptr);
newpkg->depends = alpm_list_add(newpkg->depends, dep);
} else if(strcmp(key, "optdepend") == 0) {
- newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr));
+ alpm_optdepend_t *optdep = _alpm_splitoptdep(ptr);
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
} else if(strcmp(key, "conflict") == 0) {
newpkg->conflicts = alpm_list_add(newpkg->conflicts, strdup(ptr));
} else if(strcmp(key, "replaces") == 0) {
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 07356f0..2b6f98e 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -555,7 +555,12 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
pkg->depends = alpm_list_add(pkg->depends, _alpm_splitdep(line));
}
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(pkg->optdepends);
+ /* Different than the rest because of the _alpm_splitoptdep call. */
+ while(1) {
+ READ_NEXT();
+ if(strlen(line) == 0) break;
+ pkg->optdepends = alpm_list_add(pkg->optdepends, _alpm_splitoptdep(line));
+ }
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_STORE_ALL(pkg->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index fd3d0c6..1d30503 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -503,7 +503,9 @@ alpm_pkg_t *_alpm_pkg_dup(alpm_pkg_t *pkg)
for(i = pkg->depends; i; i = alpm_list_next(i)) {
newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
}
- newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
+ for(i = pkg->optdepends; i; i = alpm_list_next(i)) {
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, _alpm_optdep_dup(i->data));
+ }
newpkg->conflicts = alpm_list_strdup(pkg->conflicts);
newpkg->provides = alpm_list_strdup(pkg->provides);
for(i = pkg->deltas; i; i = alpm_list_next(i)) {
@@ -557,7 +559,8 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
alpm_list_free(pkg->backup);
alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
alpm_list_free(pkg->depends);
- FREELIST(pkg->optdepends);
+ alpm_list_free_inner(pkg->optdepends, (alpm_list_fn_free)_alpm_optdep_free);
+ alpm_list_free(pkg->optdepends);
FREELIST(pkg->conflicts);
FREELIST(pkg->provides);
alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 45afded..7b1442e 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -53,7 +53,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
const char *label;
double size;
const alpm_list_t *i;
- alpm_list_t *requiredby = NULL, *depstrings = NULL;
+ alpm_list_t *depstrings = NULL, *optstrings = NULL, *requiredby = NULL;

if(pkg == NULL) {
return;
@@ -87,6 +87,12 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep));
}

+ /* turn optdepends list into a text list */
+ for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
if(extra || from == PKG_FROM_LOCALDB) {
/* compute this here so we don't get a pause in the middle of output */
requiredby = alpm_pkg_compute_requiredby(pkg);
@@ -104,7 +110,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
list_display(_("Provides :"), alpm_pkg_get_provides(pkg));
list_display(_("Depends On :"), depstrings);
- list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
+ list_display_linebreak(_("Optional Deps :"), optstrings);
if(extra || from == PKG_FROM_LOCALDB) {
list_display(_("Required By :"), requiredby);
}
@@ -158,6 +164,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
printf("
");

FREELIST(depstrings);
+ FREELIST(optstrings);
FREELIST(requiredby);
}

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 7065abd..f66d6e1 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -974,32 +974,81 @@ void print_packages(const alpm_list_t *packages)
}
}

-/* Helper function for comparing strings using the
- * alpm "compare func" signature */
-int str_cmp(const void *s1, const void *s2)
+/* Helper function for comparing optdepends using the
+ * alpm "compare func" signature. */
+static int opt_cmp(const void *o1, const void *o2)
{
- return strcmp(s1, s2);
+ const alpm_optdepend_t *od1 = o1;
+ const alpm_optdepend_t *od2 = o2;
+ int ret;
+
+ ret = strcmp(od1->depend->name, od2->depend->name);
+ if(ret == 0) {
+ ret = od1->depend->mod - od2->depend->mod;
+ }
+ if(ret == 0 && od1->depend->version != od2->depend->version) {
+ if(od1->depend->version && od2->depend->version) {
+ ret = strcmp(od1->depend->version, od2->depend->version);
+ } else if(!od1->depend->version && od2->depend->version) {
+ return -1;
+ } else if(od1->depend->version && !od2->depend->version) {
+ return 1;
+ }
+ }
+ if(ret == 0 && od1->description != od2->description) {
+ if(od1->description && od2->description) {
+ ret = strcmp(od1->description, od2->description);
+ } else if(!od1->description && od2->description) {
+ return -1;
+ } else if(od1->description && !od2->description) {
+ return 1;
+ }
+ }
+
+ return ret;
}

void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
{
- alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
- alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
- alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
- if(optdeps) {
+ alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
+
+ old = alpm_pkg_get_optdepends(oldpkg);
+ new = alpm_pkg_get_optdepends(newpkg);
+ optdeps = alpm_list_diff(new, old, opt_cmp);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("New optional dependencies for %s
"), alpm_pkg_get_name(newpkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
alpm_list_free(optdeps);
+ FREELIST(optstrings);
}

void display_optdepends(alpm_pkg_t *pkg)
{
- alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
- if(optdeps) {
+ alpm_list_t *i, *optdeps, *optstrings = NULL;
+
+ optdeps = alpm_pkg_get_optdepends(pkg);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("Optional dependencies for %s
"), alpm_pkg_get_name(pkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
+ FREELIST(optstrings);
}

static void display_repo_list(const char *dbname, alpm_list_t *list)
--
1.7.6
 
Old 09-11-2011, 07:29 PM
Benedikt Morbach
 
Default Hook new optdepend structures up

No new behaviour introduced, everything should work exactly as before.

Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com>
---
lib/libalpm/be_local.c | 12 ++++++-
lib/libalpm/be_package.c | 5 ++-
lib/libalpm/be_sync.c | 8 ++++-
lib/libalpm/package.c | 7 +++-
src/pacman/package.c | 18 ++++++++++-
src/pacman/util.c | 73 ++++++++++++++++++++++++++++++++++++++-------
6 files changed, 102 insertions(+), 21 deletions(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 80711df..ad425b6 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -512,6 +512,12 @@ static char *get_pkgpath(alpm_db_t *db, alpm_pkg_t *info)
f = alpm_list_add(f, _alpm_splitdep(line));
} while(1) /* note the while(1) and not (0) */

+#define READ_AND_SPLITOPTDEP(f) do {
+ if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error;
+ if(_alpm_strip_newline(line) == 0) break;
+ f = alpm_list_add(f, _alpm_splitoptdep(line));
+} while(1) /* note the while(1) and not (0) */
+
static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
{
FILE *fp = NULL;
@@ -607,7 +613,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
} else if(strcmp(line, "%DEPENDS%") == 0) {
READ_AND_SPLITDEP(info->depends);
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(info->optdepends);
+ READ_AND_SPLITOPTDEP(info->optdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(info->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
@@ -818,7 +824,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->optdepends) {
fputs("%OPTDEPENDS%
", fp);
for(lp = info->optdepends; lp; lp = lp->next) {
- fprintf(fp, "%s
", (char *)lp->data);
+ char *optstring = alpm_optdep_compute_string(lp->data);
+ fprintf(fp, "%s
", optstring);
+ free(optstring);
}
fprintf(fp, "
");
}
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 8b035ca..1364d08 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -35,7 +35,7 @@
#include "log.h"
#include "handle.h"
#include "package.h"
-#include "deps.h" /* _alpm_splitdep */
+#include "deps.h"

/**
* Open a package changelog for reading. Similar to fopen in functionality,
@@ -192,7 +192,8 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
alpm_depend_t *dep = _alpm_splitdep(ptr);
newpkg->depends = alpm_list_add(newpkg->depends, dep);
} else if(strcmp(key, "optdepend") == 0) {
- newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr));
+ alpm_optdepend_t *optdep = _alpm_splitoptdep(ptr);
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
} else if(strcmp(key, "conflict") == 0) {
alpm_depend_t *conflict = _alpm_splitdep(ptr);
newpkg->conflicts = alpm_list_add(newpkg->conflicts, conflict);
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 7eb2539..9f6797d 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -491,6 +491,12 @@ static int sync_db_populate(alpm_db_t *db)
f = alpm_list_add(f, _alpm_splitdep(line));
} while(1) /* note the while(1) and not (0) */

+#define READ_AND_SPLITOPTDEP(f) do {
+ if(_alpm_archive_fgets(archive, &buf) != ARCHIVE_OK) goto error;
+ if(_alpm_strip_newline(buf.line) == 0) break;
+ f = alpm_list_add(f, _alpm_splitoptdep(line));
+} while(1) /* note the while(1) and not (0) */
+
static int sync_db_read(alpm_db_t *db, struct archive *archive,
struct archive_entry *entry, alpm_pkg_t **likely_pkg)
{
@@ -577,7 +583,7 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
} else if(strcmp(line, "%DEPENDS%") == 0) {
READ_AND_SPLITDEP(pkg->depends);
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(pkg->optdepends);
+ READ_AND_SPLITOPTDEP(pkg->optdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(pkg->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 3045857..c1fbcca 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -538,7 +538,9 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
for(i = pkg->depends; i; i = i->next) {
newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
}
- newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
+ for(i = pkg->optdepends; i; i = i->next) {
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, _alpm_optdep_dup(i->data));
+ }
for(i = pkg->conflicts; i; i = i->next) {
newpkg->conflicts = alpm_list_add(newpkg->conflicts, _alpm_dep_dup(i->data));
}
@@ -600,7 +602,8 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
alpm_list_free(pkg->backup);
alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
alpm_list_free(pkg->depends);
- FREELIST(pkg->optdepends);
+ alpm_list_free_inner(pkg->optdepends, (alpm_list_fn_free)_alpm_optdep_free);
+ alpm_list_free(pkg->optdepends);
alpm_list_free_inner(pkg->conflicts, (alpm_list_fn_free)_alpm_dep_free);
alpm_list_free(pkg->conflicts);
alpm_list_free_inner(pkg->provides, (alpm_list_fn_free)_alpm_dep_free);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 6a312f9..4f8a180 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -39,7 +39,6 @@

/** Turn a depends list into a text list.
* @param deps a list with items of type alpm_depend_t
- * @return a string list, must be freed
*/
static void deplist_display(const char *title,
alpm_list_t *deps)
@@ -53,6 +52,21 @@ static void deplist_display(const char *title,
FREELIST(text);
}

+/** Turn a optdepends list into a text list.
+ * @param optdeps a list with items of type alpm_optdepend_t
+ */
+static void optdeplist_display(const char *title,
+ alpm_list_t *optdeps)
+{
+ alpm_list_t *i, *text = NULL;
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ text = alpm_list_add(text, alpm_optdep_compute_string(optdep));
+ }
+ list_display_linebreak(title, text);
+ FREELIST(text);
+}
+
/**
* Display the details of a package.
* Extra information entails 'required by' info for sync packages and backup
@@ -112,7 +126,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
deplist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
deplist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
- list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
+ optdeplist_display(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
if(extra || from == PKG_FROM_LOCALDB) {
list_display(_("Required By :"), requiredby);
}
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 594186f..e8dd326 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -996,32 +996,81 @@ void print_packages(const alpm_list_t *packages)
}
}

-/* Helper function for comparing strings using the
- * alpm "compare func" signature */
-int str_cmp(const void *s1, const void *s2)
+/* Helper function for comparing optdepends using the
+ * alpm "compare func" signature. */
+static int opt_cmp(const void *o1, const void *o2)
{
- return strcmp(s1, s2);
+ const alpm_optdepend_t *od1 = o1;
+ const alpm_optdepend_t *od2 = o2;
+ int ret;
+
+ ret = strcmp(od1->depend->name, od2->depend->name);
+ if(ret == 0) {
+ ret = od1->depend->mod - od2->depend->mod;
+ }
+ if(ret == 0 && od1->depend->version != od2->depend->version) {
+ if(od1->depend->version && od2->depend->version) {
+ ret = strcmp(od1->depend->version, od2->depend->version);
+ } else if(!od1->depend->version && od2->depend->version) {
+ return -1;
+ } else if(od1->depend->version && !od2->depend->version) {
+ return 1;
+ }
+ }
+ if(ret == 0 && od1->description != od2->description) {
+ if(od1->description && od2->description) {
+ ret = strcmp(od1->description, od2->description);
+ } else if(!od1->description && od2->description) {
+ return -1;
+ } else if(od1->description && !od2->description) {
+ return 1;
+ }
+ }
+
+ return ret;
}

void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
{
- alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
- alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
- alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
- if(optdeps) {
+ alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
+
+ old = alpm_pkg_get_optdepends(oldpkg);
+ new = alpm_pkg_get_optdepends(newpkg);
+ optdeps = alpm_list_diff(new, old, opt_cmp);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("New optional dependencies for %s
"), alpm_pkg_get_name(newpkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
alpm_list_free(optdeps);
+ FREELIST(optstrings);
}

void display_optdepends(alpm_pkg_t *pkg)
{
- alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
- if(optdeps) {
+ alpm_list_t *i, *optdeps, *optstrings = NULL;
+
+ optdeps = alpm_pkg_get_optdepends(pkg);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = alpm_list_getdata(i);
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("Optional dependencies for %s
"), alpm_pkg_get_name(pkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
+ FREELIST(optstrings);
}

static void display_repo_list(const char *dbname, alpm_list_t *list)
--
1.7.6.1
 
Old 11-23-2011, 02:51 PM
Benedikt Morbach
 
Default Hook new optdepend structures up

No new behaviour introduced, everything should work exactly as before.

Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com>
---
lib/libalpm/be_local.c | 12 ++++++-
lib/libalpm/be_package.c | 5 ++-
lib/libalpm/be_sync.c | 8 ++++-
lib/libalpm/package.c | 7 +++-
src/pacman/package.c | 18 ++++++++++-
src/pacman/util.c | 73 ++++++++++++++++++++++++++++++++++++++-------
6 files changed, 102 insertions(+), 21 deletions(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 21d2748..6a578ff 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -517,6 +517,12 @@ char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info, const char *filena
f = alpm_list_add(f, _alpm_splitdep(line));
} while(1) /* note the while(1) and not (0) */

+#define READ_AND_SPLITOPTDEP(f) do {
+ if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error;
+ if(_alpm_strip_newline(line) == 0) break;
+ f = alpm_list_add(f, _alpm_splitoptdep(line));
+} while(1) /* note the while(1) and not (0) */
+
static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
{
FILE *fp = NULL;
@@ -613,7 +619,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
} else if(strcmp(line, "%DEPENDS%") == 0) {
READ_AND_SPLITDEP(info->depends);
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(info->optdepends);
+ READ_AND_SPLITOPTDEP(info->optdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(info->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
@@ -824,7 +830,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->optdepends) {
fputs("%OPTDEPENDS%
", fp);
for(lp = info->optdepends; lp; lp = lp->next) {
- fprintf(fp, "%s
", (char *)lp->data);
+ char *optstring = alpm_optdep_compute_string(lp->data);
+ fprintf(fp, "%s
", optstring);
+ free(optstring);
}
fprintf(fp, "
");
}
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 4f530e0..be6e4c8 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -38,7 +38,7 @@
#include "log.h"
#include "handle.h"
#include "package.h"
-#include "deps.h" /* _alpm_splitdep */
+#include "deps.h"

struct package_changelog {
struct archive *archive;
@@ -213,7 +213,8 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
alpm_depend_t *dep = _alpm_splitdep(ptr);
newpkg->depends = alpm_list_add(newpkg->depends, dep);
} else if(strcmp(key, "optdepend") == 0) {
- newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr));
+ alpm_optdepend_t *optdep = _alpm_splitoptdep(ptr);
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
} else if(strcmp(key, "conflict") == 0) {
alpm_depend_t *conflict = _alpm_splitdep(ptr);
newpkg->conflicts = alpm_list_add(newpkg->conflicts, conflict);
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 54c4f87..0aaf085 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -504,6 +504,12 @@ cleanup:
f = alpm_list_add(f, _alpm_splitdep(line));
} while(1) /* note the while(1) and not (0) */

+#define READ_AND_SPLITOPTDEP(f) do {
+ if(_alpm_archive_fgets(archive, &buf) != ARCHIVE_OK) goto error;
+ if(_alpm_strip_newline(buf.line) == 0) break;
+ f = alpm_list_add(f, _alpm_splitoptdep(line));
+} while(1) /* note the while(1) and not (0) */
+
static int sync_db_read(alpm_db_t *db, struct archive *archive,
struct archive_entry *entry, alpm_pkg_t **likely_pkg)
{
@@ -590,7 +596,7 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
} else if(strcmp(line, "%DEPENDS%") == 0) {
READ_AND_SPLITDEP(pkg->depends);
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(pkg->optdepends);
+ READ_AND_SPLITOPTDEP(pkg->optdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(pkg->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 2a97177..451506b 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -531,7 +531,9 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
for(i = pkg->depends; i; i = i->next) {
newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
}
- newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
+ for(i = pkg->optdepends; i; i = i->next) {
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, _alpm_optdep_dup(i->data));
+ }
for(i = pkg->conflicts; i; i = i->next) {
newpkg->conflicts = alpm_list_add(newpkg->conflicts, _alpm_dep_dup(i->data));
}
@@ -593,7 +595,8 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
alpm_list_free(pkg->backup);
alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
alpm_list_free(pkg->depends);
- FREELIST(pkg->optdepends);
+ alpm_list_free_inner(pkg->optdepends, (alpm_list_fn_free)_alpm_optdep_free);
+ alpm_list_free(pkg->optdepends);
alpm_list_free_inner(pkg->conflicts, (alpm_list_fn_free)_alpm_dep_free);
alpm_list_free(pkg->conflicts);
alpm_list_free_inner(pkg->provides, (alpm_list_fn_free)_alpm_dep_free);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index d4bbf88..c7bfb14 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -40,7 +40,6 @@

/** Turn a depends list into a text list.
* @param deps a list with items of type alpm_depend_t
- * @return a string list, must be freed
*/
static void deplist_display(const char *title,
alpm_list_t *deps)
@@ -54,6 +53,21 @@ static void deplist_display(const char *title,
FREELIST(text);
}

+/** Turn a optdepends list into a text list.
+ * @param optdeps a list with items of type alpm_optdepend_t
+ */
+static void optdeplist_display(const char *title,
+ alpm_list_t *optdeps)
+{
+ alpm_list_t *i, *text = NULL;
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = i->data;
+ text = alpm_list_add(text, alpm_optdep_compute_string(optdep));
+ }
+ list_display_linebreak(title, text);
+ FREELIST(text);
+}
+
/**
* Display the details of a package.
* Extra information entails 'required by' info for sync packages and backup
@@ -113,7 +127,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
deplist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
deplist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
- list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
+ optdeplist_display(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
if(extra || from == PKG_FROM_LOCALDB) {
list_display(_("Required By :"), requiredby);
}
diff --git a/src/pacman/util.c b/src/pacman/util.c
index c0dcb9f..2363e6f 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1139,32 +1139,81 @@ void print_packages(const alpm_list_t *packages)
}
}

-/* Helper function for comparing strings using the
- * alpm "compare func" signature */
-int str_cmp(const void *s1, const void *s2)
+/* Helper function for comparing optdepends using the
+ * alpm "compare func" signature. */
+static int opt_cmp(const void *o1, const void *o2)
{
- return strcmp(s1, s2);
+ const alpm_optdepend_t *od1 = o1;
+ const alpm_optdepend_t *od2 = o2;
+ int ret;
+
+ ret = strcmp(od1->depend->name, od2->depend->name);
+ if(ret == 0) {
+ ret = od1->depend->mod - od2->depend->mod;
+ }
+ if(ret == 0 && od1->depend->version != od2->depend->version) {
+ if(od1->depend->version && od2->depend->version) {
+ ret = strcmp(od1->depend->version, od2->depend->version);
+ } else if(!od1->depend->version && od2->depend->version) {
+ return -1;
+ } else if(od1->depend->version && !od2->depend->version) {
+ return 1;
+ }
+ }
+ if(ret == 0 && od1->description != od2->description) {
+ if(od1->description && od2->description) {
+ ret = strcmp(od1->description, od2->description);
+ } else if(!od1->description && od2->description) {
+ return -1;
+ } else if(od1->description && !od2->description) {
+ return 1;
+ }
+ }
+
+ return ret;
}

void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
{
- alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
- alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
- alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
- if(optdeps) {
+ alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
+
+ old = alpm_pkg_get_optdepends(oldpkg);
+ new = alpm_pkg_get_optdepends(newpkg);
+ optdeps = alpm_list_diff(new, old, opt_cmp);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = i->data;
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("New optional dependencies for %s
"), alpm_pkg_get_name(newpkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
alpm_list_free(optdeps);
+ FREELIST(optstrings);
}

void display_optdepends(alpm_pkg_t *pkg)
{
- alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
- if(optdeps) {
+ alpm_list_t *i, *optdeps, *optstrings = NULL;
+
+ optdeps = alpm_pkg_get_optdepends(pkg);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_optdepend_t *optdep = i->data;
+ optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("Optional dependencies for %s
"), alpm_pkg_get_name(pkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
+ FREELIST(optstrings);
}

static void display_repo_list(const char *dbname, alpm_list_t *list)
--
1.7.7.3
 
Old 11-23-2011, 03:20 PM
Denis A. Altoé Falqueto
 
Default Hook new optdepend structures up

On Wed, Nov 23, 2011 at 1:51 PM, Benedikt Morbach
<benedikt.morbach@googlemail.com> wrote:
> --- a/lib/libalpm/be_local.c
> +++ b/lib/libalpm/be_local.c
> @@ -517,6 +517,12 @@ char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info, const char *filena
> * * * *f = alpm_list_add(f, _alpm_splitdep(line));
> *} while(1) /* note the while(1) and not (0) */
>
> +#define READ_AND_SPLITOPTDEP(f) do {
> + * * * if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error;
> + * * * if(_alpm_strip_newline(line) == 0) break;
> + * * * f = alpm_list_add(f, _alpm_splitoptdep(line));
> +} while(1) /* note the while(1) and not (0) */

This DEFINE is equal to the one bellow. Wouldn't it be possible to
separete it in some header file and use from there?

> --- a/lib/libalpm/be_sync.c
> +++ b/lib/libalpm/be_sync.c
> @@ -504,6 +504,12 @@ cleanup:
> * * * *f = alpm_list_add(f, _alpm_splitdep(line));
> *} while(1) /* note the while(1) and not (0) */
>
> +#define READ_AND_SPLITOPTDEP(f) do {
> + * * * if(_alpm_archive_fgets(archive, &buf) != ARCHIVE_OK) goto error;
> + * * * if(_alpm_strip_newline(buf.line) == 0) break;
> + * * * f = alpm_list_add(f, _alpm_splitoptdep(line));
> +} while(1) /* note the while(1) and not (0) */
> +

> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index c0dcb9f..2363e6f 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -1139,32 +1139,81 @@ void print_packages(const alpm_list_t *packages)
> *void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
> *{
> - * * * alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
> - * * * alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
> - * * * alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
> - * * * if(optdeps) {
> + * * * alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
> +
> + * * * old = alpm_pkg_get_optdepends(oldpkg);
> + * * * new = alpm_pkg_get_optdepends(newpkg);
> + * * * optdeps = alpm_list_diff(new, old, opt_cmp);
> +
> + * * * /* turn optdepends list into a text list */
> + * * * for(i = optdeps; i; i = alpm_list_next(i)) {
> + * * * * * * * alpm_optdepend_t *optdep = i->data;
> + * * * * * * * optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
> + * * * }

This las for also looks quite equal to the one in display_optdepends.
I think they could be merged somehow (maybe another DEFINE or a
function)

> *void display_optdepends(alpm_pkg_t *pkg)
> *{
> - * * * alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
> - * * * if(optdeps) {
> + * * * alpm_list_t *i, *optdeps, *optstrings = NULL;
> +
> + * * * optdeps = alpm_pkg_get_optdepends(pkg);
> +
> + * * * /* turn optdepends list into a text list */
> + * * * for(i = optdeps; i; i = alpm_list_next(i)) {
> + * * * * * * * alpm_optdepend_t *optdep = i->data;
> + * * * * * * * optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
> + * * * }

--
A: Because it obfuscates the reading.
Q: Why is top posting so bad?

-------------------------------------------
Denis A. Altoe Falqueto
Linux user #524555
-------------------------------------------
 
Old 12-01-2011, 02:16 AM
Dan McGee
 
Default Hook new optdepend structures up

On Wed, Nov 23, 2011 at 9:51 AM, Benedikt Morbach
<benedikt.morbach@googlemail.com> wrote:
> No new behaviour introduced, everything should work exactly as before.
>
> Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com>
> ---
> *lib/libalpm/be_local.c * | * 12 ++++++-
> *lib/libalpm/be_package.c | * *5 ++-
> *lib/libalpm/be_sync.c * *| * *8 ++++-
> *lib/libalpm/package.c * *| * *7 +++-
> *src/pacman/package.c * * | * 18 ++++++++++-
> *src/pacman/util.c * * * *| * 73 ++++++++++++++++++++++++++++++++++++++-------
> *6 files changed, 102 insertions(+), 21 deletions(-)
>
> diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
> index 21d2748..6a578ff 100644
> --- a/lib/libalpm/be_local.c
> +++ b/lib/libalpm/be_local.c
> @@ -517,6 +517,12 @@ char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info, const char *filena
> * * * *f = alpm_list_add(f, _alpm_splitdep(line));
> *} while(1) /* note the while(1) and not (0) */
>
> +#define READ_AND_SPLITOPTDEP(f) do {
> + * * * if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error;
> + * * * if(_alpm_strip_newline(line) == 0) break;
> + * * * f = alpm_list_add(f, _alpm_splitoptdep(line));
> +} while(1) /* note the while(1) and not (0) */
> +
This and the one in be_sync can go away if you implement my suggestion
in patch #1; READ_AND_SPLITDEP can simply be reused.

> *static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
> *{
> * * * *FILE *fp = NULL;
> @@ -613,7 +619,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
> * * * * * * * * * * * *} else if(strcmp(line, "%DEPENDS%") == 0) {
> * * * * * * * * * * * * * * * *READ_AND_SPLITDEP(info->depends);
> * * * * * * * * * * * *} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
> - * * * * * * * * * * * * * * * READ_AND_STORE_ALL(info->optdepends);
> + * * * * * * * * * * * * * * * READ_AND_SPLITOPTDEP(info->optdepends);
> * * * * * * * * * * * *} else if(strcmp(line, "%CONFLICTS%") == 0) {
> * * * * * * * * * * * * * * * *READ_AND_SPLITDEP(info->conflicts);
> * * * * * * * * * * * *} else if(strcmp(line, "%PROVIDES%") == 0) {
> @@ -824,7 +830,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
> * * * * * * * *if(info->optdepends) {
> * * * * * * * * * * * *fputs("%OPTDEPENDS%
", fp);
> * * * * * * * * * * * *for(lp = info->optdepends; lp; lp = lp->next) {
> - * * * * * * * * * * * * * * * fprintf(fp, "%s
", (char *)lp->data);
> + * * * * * * * * * * * * * * * char *optstring = alpm_optdep_compute_string(lp->data);
> + * * * * * * * * * * * * * * * fprintf(fp, "%s
", optstring);
> + * * * * * * * * * * * * * * * free(optstring);
> * * * * * * * * * * * *}
> * * * * * * * * * * * *fprintf(fp, "
");
> * * * * * * * *}
> diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
> index 4f530e0..be6e4c8 100644
> --- a/lib/libalpm/be_package.c
> +++ b/lib/libalpm/be_package.c
> @@ -38,7 +38,7 @@
> *#include "log.h"
> *#include "handle.h"
> *#include "package.h"
> -#include "deps.h" /* _alpm_splitdep */
> +#include "deps.h"
>
> *struct package_changelog {
> * * * *struct archive *archive;
> @@ -213,7 +213,8 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
> * * * * * * * * * * * * * * * *alpm_depend_t *dep = _alpm_splitdep(ptr);
> * * * * * * * * * * * * * * * *newpkg->depends = alpm_list_add(newpkg->depends, dep);
> * * * * * * * * * * * *} else if(strcmp(key, "optdepend") == 0) {
> - * * * * * * * * * * * * * * * newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr));
> + * * * * * * * * * * * * * * * alpm_optdepend_t *optdep = _alpm_splitoptdep(ptr);
> + * * * * * * * * * * * * * * * newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
> * * * * * * * * * * * *} else if(strcmp(key, "conflict") == 0) {
> * * * * * * * * * * * * * * * *alpm_depend_t *conflict = _alpm_splitdep(ptr);
> * * * * * * * * * * * * * * * *newpkg->conflicts = alpm_list_add(newpkg->conflicts, conflict);
> diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
> index 54c4f87..0aaf085 100644
> --- a/lib/libalpm/be_sync.c
> +++ b/lib/libalpm/be_sync.c
> @@ -504,6 +504,12 @@ cleanup:
> * * * *f = alpm_list_add(f, _alpm_splitdep(line));
> *} while(1) /* note the while(1) and not (0) */
>
> +#define READ_AND_SPLITOPTDEP(f) do {
> + * * * if(_alpm_archive_fgets(archive, &buf) != ARCHIVE_OK) goto error;
> + * * * if(_alpm_strip_newline(buf.line) == 0) break;
> + * * * f = alpm_list_add(f, _alpm_splitoptdep(line));
> +} while(1) /* note the while(1) and not (0) */
> +
> *static int sync_db_read(alpm_db_t *db, struct archive *archive,
> * * * * * * * *struct archive_entry *entry, alpm_pkg_t **likely_pkg)
> *{
> @@ -590,7 +596,7 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
> * * * * * * * * * * * *} else if(strcmp(line, "%DEPENDS%") == 0) {
> * * * * * * * * * * * * * * * *READ_AND_SPLITDEP(pkg->depends);
> * * * * * * * * * * * *} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
> - * * * * * * * * * * * * * * * READ_AND_STORE_ALL(pkg->optdepends);
> + * * * * * * * * * * * * * * * READ_AND_SPLITOPTDEP(pkg->optdepends);
> * * * * * * * * * * * *} else if(strcmp(line, "%CONFLICTS%") == 0) {
> * * * * * * * * * * * * * * * *READ_AND_SPLITDEP(pkg->conflicts);
> * * * * * * * * * * * *} else if(strcmp(line, "%PROVIDES%") == 0) {
> diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
> index 2a97177..451506b 100644
> --- a/lib/libalpm/package.c
> +++ b/lib/libalpm/package.c
> @@ -531,7 +531,9 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
> * * * *for(i = pkg->depends; i; i = i->next) {
> * * * * * * * *newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
> * * * *}
> - * * * newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
> + * * * for(i = pkg->optdepends; i; i = i->next) {
> + * * * * * * * newpkg->optdepends = alpm_list_add(newpkg->optdepends, _alpm_optdep_dup(i->data));
> + * * * }
If we move to all of these being alpm_depend_t typed; implementing a
static method to help the dup process might be worthwhile. Patch on
the way; feel free to include it in your patch series next submission
if it isn't merged already.

> * * * *for(i = pkg->conflicts; i; i = i->next) {
> * * * * * * * *newpkg->conflicts = alpm_list_add(newpkg->conflicts, _alpm_dep_dup(i->data));
> * * * *}
> @@ -593,7 +595,8 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
> * * * *alpm_list_free(pkg->backup);
> * * * *alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
> * * * *alpm_list_free(pkg->depends);
> - * * * FREELIST(pkg->optdepends);
> + * * * alpm_list_free_inner(pkg->optdepends, (alpm_list_fn_free)_alpm_optdep_free);
> + * * * alpm_list_free(pkg->optdepends);
> * * * *alpm_list_free_inner(pkg->conflicts, (alpm_list_fn_free)_alpm_dep_free);
> * * * *alpm_list_free(pkg->conflicts);
> * * * *alpm_list_free_inner(pkg->provides, (alpm_list_fn_free)_alpm_dep_free);
> diff --git a/src/pacman/package.c b/src/pacman/package.c
> index d4bbf88..c7bfb14 100644
> --- a/src/pacman/package.c
> +++ b/src/pacman/package.c
> @@ -40,7 +40,6 @@
>
> */** Turn a depends list into a text list.
> ** @param deps a list with items of type alpm_depend_t
> - * @return a string list, must be freed
> **/
> *static void deplist_display(const char *title,
> * * * * * * * *alpm_list_t *deps)
> @@ -54,6 +53,21 @@ static void deplist_display(const char *title,
> * * * *FREELIST(text);
> *}
>
> +/** Turn a optdepends list into a text list.
> + * @param optdeps a list with items of type alpm_optdepend_t
> + */
> +static void optdeplist_display(const char *title,
> + * * * * * * * alpm_list_t *optdeps)
> +{
> + * * * alpm_list_t *i, *text = NULL;
> + * * * for(i = optdeps; i; i = alpm_list_next(i)) {
> + * * * * * * * alpm_optdepend_t *optdep = i->data;
> + * * * * * * * text = alpm_list_add(text, alpm_optdep_compute_string(optdep));
> + * * * }
> + * * * list_display_linebreak(title, text);
> + * * * FREELIST(text);
> +}
> +
> */**
> ** Display the details of a package.
> ** Extra information entails 'required by' info for sync packages and backup
> @@ -113,7 +127,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
> * * * *list_display(_("Groups * * * * :"), alpm_pkg_get_groups(pkg));
> * * * *deplist_display(_("Provides * * * :"), alpm_pkg_get_provides(pkg));
> * * * *deplist_display(_("Depends On * * :"), alpm_pkg_get_depends(pkg));
> - * * * list_display_linebreak(_("Optional Deps *:"), alpm_pkg_get_optdepends(pkg));
> + * * * optdeplist_display(_("Optional Deps *:"), alpm_pkg_get_optdepends(pkg));
> * * * *if(extra || from == PKG_FROM_LOCALDB) {
> * * * * * * * *list_display(_("Required By * *:"), requiredby);
> * * * *}
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index c0dcb9f..2363e6f 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -1139,32 +1139,81 @@ void print_packages(const alpm_list_t *packages)
> * * * *}
> *}
>
> -/* Helper function for comparing strings using the
> - * alpm "compare func" signature */
> -int str_cmp(const void *s1, const void *s2)
> +/* Helper function for comparing optdepends using the
> + * alpm "compare func" signature. */
> +static int opt_cmp(const void *o1, const void *o2)
optdep_cmp at least (depend_cmp if we refactor the type), "opt" all by
itself is pretty hard to grok.
> *{
> - * * * return strcmp(s1, s2);
> + * * * const alpm_optdepend_t *od1 = o1;
> + * * * const alpm_optdepend_t *od2 = o2;
> + * * * int ret;
> +
> + * * * ret = strcmp(od1->depend->name, od2->depend->name);
> + * * * if(ret == 0) {
> + * * * * * * * ret = od1->depend->mod - od2->depend->mod;
> + * * * }
> + * * * if(ret == 0 && od1->depend->version != od2->depend->version) {
> + * * * * * * * if(od1->depend->version && od2->depend->version) {
> + * * * * * * * * * * * ret = strcmp(od1->depend->version, od2->depend->version);
> + * * * * * * * } else if(!od1->depend->version && od2->depend->version) {
> + * * * * * * * * * * * return -1;
> + * * * * * * * } else if(od1->depend->version && !od2->depend->version) {
> + * * * * * * * * * * * return *1;
> + * * * * * * * }
> + * * * }
> + * * * if(ret == 0 && od1->description != od2->description) {
> + * * * * * * * if(od1->description && od2->description) {
> + * * * * * * * * * * * ret = strcmp(od1->description, od2->description);
> + * * * * * * * } else if(!od1->description && od2->description) {
> + * * * * * * * * * * * return -1;
> + * * * * * * * } else if(od1->description && !od2->description) {
> + * * * * * * * * * * * return *1;
> + * * * * * * * }
> + * * * }
> +
> + * * * return ret;
I feel like this could be simplified a bit, but we can tackle that later.

> *}
>
> *void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
> *{
> - * * * alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
> - * * * alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
> - * * * alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
> - * * * if(optdeps) {
> + * * * alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
> +
> + * * * old = alpm_pkg_get_optdepends(oldpkg);
> + * * * new = alpm_pkg_get_optdepends(newpkg);
> + * * * optdeps = alpm_list_diff(new, old, opt_cmp);
> +
> + * * * /* turn optdepends list into a text list */
> + * * * for(i = optdeps; i; i = alpm_list_next(i)) {
> + * * * * * * * alpm_optdepend_t *optdep = i->data;
> + * * * * * * * optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
> + * * * }
> +
> + * * * if(optstrings) {
> * * * * * * * *printf(_("New optional dependencies for %s
"), alpm_pkg_get_name(newpkg));
> - * * * * * * * list_display_linebreak(" * ", optdeps);
> + * * * * * * * list_display_linebreak(" * ", optstrings);
> * * * *}
> +
> * * * *alpm_list_free(optdeps);
> + * * * FREELIST(optstrings);
> *}
>
> *void display_optdepends(alpm_pkg_t *pkg)
> *{
> - * * * alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
> - * * * if(optdeps) {
> + * * * alpm_list_t *i, *optdeps, *optstrings = NULL;
> +
> + * * * optdeps = alpm_pkg_get_optdepends(pkg);
> +
> + * * * /* turn optdepends list into a text list */
> + * * * for(i = optdeps; i; i = alpm_list_next(i)) {
> + * * * * * * * alpm_optdepend_t *optdep = i->data;
> + * * * * * * * optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
> + * * * }
> +
> + * * * if(optstrings) {
> * * * * * * * *printf(_("Optional dependencies for %s
"), alpm_pkg_get_name(pkg));
> - * * * * * * * list_display_linebreak(" * ", optdeps);
> + * * * * * * * list_display_linebreak(" * ", optstrings);
> * * * *}
> +
> + * * * FREELIST(optstrings);
> *}
>
> *static void display_repo_list(const char *dbname, alpm_list_t *list)
> --
> 1.7.7.3
>
>
 
Old 03-08-2012, 10:14 PM
Dan McGee
 
Default Hook new optdepend structures up

From: Benedikt Morbach <benedikt.morbach@googlemail.com>

No new behaviour introduced, everything should work exactly as before.

Dan: refactored to use the single alpm_depend_t structure.

Signed-off-by: Benedikt Morbach <benedikt.morbach@googlemail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
---
lib/libalpm/alpm.h | 2 +-
lib/libalpm/be_local.c | 6 ++--
lib/libalpm/be_package.c | 5 +--
lib/libalpm/be_sync.c | 2 +-
lib/libalpm/package.c | 4 +--
src/pacman/package.c | 18 +++++++++--
src/pacman/util.c | 79 +++++++++++++++++++++++++++++++++++++++-------
7 files changed, 94 insertions(+), 22 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 8a418dc..a6b7c78 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -820,7 +820,7 @@ alpm_list_t *alpm_pkg_get_depends(alpm_pkg_t *pkg);

/** Returns the list of package optional dependencies.
* @param pkg a pointer to package
- * @return a reference to an internal list of strings.
+ * @return a reference to an internal list of alpm_depend_t structures.
*/
alpm_list_t *alpm_pkg_get_optdepends(alpm_pkg_t *pkg);

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 20b7895..0d423fa 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -611,7 +611,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
} else if(strcmp(line, "%DEPENDS%") == 0) {
READ_AND_SPLITDEP(info->depends);
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(info->optdepends);
+ READ_AND_SPLITDEP(info->optdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(info->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
@@ -829,7 +829,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->optdepends) {
fputs("%OPTDEPENDS%
", fp);
for(lp = info->optdepends; lp; lp = lp->next) {
- fprintf(fp, "%s
", (char *)lp->data);
+ char *optstring = alpm_dep_compute_string(lp->data);
+ fprintf(fp, "%s
", optstring);
+ free(optstring);
}
fprintf(fp, "
");
}
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 4008195..c076f61 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -36,7 +36,7 @@
#include "log.h"
#include "handle.h"
#include "package.h"
-#include "deps.h" /* _alpm_splitdep */
+#include "deps.h"

struct package_changelog {
struct archive *archive;
@@ -214,7 +214,8 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
alpm_depend_t *dep = _alpm_splitdep(ptr);
newpkg->depends = alpm_list_add(newpkg->depends, dep);
} else if(strcmp(key, "optdepend") == 0) {
- newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr));
+ alpm_depend_t *optdep = _alpm_splitdep(ptr);
+ newpkg->optdepends = alpm_list_add(newpkg->optdepends, optdep);
} else if(strcmp(key, "conflict") == 0) {
alpm_depend_t *conflict = _alpm_splitdep(ptr);
newpkg->conflicts = alpm_list_add(newpkg->conflicts, conflict);
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index b7b2acd..c403203 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -566,7 +566,7 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
} else if(strcmp(line, "%DEPENDS%") == 0) {
READ_AND_SPLITDEP(pkg->depends);
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
- READ_AND_STORE_ALL(pkg->optdepends);
+ READ_AND_SPLITDEP(pkg->optdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(pkg->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index f66c307..5b07563 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -522,7 +522,7 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
newpkg->backup = alpm_list_add(newpkg->backup, _alpm_backup_dup(i->data));
}
newpkg->depends = list_depdup(pkg->depends);
- newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
+ newpkg->optdepends = list_depdup(pkg->optdepends);
newpkg->conflicts = list_depdup(pkg->conflicts);
newpkg->provides = list_depdup(pkg->provides);
for(i = pkg->deltas; i; i = i->next) {
@@ -597,7 +597,7 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
alpm_list_free_inner(pkg->backup, (alpm_list_fn_free)_alpm_backup_free);
alpm_list_free(pkg->backup);
free_deplist(pkg->depends);
- FREELIST(pkg->optdepends);
+ free_deplist(pkg->optdepends);
free_deplist(pkg->conflicts);
free_deplist(pkg->provides);
alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index bef91e2..54c035c 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -38,7 +38,6 @@

/** Turn a depends list into a text list.
* @param deps a list with items of type alpm_depend_t
- * @return a string list, must be freed
*/
static void deplist_display(const char *title,
alpm_list_t *deps)
@@ -52,6 +51,21 @@ static void deplist_display(const char *title,
FREELIST(text);
}

+/** Turn a optdepends list into a text list.
+ * @param optdeps a list with items of type alpm_optdepend_t
+ */
+static void optdeplist_display(const char *title,
+ alpm_list_t *optdeps)
+{
+ alpm_list_t *i, *text = NULL;
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_depend_t *optdep = i->data;
+ text = alpm_list_add(text, alpm_dep_compute_string(optdep));
+ }
+ list_display_linebreak(title, text);
+ FREELIST(text);
+}
+
/**
* Display the details of a package.
* Extra information entails 'required by' info for sync packages and backup
@@ -111,7 +125,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
deplist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
deplist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
- list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
+ optdeplist_display(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
if(extra || from == PKG_FROM_LOCALDB) {
list_display(_("Required By :"), requiredby);
}
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 1d9049e..7be3dc5 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1151,32 +1151,87 @@ void print_packages(const alpm_list_t *packages)
}
}

-/* Helper function for comparing strings using the
- * alpm "compare func" signature */
-int str_cmp(const void *s1, const void *s2)
+/**
+ * Helper function for comparing depends using the alpm "compare func"
+ * signature. The function descends through the structure in the following
+ * comparison order: name, modifier (e.g., '>', '='), version, description.
+ * @param d1 the first depend structure
+ * @param d2 the second depend structure
+ * @return -1, 0, or 1 if first is <, ==, or > second
+ */
+static int depend_cmp(const void *d1, const void *d2)
{
- return strcmp(s1, s2);
+ const alpm_depend_t *dep1 = d1;
+ const alpm_depend_t *dep2 = d2;
+ int ret;
+
+ ret = strcmp(dep1->name, dep2->name);
+ if(ret == 0) {
+ ret = dep1->mod - dep2->mod;
+ }
+ if(ret == 0) {
+ if(dep1->version && dep2->version) {
+ ret = strcmp(dep1->version, dep2->version);
+ } else if(!dep1->version && dep2->version) {
+ ret = -1;
+ } else if(dep1->version && !dep2->version) {
+ ret = 1;
+ }
+ }
+ if(ret == 0) {
+ if(dep1->desc && dep2->desc) {
+ ret = strcmp(dep1->desc, dep2->desc);
+ } else if(!dep1->desc && dep2->desc) {
+ ret = -1;
+ } else if(dep1->desc && !dep2->desc) {
+ ret = 1;
+ }
+ }
+
+ return ret;
}

void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
{
- alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg);
- alpm_list_t *new = alpm_pkg_get_optdepends(newpkg);
- alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp);
- if(optdeps) {
+ alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL;
+
+ old = alpm_pkg_get_optdepends(oldpkg);
+ new = alpm_pkg_get_optdepends(newpkg);
+ optdeps = alpm_list_diff(new, old, depend_cmp);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_depend_t *optdep = i->data;
+ optstrings = alpm_list_add(optstrings, alpm_dep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("New optional dependencies for %s
"), alpm_pkg_get_name(newpkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
alpm_list_free(optdeps);
+ FREELIST(optstrings);
}

void display_optdepends(alpm_pkg_t *pkg)
{
- alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
- if(optdeps) {
+ alpm_list_t *i, *optdeps, *optstrings = NULL;
+
+ optdeps = alpm_pkg_get_optdepends(pkg);
+
+ /* turn optdepends list into a text list */
+ for(i = optdeps; i; i = alpm_list_next(i)) {
+ alpm_depend_t *optdep = i->data;
+ optstrings = alpm_list_add(optstrings, alpm_dep_compute_string(optdep));
+ }
+
+ if(optstrings) {
printf(_("Optional dependencies for %s
"), alpm_pkg_get_name(pkg));
- list_display_linebreak(" ", optdeps);
+ list_display_linebreak(" ", optstrings);
}
+
+ FREELIST(optstrings);
}

static void display_repo_list(const char *dbname, alpm_list_t *list)
--
1.7.9.3
 

Thread Tools




All times are GMT. The time now is 10:20 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org