Skip to content

Commit

Permalink
Rename map_pkg_to_dep() to find_pkg_match().
Browse files Browse the repository at this point in the history
The latter is a bit more descriptive and easier to follow.  Update the
function documentation while here, and convert a DEBUG printf to a
TRACE().
  • Loading branch information
Jonathan Perkin committed May 26, 2020
1 parent 4011dd3 commit f80e1e5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions depends.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ show_direct_depends(const char *pkgarg)
printf(MSG_DIRECT_DEPS_FOR, pkgname);
SLIST_FOREACH(pdp, deptreehead, next) {
if (package_version &&
(rpkg = map_pkg_to_dep(&r_plisthead, pdp->depend))
(rpkg = find_pkg_match(&r_plisthead, pdp->depend))
!= NULL)
printf("\t%s\n", rpkg->full);
else
Expand Down Expand Up @@ -208,7 +208,7 @@ show_full_dep_tree(const char *pkgarg, const char *depquery, const char *msg)

SLIST_FOREACH(pdp, deptreehead, next) {
if (package_version &&
(rpkg = map_pkg_to_dep(plisthead, pdp->depend)) != NULL)
(rpkg = find_pkg_match(plisthead, pdp->depend)) != NULL)
printf("\t%s\n", rpkg->full);
else
printf("\t%s\n", pdp->depend);
Expand Down
2 changes: 1 addition & 1 deletion impact.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ deps_impact(Plisthead *impacthead, Pkglist *pdp)
return 1;

/* record corresponding package on remote list*/
if ((rpkg = map_pkg_to_dep(&r_plisthead, pdp->depend)) == NULL)
if ((rpkg = find_pkg_match(&r_plisthead, pdp->depend)) == NULL)
return 1; /* no corresponding package in list */

XSTRCPY(remotepkg, rpkg->full);
Expand Down
17 changes: 9 additions & 8 deletions pkg_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,20 @@ unique_pkg(const char *pkgname, const char *dest)
return u_pkg;
}

/* return a pkgname corresponding to a dependency */
/*
* Return first matching SLIST entry in package list, or NULL if no match.
*/
Pkglist *
map_pkg_to_dep(Plisthead *plisthead, char *depname)
find_pkg_match(Plisthead *plisthead, char *match)
{
Pkglist *plist;

SLIST_FOREACH(plist, plisthead, next)
if (pkg_match(depname, plist->full)) {
#ifdef DEBUG
printf("match ! %s -> %s\n", depname, plist->full);
#endif
SLIST_FOREACH(plist, plisthead, next) {
if (pkg_match(match, plist->full)) {
TRACE("Matched %s with %s\n", match, plist->full);
return plist;
}
}

return NULL;
}
Expand Down Expand Up @@ -332,7 +333,7 @@ glob_to_pkgarg(char **globpkg, int *rc)
if (strpbrk(globpkg[i], GLOBCHARS) == NULL)
pkgargs[count] = xstrdup(globpkg[i]);
else {
if ((plist = map_pkg_to_dep(&r_plisthead,
if ((plist = find_pkg_match(&r_plisthead,
globpkg[i])) == NULL) {
fprintf(stderr, MSG_PKG_NOT_AVAIL, globpkg[i]);
count--;
Expand Down
2 changes: 1 addition & 1 deletion pkgin.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ char *read_repos(void);
/* pkg_str.c */
int find_preferred_pkg(const char *, char **);
char *unique_pkg(const char *, const char *);
Pkglist *map_pkg_to_dep(Plisthead *, char *);
Pkglist *find_pkg_match(Plisthead *, char *);
uint8_t non_trivial_glob(char *);
char *get_pkgname_from_depend(char *);
int exact_pkgfmt(const char *);
Expand Down
2 changes: 1 addition & 1 deletion sqlite_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pdb_rec_depends(void *param, int argc, char **argv, char **colname)
plisthead = &r_plisthead;

/* map corresponding pkgname */
if ((pkg_map = map_pkg_to_dep(plisthead, deptree->depend)) != NULL)
if ((pkg_map = find_pkg_match(plisthead, deptree->depend)) != NULL)
deptree->name = xstrdup(pkg_map->name);
else
/* some dependencies just don't match anything */
Expand Down

0 comments on commit f80e1e5

Please sign in to comment.