razor.c
changeset 133 ab28214596aa
parent 130 10e6914910dd
parent 131 1b5338bcb7d1
child 134 a3672fc689b7
     1.1 --- a/razor.c	Fri Feb 22 12:49:13 2008 -0500
     1.2 +++ b/razor.c	Tue Feb 26 13:47:31 2008 -0500
     1.3 @@ -1740,7 +1740,8 @@
     1.4  	upool = upstream->string_pool.data;
     1.5  	package_pool = &upstream->package_pool;
     1.6  
     1.7 -	for (u = unsatisfied->data; u < end; u++) {
     1.8 +	u = unsatisfied->data;
     1.9 +	while (u < end) {
    1.10  		r = requires + *u;
    1.11  
    1.12  		while (p < pend &&
    1.13 @@ -1752,18 +1753,23 @@
    1.14  		while (p + 1 < pend && p->name == (p + 1)->name && p->type == (p + 1)->type)
    1.15  			p++;
    1.16  
    1.17 -		if (p == pend ||
    1.18 -		    strcmp(&pool[r->name], &upool[p->name]) != 0 ||
    1.19 -		    versioncmp(&pool[r->version], &upool[p->version]) > 0) {
    1.20 -			/* Do we need to track unsatisfiable requires
    1.21 -			 * as we go, or should we just do a
    1.22 -			 * razor_set_validate() at the end? */
    1.23 -		} else {
    1.24 +		if (p != pend &&
    1.25 +		    p->type == RAZOR_PROPERTY_PROVIDES &&
    1.26 +		    strcmp(&pool[r->name], &upool[p->name]) == 0 &&
    1.27 +		    versioncmp(&pool[r->version], &upool[p->version]) <= 0) {
    1.28  			pkg = array_add(list, sizeof *pkg);
    1.29  			/* We just pull in the first package that provides */
    1.30  			*pkg = list_first(&p->packages, package_pool)->data;
    1.31 +
    1.32 +			/* Remove this from the unsatisfied list */
    1.33 +			memmove (u, u + 1, end - (u + 1));
    1.34 +			end--;
    1.35 +		} else {
    1.36 +			/* Leave this in the unsatisfied list */
    1.37 +			u++;
    1.38  		}
    1.39 -	}	
    1.40 +	}
    1.41 +	unsatisfied->size = (void *)end - unsatisfied->data;
    1.42  }
    1.43  
    1.44  static void
    1.45 @@ -1816,12 +1822,50 @@
    1.46  	}
    1.47  }
    1.48  
    1.49 +/* FIXME: this is all wrong anyway; we should recompute the new_unsatisfied
    1.50 + * set as we add and remove packages...
    1.51 + */
    1.52 +static void
    1.53 +razor_set_revalidate(struct razor_set *orig_set,
    1.54 +		     struct array *orig_unsatisfied,
    1.55 +		     struct razor_set *new_set,
    1.56 +		     struct array *new_unsatisfied)
    1.57 +{
    1.58 +	uint32_t *nu, *nuend, *ou, *ouend;
    1.59 +	struct razor_property *new_props, *orig_props;
    1.60 +	char *new_pool, *orig_pool;
    1.61 +
    1.62 +	razor_set_validate(new_set, new_unsatisfied);
    1.63 +
    1.64 +	ouend = orig_unsatisfied->data + orig_unsatisfied->size;
    1.65 +	nuend = new_unsatisfied->data + new_unsatisfied->size;
    1.66 +	new_props = new_set->properties.data;
    1.67 +	orig_props = orig_set->properties.data;
    1.68 +	new_pool = new_set->string_pool.data;
    1.69 +	orig_pool = orig_set->string_pool.data;
    1.70 +
    1.71 +	for (nu = new_unsatisfied->data; nu < nuend; nu++) {
    1.72 +		for (ou = orig_unsatisfied->data; ou < ouend; ou++) {
    1.73 +			if (!strcmp (&new_pool[new_props[*nu].name],
    1.74 +				     &orig_pool[orig_props[*ou].name]) &&
    1.75 +			    new_props[*nu].relation == orig_props[*ou].relation &&
    1.76 +			    !strcmp (&new_pool[new_props[*nu].version],
    1.77 +				     &orig_pool[orig_props[*ou].version])) {
    1.78 +				*(nu--) = *(--nuend);
    1.79 +				break;
    1.80 +			}
    1.81 +		}
    1.82 +	}
    1.83 +
    1.84 +	new_unsatisfied->size = (void *)nuend - new_unsatisfied->data;
    1.85 +}
    1.86 +
    1.87  struct razor_set *
    1.88  razor_set_update(struct razor_set *set, struct razor_set *upstream,
    1.89  		 int count, const char **packages)
    1.90  {
    1.91  	struct razor_set *new;
    1.92 -	struct array list, unsatisfied;
    1.93 +	struct array list, unsatisfied_before, unsatisfied;
    1.94  
    1.95  	array_init(&list);
    1.96  	if (count > 0)
    1.97 @@ -1829,20 +1873,35 @@
    1.98  	else
    1.99  		find_all_packages(set, upstream, &list);
   1.100  
   1.101 +	array_init(&unsatisfied_before);
   1.102 +	razor_set_validate(set, &unsatisfied_before);
   1.103 +
   1.104  	while (list.size > 0) {
   1.105  		new = razor_set_add(set, upstream, &list);
   1.106  		array_release(&list);
   1.107 +
   1.108 +		array_init(&unsatisfied);
   1.109 +		razor_set_revalidate(set, &unsatisfied_before,
   1.110 +				     new, &unsatisfied);
   1.111 +
   1.112 +		array_init(&list);
   1.113 +		razor_set_satisfy(new, &unsatisfied, upstream, &list);
   1.114 +
   1.115 +		if (unsatisfied.size) {
   1.116 +			/* FIXME: need to return this list */
   1.117 +			array_release(&unsatisfied);
   1.118 +			razor_set_destroy(new);
   1.119 +			razor_set_destroy(set);
   1.120 +			set = NULL;
   1.121 +			break;
   1.122 +		}
   1.123 +
   1.124  		razor_set_destroy(set);
   1.125  		set = new;
   1.126 -
   1.127 -		array_init(&unsatisfied);
   1.128 -		razor_set_validate(new, &unsatisfied);
   1.129 -		array_init(&list);
   1.130 -		razor_set_satisfy(new, &unsatisfied, upstream, &list);
   1.131 -		array_release(&unsatisfied);
   1.132  	}
   1.133  
   1.134  	array_release(&list);
   1.135 +	array_release(&unsatisfied_before);
   1.136  
   1.137  	return set;
   1.138  }