fragment: add pkg_fragment_exists() and use it to mergemaster in pkg_fragment_copy().

feature/tap-sh
William Pitcock 2012-05-03 20:43:09 +00:00
parent a4a572f608
commit 26c5dcb125
2 changed files with 21 additions and 0 deletions

View File

@ -66,11 +66,31 @@ pkg_fragment_add(pkg_fragment_t *head, const char *string)
return pkg_fragment_append(head, frag);
}
bool
pkg_fragment_exists(pkg_fragment_t *head, pkg_fragment_t *base)
{
pkg_fragment_t *node;
foreach_list_entry(head, node)
{
if (base->type != node->type)
continue;
if (!strcmp(base->data, node->data))
return true;
}
return false;
}
pkg_fragment_t *
pkg_fragment_copy(pkg_fragment_t *head, pkg_fragment_t *base)
{
pkg_fragment_t *frag;
if (pkg_fragment_exists(head, base))
return head;
frag = calloc(sizeof(pkg_fragment_t), 1);
frag->type = base->type;

1
pkg.h
View File

@ -138,5 +138,6 @@ pkg_fragment_t *pkg_fragment_append(pkg_fragment_t *head, pkg_fragment_t *tail);
pkg_fragment_t *pkg_fragment_add(pkg_fragment_t *head, const char *string);
pkg_fragment_t *pkg_fragment_copy(pkg_fragment_t *head, pkg_fragment_t *base);
void pkg_fragment_delete(pkg_fragment_t *node);
bool pkg_fragment_exists(pkg_fragment_t *head, pkg_fragment_t *base);
#endif