lib: Add rpm_ostree_package_cmp()
Equivalent to hy_package_cmp(), but works for comparing packages from different memory pools. This a stop gap measure in light of https://github.com/rpm-software-management/hawkey/pull/90 If and when that pull request gets merged, then this function could at some later point simply call hy_package_cmp().
This commit is contained in:
parent
1c3a549ef9
commit
03b886dae0
@ -11,4 +11,5 @@ rpm_ostree_package_get_name
|
|||||||
rpm_ostree_package_get_evr
|
rpm_ostree_package_get_evr
|
||||||
rpm_ostree_package_get_arch
|
rpm_ostree_package_get_arch
|
||||||
rpm_ostree_package_get_nevra
|
rpm_ostree_package_get_nevra
|
||||||
|
rpm_ostree_package_cmp
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
@ -125,6 +125,51 @@ rpm_ostree_package_get_arch (RpmOstreePackage *p)
|
|||||||
return hy_package_get_arch (p->hypkg);
|
return hy_package_get_arch (p->hypkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rpm_ostree_package_cmp:
|
||||||
|
* @p1: Package
|
||||||
|
* @p2: Package
|
||||||
|
*
|
||||||
|
* Compares two packages by name, epoch:version-release and architecture.
|
||||||
|
*
|
||||||
|
* Returns: an integer suitable for sorting functions; negative if @p1 should
|
||||||
|
* sort before @p2 in name or version, 0 if equal, positive if @p1
|
||||||
|
* should sort after @p2
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
rpm_ostree_package_cmp (RpmOstreePackage *p1, RpmOstreePackage *p2)
|
||||||
|
{
|
||||||
|
/* XXX This is equivalent to hy_package_cmp(), but works
|
||||||
|
* for comparing packages from different memory pools.
|
||||||
|
*
|
||||||
|
* See https://github.com/rpm-software-management/hawkey/pull/90
|
||||||
|
*/
|
||||||
|
|
||||||
|
const char *str1, *str2;
|
||||||
|
gint ret;
|
||||||
|
|
||||||
|
str1 = rpm_ostree_package_get_name (p1);
|
||||||
|
str2 = rpm_ostree_package_get_name (p2);
|
||||||
|
ret = strcmp (str1, str2);
|
||||||
|
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
str1 = rpm_ostree_package_get_evr (p1);
|
||||||
|
str2 = rpm_ostree_package_get_evr (p2);
|
||||||
|
|
||||||
|
/* This assumes both pools (if they are different)
|
||||||
|
* have identical configuration for epoch handling. */
|
||||||
|
ret = hy_sack_evr_cmp (p1->sack->sack, str1, str2);
|
||||||
|
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
str1 = rpm_ostree_package_get_arch (p1);
|
||||||
|
str2 = rpm_ostree_package_get_arch (p2);
|
||||||
|
return strcmp (str1, str2);
|
||||||
|
}
|
||||||
|
|
||||||
RpmOstreePackage *
|
RpmOstreePackage *
|
||||||
_rpm_ostree_package_new (RpmOstreeRefSack *rsack, HyPackage hypkg)
|
_rpm_ostree_package_new (RpmOstreeRefSack *rsack, HyPackage hypkg)
|
||||||
{
|
{
|
||||||
|
@ -44,3 +44,5 @@ const char *rpm_ostree_package_get_evr (RpmOstreePackage *p);
|
|||||||
_RPMOSTREE_EXTERN
|
_RPMOSTREE_EXTERN
|
||||||
const char *rpm_ostree_package_get_arch (RpmOstreePackage *p);
|
const char *rpm_ostree_package_get_arch (RpmOstreePackage *p);
|
||||||
|
|
||||||
|
_RPMOSTREE_EXTERN
|
||||||
|
int rpm_ostree_package_cmp (RpmOstreePackage *p1, RpmOstreePackage *p2);
|
||||||
|
Loading…
Reference in New Issue
Block a user