From 240bdf59713e85bc3d3a3335cf69c2bb9003369a Mon Sep 17 00:00:00 2001
From: Chantry Xavier <shiningxc@gmail.com>
Date: Mon, 16 Jul 2007 18:27:42 +0200
Subject: libalpm/deps.c : split alpm_depcmp.

That function wasn't big, but this might be useful
for later refactoring of the search for satisfier code.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
---
 lib/libalpm/deps.c | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

(limited to 'lib')

diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index cd20dd5c..67cfb0f9 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -443,25 +443,38 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
 	return(baddeps);
 }
 
+static int _alpm_dep_vercmp(const char *version1, pmdepmod_t mod,
+		const char *version2)
+{
+	int equal = 0;
+
+	if(mod == PM_DEP_MOD_ANY) {
+		equal = 1;
+	} else {
+		int cmp = _alpm_versioncmp(version1, version2);
+		switch(mod) {
+			case PM_DEP_MOD_EQ: equal = (cmp == 0); break;
+			case PM_DEP_MOD_GE: equal = (cmp >= 0); break;
+			case PM_DEP_MOD_LE: equal = (cmp <= 0); break;
+			default: equal = 1; break;
+		}
+	}
+	return(equal);
+}
+
 int SYMEXPORT alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
 {
 	int equal = 0;
 
 	ALPM_LOG_FUNC;
 
-  if(strcmp(pkg->name, dep->name) == 0
-	    || alpm_list_find_str(alpm_pkg_get_provides(pkg), dep->name)) {
-		if(dep->mod == PM_DEP_MOD_ANY) {
-			equal = 1;
-		} else {
-			int cmp = _alpm_versioncmp(alpm_pkg_get_version(pkg), dep->version);
-			switch(dep->mod) {
-				case PM_DEP_MOD_EQ: equal = (cmp == 0); break;
-				case PM_DEP_MOD_GE: equal = (cmp >= 0); break;
-				case PM_DEP_MOD_LE: equal = (cmp <= 0); break;
-				default: equal = 1; break;
-			}
-		}
+	const char *pkgname = alpm_pkg_get_name(pkg);
+	const char *pkgversion = alpm_pkg_get_version(pkg);
+
+	if(strcmp(pkgname, dep->name) == 0
+			|| alpm_list_find_str(alpm_pkg_get_provides(pkg), dep->name)) {
+
+		equal = _alpm_dep_vercmp(pkgversion, dep->mod, dep->version);
 
 		char *mod = "~=";
 		switch(dep->mod) {
@@ -473,16 +486,16 @@ int SYMEXPORT alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
 
 		if(strlen(dep->version) > 0) {
 			_alpm_log(PM_LOG_DEBUG, "depcmp: %s-%s %s %s-%s => %s",
-								alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
+								pkgname, pkgversion,
 								mod, dep->name, dep->version, (equal ? "match" : "no match"));
 		} else {
 			_alpm_log(PM_LOG_DEBUG, "depcmp: %s-%s %s %s => %s",
-								alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
+								pkgname, pkgversion,
 								mod, dep->name, (equal ? "match" : "no match"));
 		}
 	}
 
-	return equal;
+	return(equal);
 }
 
 pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
-- 
cgit v1.2.3-70-g09d2