Skip to content

Commit

Permalink
Add four new extension tags for pretty-formatting dependencies
Browse files Browse the repository at this point in the history
- The current method that --requires and friends use is kinda
  cumbersome and outputs extra whitespace for dependencies which
  dont have flags+version attached. Adding extensions for this
  is likely to be easier than teaching query formatting to
  permit conditionalizing on current value instead of just tag existence.
  • Loading branch information
pmatilai committed Sep 6, 2011
1 parent 31d807f commit 628ad2f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rpmtag.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ typedef enum rpmTag_e {
RPMTAG_MSSFMANIFEST = 5038, /* s[] reservation (unimplemented) */
RPMTAG_MSSFDOMAIN = 5039, /* s[] reservation (unimplemented) */
RPMTAG_INSTFILENAMES = 5040, /* s[] extension */
RPMTAG_REQUIRENEVRS = 5041, /* s[] extension */
RPMTAG_PROVIDENEVRS = 5042, /* s[] extension */
RPMTAG_OBSOLETENEVRS = 5043, /* s[] extension */
RPMTAG_CONFLICTNEVRS = 5044, /* s[] extension */

RPMTAG_FIRSTFREE_TAG /*!< internal */
} rpmTag;
Expand Down
45 changes: 45 additions & 0 deletions lib/tagexts.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,47 @@ static int epochnumTag(Header h, rpmtd td, headerGetFlags hgflags)
return 1;
}

static int depnevrsTag(Header h, rpmtd td, headerGetFlags hgflags,
rpmTagVal tag)
{
rpmds ds = rpmdsNew(h, tag, 0);
int ndeps = rpmdsCount(ds);

if (ndeps > 0) {
char **deps = xmalloc(sizeof(*deps) * ndeps);
int i;
while ((i = rpmdsNext(ds)) >= 0) {
deps[i] = rpmdsNewDNEVR(NULL, ds);
}
td->data = deps;
td->type = RPM_STRING_ARRAY_TYPE;
td->count = ndeps;
td->flags |= (RPMTD_ALLOCED | RPMTD_PTR_ALLOCED);
}
rpmdsFree(ds);
return (ndeps > 0);
}

static int requirenevrsTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return depnevrsTag(h, td, hgflags, RPMTAG_REQUIRENAME);
}

static int providenevrsTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return depnevrsTag(h, td, hgflags, RPMTAG_PROVIDENAME);
}

static int obsoletenevrsTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return depnevrsTag(h, td, hgflags, RPMTAG_OBSOLETENAME);
}

static int conflictnevrsTag(Header h, rpmtd td, headerGetFlags hgflags)
{
return depnevrsTag(h, td, hgflags, RPMTAG_CONFLICTNAME);
}

static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
{ RPMTAG_GROUP, groupTag },
{ RPMTAG_DESCRIPTION, descriptionTag },
Expand All @@ -751,6 +792,10 @@ static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
{ RPMTAG_VERBOSE, verboseTag },
{ RPMTAG_EPOCHNUM, epochnumTag },
{ RPMTAG_INSTFILENAMES, instfilenamesTag },
{ RPMTAG_REQUIRENEVRS, requirenevrsTag },
{ RPMTAG_PROVIDENEVRS, providenevrsTag },
{ RPMTAG_OBSOLETENEVRS, obsoletenevrsTag },
{ RPMTAG_CONFLICTNEVRS, conflictnevrsTag },
{ 0, NULL }
};

Expand Down
4 changes: 4 additions & 0 deletions tests/rpmgeneral.at
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ CLASSDICT
COLLECTIONS
CONFLICTFLAGS
CONFLICTNAME
CONFLICTNEVRS
CONFLICTS
CONFLICTVERSION
COOKIE
Expand Down Expand Up @@ -142,6 +143,7 @@ NVRA
O
OBSOLETEFLAGS
OBSOLETENAME
OBSOLETENEVRS
OBSOLETES
OBSOLETEVERSION
OLDFILENAMES
Expand Down Expand Up @@ -191,6 +193,7 @@ PREUNFLAGS
PREUNPROG
PROVIDEFLAGS
PROVIDENAME
PROVIDENEVRS
PROVIDES
PROVIDEVERSION
PUBKEYS
Expand All @@ -200,6 +203,7 @@ RELEASE
REMOVETID
REQUIREFLAGS
REQUIRENAME
REQUIRENEVRS
REQUIRES
REQUIREVERSION
RPMVERSION
Expand Down

0 comments on commit 628ad2f

Please sign in to comment.