From: Xavier Chantry <[email protected]>

This flag allows to disable version checking in dependency resolving
code.

depcmp_tolerant respects the NODEPVERSION flag but we still keep the
original strict depcmp. The idea is to reduce the impact of the
NODEPVERSION flag by using it in fewer places.

I replaced almost all depcmp calls by depcmp_tolerant in deps.c (except
in the public find_satisfier used by deptest / pacman -T), but I kept
depcmp in sync.c and conflict.c

Signed-off-by: Xavier Chantry <[email protected]>
---
 lib/libalpm/alpm.h |    2 +-
 lib/libalpm/deps.c |   43 +++++++++++++++++++++++++++++++++++--------
 lib/libalpm/deps.h |    1 +
 3 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 7c4cd48..66258f8 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -275,7 +275,7 @@ typedef enum _pmtransflag_t {
        PM_TRANS_FLAG_NODEPS = 1,
        PM_TRANS_FLAG_FORCE = (1 << 1),
        PM_TRANS_FLAG_NOSAVE = (1 << 2),
-       /* (1 << 3) flag can go here */
+       PM_TRANS_FLAG_NODEPVERSION = (1 << 3),
        PM_TRANS_FLAG_CASCADE = (1 << 4),
        PM_TRANS_FLAG_RECURSE = (1 << 5),
        PM_TRANS_FLAG_DBONLY = (1 << 6),
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 3d4b1df..3c057a6 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -195,7 +195,7 @@ pmpkg_t *_alpm_find_dep_satisfier(alpm_list_t *pkgs, 
pmdepend_t *dep)
 
        for(i = pkgs; i; i = alpm_list_next(i)) {
                pmpkg_t *pkg = i->data;
-               if(_alpm_depcmp(pkg, dep)) {
+               if(_alpm_depcmp_tolerant(pkg, dep)) {
                        return(pkg);
                }
        }
@@ -319,12 +319,20 @@ static int dep_vercmp(const char *version1, pmdepmod_t 
mod,
        return(equal);
 }
 
-int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
+/* nodepversion: skip version checking */
+static int _depcmp(pmpkg_t *pkg, pmdepend_t *dep, int nodepversion)
 {
        alpm_list_t *i;
        const char *pkgname = pkg->name;
        const char *pkgversion = pkg->version;
        int satisfy = 0;
+       int depmod;
+
+       if(nodepversion) {
+               depmod = PM_DEP_MOD_ANY;
+       } else {
+               depmod = dep->mod;
+       }
 
        /* check (pkg->name, pkg->version) */
        if(pkg->name_hash && dep->name_hash
@@ -332,7 +340,7 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
                /* skip more expensive checks */
        } else {
                satisfy = (strcmp(pkgname, dep->name) == 0
-                               && dep_vercmp(pkgversion, dep->mod, 
dep->version));
+                               && dep_vercmp(pkgversion, depmod, 
dep->version));
                if(satisfy) {
                        return(satisfy);
                }
@@ -344,7 +352,7 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
                const char *provver = strchr(provision, '=');
 
                if(provver == NULL) { /* no provision version */
-                       satisfy = (dep->mod == PM_DEP_MOD_ANY
+                       satisfy = (depmod == PM_DEP_MOD_ANY
                                        && strcmp(provision, dep->name) == 0);
                } else {
                        /* This is a bit tricker than the old code for 
performance reasons. To
@@ -356,13 +364,32 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
                        provver += 1;
                        satisfy = (strlen(dep->name) == namelen
                                        && strncmp(provision, dep->name, 
namelen) == 0
-                                       && dep_vercmp(provver, dep->mod, 
dep->version));
+                                       && dep_vercmp(provver, depmod, 
dep->version));
                }
        }
 
        return(satisfy);
 }
 
+/* tolerant : respects NODEPVERSION flag */
+int _alpm_depcmp_tolerant(pmpkg_t *pkg, pmdepend_t *dep)
+{
+       int nodepversion = 0;
+       int flags = alpm_trans_get_flags();
+
+       if (flags != -1) {
+               nodepversion = flags & PM_TRANS_FLAG_NODEPVERSION;
+       }
+
+       return(_depcmp(pkg, dep, nodepversion));
+}
+
+/* strict : ignores NODEPVERSION flag */
+int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
+{
+       return(_depcmp(pkg, dep, 0));
+}
+
 pmdepend_t *_alpm_splitdep(const char *depstring)
 {
        pmdepend_t *depend;
@@ -527,7 +554,7 @@ pmpkg_t *_alpm_resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
        /* 1. literals */
        for(i = dbs; i; i = i->next) {
                pmpkg_t *pkg = _alpm_db_get_pkgfromcache(i->data, dep->name);
-               if(pkg && _alpm_depcmp(pkg, dep) && !_alpm_pkg_find(excluding, 
pkg->name)) {
+               if(pkg && _alpm_depcmp_tolerant(pkg, dep) && 
!_alpm_pkg_find(excluding, pkg->name)) {
                        if(_alpm_pkg_should_ignore(pkg)) {
                                int install = 0;
                                if (prompt) {
@@ -548,7 +575,7 @@ pmpkg_t *_alpm_resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
        for(i = dbs; i; i = i->next) {
                for(j = _alpm_db_get_pkgcache(i->data); j; j = j->next) {
                        pmpkg_t *pkg = j->data;
-                       if(_alpm_depcmp(pkg, dep) && strcmp(pkg->name, 
dep->name) != 0 &&
+                       if(_alpm_depcmp_tolerant(pkg, dep) && strcmp(pkg->name, 
dep->name) != 0 &&
                                     !_alpm_pkg_find(excluding, pkg->name)) {
                                if(_alpm_pkg_should_ignore(pkg)) {
                                        int install = 0;
@@ -674,7 +701,7 @@ int _alpm_dep_edge(pmpkg_t *pkg1, pmpkg_t *pkg2)
 {
        alpm_list_t *i;
        for(i = alpm_pkg_get_depends(pkg1); i; i = i->next) {
-               if(_alpm_depcmp(pkg2, i->data)) {
+               if(_alpm_depcmp_tolerant(pkg2, i->data)) {
                        return(1);
                }
        }
diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
index bd5e9a4..86070ab 100644
--- a/lib/libalpm/deps.h
+++ b/lib/libalpm/deps.h
@@ -57,6 +57,7 @@ int _alpm_dep_edge(pmpkg_t *pkg1, pmpkg_t *pkg2);
 pmdepend_t *_alpm_splitdep(const char *depstring);
 pmpkg_t *_alpm_find_dep_satisfier(alpm_list_t *pkgs, pmdepend_t *dep);
 int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep);
+int _alpm_depcmp_tolerant(pmpkg_t *pkg, pmdepend_t *dep);
 
 #endif /* _ALPM_DEPS_H */
 
-- 
1.7.3.5

Reply via email to