Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/deps.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/deps.c')
-rw-r--r--lib/libalpm/deps.c90
1 files changed, 46 insertions, 44 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 26f9b16d..3d4b1df4 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -1,7 +1,7 @@
/*
* deps.c
*
- * Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org>
+ * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
@@ -34,7 +34,6 @@
#include "graph.h"
#include "package.h"
#include "db.h"
-#include "cache.h"
#include "handle.h"
void _alpm_dep_free(pmdepend_t *dep)
@@ -196,36 +195,25 @@ 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(pkg, dep)) {
return(pkg);
}
}
return(NULL);
}
-/** Checks dependencies and returns missing ones in a list.
- * Dependencies can include versions with depmod operators.
- * @param db pointer to the local package database
- * @param targets an alpm_list_t* of dependencies strings to satisfy
- * @return an alpm_list_t* of missing dependencies strings
+/** Find a package satisfying a specified dependency.
+ * The dependency can include versions with depmod operators.
+ * @param pkgs an alpm_list_t* of pmpkg_t where the satisfier will be searched
+ * @param depstring package or provision name, versioned or not
+ * @return a pmpkg_t* satisfying depstring
*/
-alpm_list_t SYMEXPORT *alpm_deptest(pmdb_t *db, alpm_list_t *targets)
+pmpkg_t SYMEXPORT *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring)
{
- alpm_list_t *i, *ret = NULL;
-
- for(i = targets; i; i = alpm_list_next(i)) {
- pmdepend_t *dep;
- char *target;
-
- target = alpm_list_getdata(i);
- dep = _alpm_splitdep(target);
-
- if(!_alpm_find_dep_satisfier(_alpm_db_get_pkgcache(db), dep)) {
- ret = alpm_list_add(ret, target);
- }
- _alpm_dep_free(dep);
- }
- return(ret);
+ pmdepend_t *dep = _alpm_splitdep(depstring);
+ pmpkg_t *pkg = _alpm_find_dep_satisfier(pkgs, dep);
+ _alpm_dep_free(dep);
+ return(pkg);
}
/** Checks dependencies and returns missing ones in a list.
@@ -248,8 +236,8 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
targets = alpm_list_join(alpm_list_copy(remove), alpm_list_copy(upgrade));
for(i = pkglist; i; i = i->next) {
- void *pkg = i->data;
- if(alpm_list_find(targets, pkg, _alpm_pkg_cmp)) {
+ pmpkg_t *pkg = i->data;
+ if(_alpm_pkg_find(targets, pkg->name)) {
modified = alpm_list_add(modified, pkg);
} else {
dblist = alpm_list_add(dblist, pkg);
@@ -331,35 +319,45 @@ static int dep_vercmp(const char *version1, pmdepmod_t mod,
return(equal);
}
-int SYMEXPORT alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
+int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
{
alpm_list_t *i;
-
- ALPM_LOG_FUNC;
-
- const char *pkgname = alpm_pkg_get_name(pkg);
- const char *pkgversion = alpm_pkg_get_version(pkg);
+ const char *pkgname = pkg->name;
+ const char *pkgversion = pkg->version;
int satisfy = 0;
/* check (pkg->name, pkg->version) */
- satisfy = (strcmp(pkgname, dep->name) == 0
- && dep_vercmp(pkgversion, dep->mod, dep->version));
+ if(pkg->name_hash && dep->name_hash
+ && pkg->name_hash != dep->name_hash) {
+ /* skip more expensive checks */
+ } else {
+ satisfy = (strcmp(pkgname, dep->name) == 0
+ && dep_vercmp(pkgversion, dep->mod, dep->version));
+ if(satisfy) {
+ return(satisfy);
+ }
+ }
/* check provisions, format : "name=version" */
for(i = alpm_pkg_get_provides(pkg); i && !satisfy; i = i->next) {
- char *provname = strdup(i->data);
- char *provver = strchr(provname, '=');
+ const char *provision = i->data;
+ const char *provver = strchr(provision, '=');
if(provver == NULL) { /* no provision version */
satisfy = (dep->mod == PM_DEP_MOD_ANY
- && strcmp(provname, dep->name) == 0);
+ && strcmp(provision, dep->name) == 0);
} else {
- *provver = '\0';
+ /* This is a bit tricker than the old code for performance reasons. To
+ * prevent the need to copy and duplicate strings, strncmp only the name
+ * portion if they are the same length, since there is a version and
+ * operator in play here. Cast is to silence sign conversion warning;
+ * we know provver >= provision if we are here. */
+ size_t namelen = (size_t)(provver - provision);
provver += 1;
- satisfy = (strcmp(provname, dep->name) == 0
+ satisfy = (strlen(dep->name) == namelen
+ && strncmp(provision, dep->name, namelen) == 0
&& dep_vercmp(provver, dep->mod, dep->version));
}
- free(provname);
}
return(satisfy);
@@ -388,7 +386,8 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
depend->mod = PM_DEP_MOD_LE;
*ptr = '\0';
ptr += 2;
- } else if((ptr = strstr(newstr, "="))) { /* Note: we must do =,<,> checks after <=, >= checks */
+ } else if((ptr = strstr(newstr, "="))) {
+ /* Note: we must do =,<,> checks after <=, >= checks */
depend->mod = PM_DEP_MOD_EQ;
*ptr = '\0';
ptr += 1;
@@ -404,6 +403,7 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
/* no version specified - copy the name and return it */
depend->mod = PM_DEP_MOD_ANY;
STRDUP(depend->name, newstr, RET_ERR(PM_ERR_MEMORY, NULL));
+ depend->name_hash = _alpm_hash_sdbm(depend->name);
depend->version = NULL;
free(newstr);
return(depend);
@@ -412,6 +412,7 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
/* if we get here, we have a version comparator, copy the right parts
* to the right places */
STRDUP(depend->name, newstr, RET_ERR(PM_ERR_MEMORY, NULL));
+ depend->name_hash = _alpm_hash_sdbm(depend->name);
STRDUP(depend->version, ptr, RET_ERR(PM_ERR_MEMORY, NULL));
free(newstr);
@@ -424,6 +425,7 @@ pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep)
CALLOC(newdep, 1, sizeof(pmdepend_t), RET_ERR(PM_ERR_MEMORY, NULL));
STRDUP(newdep->name, dep->name, RET_ERR(PM_ERR_MEMORY, NULL));
+ newdep->name_hash = dep->name_hash;
STRDUP(newdep->version, dep->version, RET_ERR(PM_ERR_MEMORY, NULL));
newdep->mod = dep->mod;
@@ -525,7 +527,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(pkg, dep) && !_alpm_pkg_find(excluding, pkg->name)) {
if(_alpm_pkg_should_ignore(pkg)) {
int install = 0;
if (prompt) {
@@ -546,7 +548,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) &&
+ if(_alpm_depcmp(pkg, dep) && strcmp(pkg->name, dep->name) != 0 &&
!_alpm_pkg_find(excluding, pkg->name)) {
if(_alpm_pkg_should_ignore(pkg)) {
int install = 0;
@@ -672,7 +674,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(pkg2, i->data)) {
return(1);
}
}