Hi guys!

Can someone give me write access to pacman git (Dan?), so I don't have
to send every patch to the list :)

Anyways, I took a bit of time to start writing tag support for pacman
and makepkg, which is usefull now we don't have categories anymore
like we had before (and still have for community).
You should be warned that I did not yet do a code cleanup (that will
come when all features are in), but it is starting to get a bit messy
with patch files on my local box so I like to commit.

I guess the patch should work both against pacman git and 3.2.0 at the moment.

How does it work?

in PKGBUILD, define a field called tags, for example:
tags=('gnome' 'gtk' 'network' 'messenger')

compile with makepkg as usual. Install with pacman with attached patch applied.
the tags field should show up in 'pacman -Qi'.

Further you can search the local database (only long option is
working, short option not yet, have to look into it). You can search
with (multiple tags works):
pacman -Q --tags gnome

My little TODO list  for next pacman release:

- be able to search for tags in the repos
- get short options working
- write proper documentation
- cleanup

So please patch it into git, or better give me access. Any comments are welcome.

Regards,

Ronald
--- scripts/makepkg.sh.in.old	2008-08-20 18:06:37.000000000 +0200
+++ scripts/makepkg.sh.in	2008-08-20 18:06:28.000000000 +0200
@@ -819,6 +819,9 @@
 	for it in "[EMAIL PROTECTED]"; do
 		echo "backup = $it" >>.PKGINFO
 	done
+        for it in "[EMAIL PROTECTED]"; do
+		echo "tag = $it" >> .PKGINFO
+	done
 
 	# TODO maybe remove this at some point
 	# warn if license array is not present or empty
@@ -1288,7 +1291,7 @@
 
 unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums
 unset replaces depends conflicts backup source install build makedepends
-unset optdepends options noextract
+unset optdepends options noextract tags
 
 if [ ! -f "$BUILDSCRIPT" ]; then
 	error "$(gettext "%s does not exist.")" "$BUILDSCRIPT"
--- src/pacman/package.c.old	2008-08-20 18:23:10.000000000 +0200
+++ src/pacman/package.c	2008-08-20 18:25:26.000000000 +0200
@@ -98,6 +98,7 @@
 	list_display(_("Provides       :"), alpm_pkg_get_provides(pkg));
 	list_display(_("Depends On     :"), depstrings);
 	list_display(_("Optional Deps  :"), alpm_pkg_get_optdepends(pkg));
+	list_display(_("Tags           :"), alpm_pkg_get_tags(pkg));
 	/* Only applicable if installed */
 	if(level > 0) {
 		list_display(_("Required By    :"), requiredby);
--- lib/libalpm/package.c.old	2008-08-20 18:31:58.000000000 +0200
+++ lib/libalpm/package.c	2008-08-20 18:37:41.000000000 +0200
@@ -281,6 +281,21 @@
 	return pkg->licenses;
 }
 
+alpm_list_t SYMEXPORT *alpm_pkg_get_tags(pmpkg_t *pkg)
+{
+        ALPM_LOG_FUNC;
+
+        /* Sanity checks */
+        ASSERT(handle != NULL, return(NULL));
+        ASSERT(pkg != NULL, return(NULL));
+
+        if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+                _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
+        }
+        return pkg->tags;
+}
+
+
 alpm_list_t SYMEXPORT *alpm_pkg_get_groups(pmpkg_t *pkg)
 {
 	ALPM_LOG_FUNC;
@@ -770,6 +785,7 @@
 	newpkg->replaces   = alpm_list_strdup(pkg->replaces);
 	newpkg->groups     = alpm_list_strdup(pkg->groups);
 	newpkg->files      = alpm_list_strdup(pkg->files);
+	newpkg->tags	   = alpm_list_strdup(pkg->tags);
 	newpkg->backup     = alpm_list_strdup(pkg->backup);
 	for(i = pkg->depends; i; i = alpm_list_next(i)) {
 		newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
@@ -808,6 +824,7 @@
 	FREE(pkg->md5sum);
 	FREE(pkg->arch);
 	FREELIST(pkg->licenses);
+	FREELIST(pkg->tags);
 	FREELIST(pkg->replaces);
 	FREELIST(pkg->groups);
 	FREELIST(pkg->files);

--- lib/libalpm/package.h.old	2008-08-20 18:40:22.000000000 +0200
+++ lib/libalpm/package.h	2008-08-20 18:40:04.000000000 +0200
@@ -52,6 +52,7 @@
 	unsigned short force;
 	pmpkgreason_t reason;
 	alpm_list_t *licenses;
+	alpm_list_t *tags;
 	alpm_list_t *replaces;
 	alpm_list_t *groups;
 	alpm_list_t *files;
--- lib/libalpm/alpm.h	2008-08-20 19:04:40.000000000 +0200
+++ lib/libalpm/alpm.new	2008-08-20 19:00:59.000000000 +0200
@@ -209,6 +209,7 @@
 off_t alpm_pkg_get_isize(pmpkg_t *pkg);
 pmpkgreason_t alpm_pkg_get_reason(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_licenses(pmpkg_t *pkg);
+alpm_list_t *alpm_pkg_get_tags(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_groups(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_depends(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_optdepends(pmpkg_t *pkg);

--- lib/libalpm/be_files.c	2008-08-20 19:04:40.000000000 +0200
+++ lib/libalpm/be_files.c.new	2008-08-20 19:01:08.000000000 +0200
@@ -454,6 +454,12 @@
 					STRDUP(linedup, _alpm_strtrim(line), goto error);
 					info->licenses = alpm_list_add(info->licenses, linedup);
 				}
+			} else if(strcmp(line, "%TAG%") == 0) {
+                                while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
+                                        char *linedup;
+                                        STRDUP(linedup, _alpm_strtrim(line), goto error);
+                                        info->tags = alpm_list_add(info->tags, linedup);
+                                }
 			} else if(strcmp(line, "%ARCH%") == 0) {
 				if(fgets(line, 512, fp) == NULL) {
 					goto error;
@@ -721,6 +727,14 @@
 				}
 				fprintf(fp, "\n");
 			}
+			if(info->tags) {
+                                fputs("%TAG%\n", fp);
+                                for(lp = info->tags; lp; lp = lp->next) {
+                                        fprintf(fp, "%s\n", (char *)lp->data);
+                                }
+                                fprintf(fp, "\n");
+                        }
+
 			if(info->arch) {
 				fprintf(fp, "%%ARCH%%\n"
 								"%s\n\n", info->arch);

--- lib/libalpm/be_package.c	2008-08-20 19:04:40.000000000 +0200
+++ lib/libalpm/be_package.c.new	2008-08-20 19:01:16.000000000 +0200
@@ -80,6 +80,8 @@
 				STRDUP(newpkg->url, ptr, RET_ERR(PM_ERR_MEMORY, -1));
 			} else if(!strcmp(key, "license")) {
 				newpkg->licenses = alpm_list_add(newpkg->licenses, strdup(ptr));
+			} else if(!strcmp(key, "tag")) {
+                                newpkg->tags = alpm_list_add(newpkg->tags, strdup(ptr));
 			} else if(!strcmp(key, "builddate")) {
 				char first = tolower(ptr[0]);
 				if(first > 'a' && first < 'z') {
--- src/pacman/query.c	2008-08-20 17:55:10.000000000 +0200
+++ src/pacman/query.c.new	2008-08-20 19:27:19.000000000 +0200
@@ -251,6 +251,48 @@
 	return ret;
 }
 
+static int query_tag(alpm_list_t *targets)
+{
+	alpm_list_t *i, *j;
+	char *tagname = NULL;
+	int ret = 0;
+	if(targets == NULL) {
+		for(j = alpm_db_gettagcache(db_local); j; j = alpm_list_next(j)) {
+			pmtag_t *tag = alpm_list_getdata(j);
+			const alpm_list_t *p, *packages;
+			const char *tagname;
+
+			tagname = alpm_tag_get_name(tag);
+			packages = alpm_tag_get_pkgs(tag);
+
+			for(p = packages; p; p = alpm_list_next(p)) {
+				printf("%s %s\n", tagname, alpm_pkg_get_name(alpm_list_getdata(p)));
+			}
+		}
+	} else {
+		for(i = targets; i; i = alpm_list_next(i)) {
+			pmtag_t *tag;
+			tagname = alpm_list_getdata(i);
+			tag = alpm_db_readtag(db_local, tagname);
+			if(tag) {
+				const alpm_list_t *p, *packages = alpm_tag_get_pkgs(tag);
+				for(p = packages; p; p = alpm_list_next(p)) {
+					if(!config->quiet) {
+						printf("%s %s\n", tagname,
+								alpm_pkg_get_name(alpm_list_getdata(p)));
+					} else {
+						printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(p)));
+					}
+				}
+			} else {
+				pm_fprintf(stderr, PM_LOG_ERROR, _("tag \"%s\" was not found\n"), tagname);
+				ret++;
+			}
+		}
+	}
+	return ret;
+}
+
 static int query_upgrades(void)
 {
 	alpm_list_t *syncpkgs = NULL;
@@ -373,6 +415,12 @@
 		return(ret);
 	}
 
+	/* looking for tags */
+	if(config->tag) {
+		ret = query_tag(targets);
+		return(ret);
+	}
+
 	if(config->op_q_foreign) {
 		/* ensure we have at least one valid sync db set up */
 		alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
--- src/pacman/pacman.c.old	2008-08-20 19:28:09.000000000 +0200
+++ src/pacman/pacman.c	2008-08-20 19:31:41.000000000 +0200
@@ -104,7 +104,8 @@
 			printf(_("  -d, --deps           list all packages installed as dependencies\n"));
 			printf(_("  -e, --explicit       list all packages explicitly installed\n"));
 			printf(_("  -g, --groups         view all members of a package group\n"));
-			printf(_("  -i, --info           view package information (-ii for backup files)\n"));
+			printf(_("  -x, --tags           view all members of a tag\n"));
+		  	printf(_("  -i, --info           view package information (-ii for backup files)\n"));
 			printf(_("  -l, --list           list the contents of the queried package\n"));
 			printf(_("  -m, --foreign        list installed packages not found in sync db(s)\n"));
 			printf(_("  -o, --owns <file>    query the package that owns <file>\n"));
@@ -323,6 +324,7 @@
 		{"explicit",   no_argument,       0, 'e'},
 		{"force",      no_argument,       0, 'f'},
 		{"groups",     no_argument,       0, 'g'},
+		{"tags",       no_argument,       0, 'x'},
 		{"help",       no_argument,       0, 'h'},
 		{"info",       no_argument,       0, 'i'},
 		{"dbonly",     no_argument,       0, 'k'},
@@ -452,7 +454,8 @@
 				break;
 			case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
 			case 'g': (config->group)++; break;
-			case 'h': config->help = 1; break;
+                       case 'x': (config->tag)++; break;
+                       case 'h': config->help = 1; break;
 			case 'i': (config->op_q_info)++; (config->op_s_info)++; break;
 			case 'k': config->flags |= PM_TRANS_FLAG_DBONLY; break;
 			case 'l': config->op_q_list = 1; break;

--- src/pacman/conf.h.old	2008-08-20 19:39:49.000000000 +0200
+++ src/pacman/conf.h	2008-08-20 19:40:02.000000000 +0200
@@ -59,6 +59,8 @@
 	unsigned short op_s_upgrade;
 
 	unsigned short group;
+	unsigned short tag;
+
 	pmtransflag_t flags;
 
 	/* conf file options */
--- lib/libalpm/db.c.old	2008-08-20 20:11:24.000000000 +0200
+++ lib/libalpm/db.c	2008-08-20 20:22:47.000000000 +0200
@@ -306,7 +306,37 @@
 
 	return(_alpm_db_get_grpcache(db));
 }
+/** Get a tag entry from a package database
+ * @param db pointer to the package database to get the tag from
+ * @param name of the ta
+ * @return the tag entry on success, NULL on error
+ */
+pmtag_t SYMEXPORT *alpm_db_readtag(pmdb_t *db, const char *name)
+{
+	ALPM_LOG_FUNC;
+
+	/* Sanity checks */
+	ASSERT(handle != NULL, return(NULL));
+	ASSERT(db != NULL, return(NULL));
+	ASSERT(name != NULL && strlen(name) != 0, return(NULL));
+
+	return(_alpm_db_get_tagfromcache(db, name));
+}
 
+/** Get the group cache of a package database
+ * @param db pointer to the package database to get the group from
+ * @return the list of groups on success, NULL on error
+ */
+alpm_list_t SYMEXPORT *alpm_db_gettagcache(pmdb_t *db)
+{
+	ALPM_LOG_FUNC;
+
+	/* Sanity checks */
+	ASSERT(handle != NULL, return(NULL));
+	ASSERT(db != NULL, return(NULL));
+
+	return(_alpm_db_get_tagcache(db));
+}
 /** Searches a database
  * @param db pointer to the package database to search in
  * @param needles the list of strings to search for

--- lib/libalpm/db.h.old	2008-08-20 20:11:28.000000000 +0200
+++ lib/libalpm/db.h	2008-08-20 20:23:15.000000000 +0200
@@ -44,6 +44,7 @@
 	void *handle;
 	alpm_list_t *pkgcache;
 	alpm_list_t *grpcache;
+        alpm_list_t *tagcache;
 	alpm_list_t *servers;
 };
 
--- lib/libalpm/alpm.h.old	2008-08-20 20:11:03.000000000 +0200
+++ lib/libalpm/alpm.h	2008-08-20 20:26:53.000000000 +0200
@@ -46,6 +46,7 @@
 typedef struct __pmpkg_t pmpkg_t;
 typedef struct __pmdelta_t pmdelta_t;
 typedef struct __pmgrp_t pmgrp_t;
+typedef struct __pmtag_t pmtag_t;
 typedef struct __pmtrans_t pmtrans_t;
 typedef struct __pmsyncpkg_t pmsyncpkg_t;
 typedef struct __pmdepend_t pmdepend_t;
@@ -174,6 +175,8 @@
 
 pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name);
 alpm_list_t *alpm_db_getgrpcache(pmdb_t *db);
+pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name);
+alpm_list_t *alpm_db_getgrpcache(pmdb_t *db);
 alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles);
 
 /*
@@ -210,6 +213,7 @@
 pmpkgreason_t alpm_pkg_get_reason(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_licenses(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_groups(pmpkg_t *pkg);
+alpm_list_t *alpm_pkg_get_tags(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_depends(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_optdepends(pmpkg_t *pkg);
 alpm_list_t *alpm_pkg_get_conflicts(pmpkg_t *pkg);
@@ -245,6 +249,13 @@
 const char *alpm_grp_get_name(const pmgrp_t *grp);
 alpm_list_t *alpm_grp_get_pkgs(const pmgrp_t *grp);
 
+
+/*
+ * Tags
+ */
+const char *alpm_tag_get_name(const pmtag_t *tag);
+alpm_list_t *alpm_tag_get_pkgs(const pmtag_t *tag);
+
 /*
  * Sync
  */
@@ -293,6 +304,10 @@
  * @{
  */
 /**
+ * @addtotag alpm_trans
+ * @{
+ */
+/**
  * @brief Transaction events.
  * NULL parameters are passed to in all events unless specified otherwise.
  */
@@ -517,6 +532,8 @@
 	PM_ERR_DLT_PATCHFAILED,
 	/* Groups */
 	PM_ERR_GRP_NOT_FOUND,
+	/* Tags */
+	PM_ERR_TAG_NOT_FOUND,
 	/* Dependencies */
 	PM_ERR_UNSATISFIED_DEPS,
 	PM_ERR_CONFLICTING_DEPS,

--- lib/libalpm/cache.h.old	2008-08-20 20:11:20.000000000 +0200
+++ lib/libalpm/cache.h	2008-08-20 20:37:19.000000000 +0200
@@ -22,6 +22,7 @@
 #include "db.h"
 #include "alpm_list.h"
 #include "group.h"
+#include "tag.h"
 #include "package.h"
 
 /* packages */
@@ -37,7 +38,11 @@
 void _alpm_db_free_grpcache(pmdb_t *db);
 alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db);
 pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target);
-
+/* tags */
+int _alpm_db_load_tagcache(pmdb_t *db);
+void _alpm_db_free_tagcache(pmdb_t *db);
+alpm_list_t *_alpm_db_get_tagcache(pmdb_t *db);
+pmtag_t *_alpm_db_get_tagfromcache(pmdb_t *db, const char *target);
 #endif /* _ALPM_CACHE_H */
 
 /* vim: set ts=2 sw=2 noet: */
--- lib/libalpm/tag.h.old	2008-08-20 20:40:34.000000000 +0200
+++ lib/libalpm/tag.h	2008-08-20 20:40:19.000000000 +0200
@@ -0,0 +1,36 @@
+/*
+ *  tag.h
+ *
+ *  Copyright (c) 2002-2007 by Judd Vinet <[EMAIL PROTECTED]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _ALPM_TAG_H
+#define _ALPM_TAG_H
+
+#include "alpm.h"
+
+struct __pmtag_t {
+	/** tag name */
+	char *name;
+	/** list of pmpkg_t packages */
+	alpm_list_t *packages;
+};
+
+pmtag_t *_alpm_tag_new(const char *name);
+void _alpm_tag_free(pmtag_t *tag);
+
+#endif /* _ALPM_TAG_H */
+
+/* vim: set ts=2 sw=2 noet: */

--- lib/libalpm/tag.c.old	2008-08-20 20:40:30.000000000 +0200
+++ lib/libalpm/tag.c	2008-08-20 20:39:41.000000000 +0200
@@ -0,0 +1,78 @@
+/*
+ *  tag.c
+ *
+ *  Copyright (c) 2002-2007 by Judd Vinet <[EMAIL PROTECTED]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/* libalpm */
+#include "tag.h"
+#include "alpm_list.h"
+#include "util.h"
+#include "log.h"
+#include "alpm.h"
+
+pmtag_t *_alpm_tag_new(const char *name)
+{
+	pmtag_t* tag;
+
+	ALPM_LOG_FUNC;
+
+	CALLOC(tag, 1, sizeof(pmtag_t), RET_ERR(PM_ERR_MEMORY, NULL));
+	STRDUP(tag->name, name, RET_ERR(PM_ERR_MEMORY, NULL));
+
+	return(tag);
+}
+
+void _alpm_tag_free(pmtag_t *tag)
+{
+	ALPM_LOG_FUNC;
+
+	if(tag == NULL) {
+		return;
+	}
+
+	FREE(tag->name);
+	/* do NOT free the contents of the list, just the nodes */
+	alpm_list_free(tag->packages);
+	FREE(tag);
+}
+
+const char SYMEXPORT *alpm_tag_get_name(const pmtag_t *tag)
+{
+	ALPM_LOG_FUNC;
+
+	/* Sanity checks */
+	ASSERT(tag != NULL, return(NULL));
+
+	return tag->name;
+}
+
+alpm_list_t SYMEXPORT *alpm_tag_get_pkgs(const pmtag_t *tag)
+{
+	ALPM_LOG_FUNC;
+
+	/* Sanity checks */
+	ASSERT(tag != NULL, return(NULL));
+
+	return tag->packages;
+}
+/* vim: set ts=2 sw=2 noet: */


--- lib/libalpm/cache.c.old	2008-08-20 20:11:08.000000000 +0200
+++ lib/libalpm/cache.c	2008-08-20 21:36:15.000000000 +0200
@@ -33,6 +33,7 @@
 #include "util.h"
 #include "package.h"
 #include "group.h"
+#include "tag.h"
 #include "db.h"
 
 /* Returns a new package cache from db.
@@ -76,6 +77,11 @@
 	if(db->grpcache) {
 		_alpm_db_free_grpcache(db);
 	}
+	
+	if(db->tagcache) {
+                _alpm_db_free_tagcache(db);
+        }
+
 }
 
 alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db)
@@ -129,6 +135,7 @@
 	db->pkgcache = alpm_list_add_sorted(db->pkgcache, newpkg, _alpm_pkg_cmp);
 
 	_alpm_db_free_grpcache(db);
+	_alpm_db_free_tagcache(db);
 
 	return(0);
 }
@@ -159,6 +166,7 @@
 	_alpm_pkg_free(data);
 
 	_alpm_db_free_grpcache(db);
+	_alpm_db_free_tagcache(db);
 
 	return(0);
 }
@@ -230,10 +238,9 @@
 			db->grpcache = alpm_list_add(db->grpcache, grp);
 		}
 	}
-
 	return(0);
 }
-
+	
 void _alpm_db_free_grpcache(pmdb_t *db)
 {
 	alpm_list_t *lg;
@@ -286,5 +293,106 @@
 
 	return(NULL);
 }
+int _alpm_db_load_tagcache(pmdb_t *db)
+{
+	alpm_list_t *lp;
+
+	ALPM_LOG_FUNC;
+
+	if(db == NULL) {
+		return(-1);
+	}
+
+	if(db->pkgcache == NULL) {
+		_alpm_db_load_pkgcache(db);
+	}
+
+	_alpm_log(PM_LOG_DEBUG, "loading tag cache for repository '%s'\n",
+			db->treename);
+
+	for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
+		const alpm_list_t *i;
+		pmpkg_t *pkg = lp->data;
+
+		for(i = alpm_pkg_get_tags(pkg); i; i = i->next) {
+			const char *tagname = i->data;
+			alpm_list_t *j;
+			pmtag_t *tag = NULL;
+			int found = 0;
+
+			/* first look through the tag cache for a tag with this name */
+			for(j = db->tagcache; j; j = j->next) {
+				tag = j->data;
+
+				if(strcmp(tag->name, tagname) == 0
+						&& !alpm_list_find_ptr(tag->packages, pkg)) {
+					tag->packages = alpm_list_add(tag->packages, pkg);
+					found = 1;
+					break;
+				}
+			}
+			if(found) {
+				continue;
+			}
+			/* we didn't find the tag, so create a new one with this name */
+			tag = _alpm_tag_new(tagname);
+			tag->packages = alpm_list_add(tag->packages, pkg);
+			db->tagcache = alpm_list_add(db->tagcache, tag);
+		}
+	}
+	return(0);
+}
+void _alpm_db_free_tagcache(pmdb_t *db)
+{
+	alpm_list_t *lg;
+
+	ALPM_LOG_FUNC;
+
+	if(db == NULL || db->tagcache == NULL) {
+		return;
+	}
+
+	for(lg = db->tagcache; lg; lg = lg->next) {
+		_alpm_tag_free(lg->data);
+		lg->data = NULL;
+	}
+	FREELIST(db->tagcache);
+}
+
+alpm_list_t *_alpm_db_get_tagcache(pmdb_t *db)
+{
+	ALPM_LOG_FUNC;
+
+	if(db == NULL) {
+		return(NULL);
+	}
+
+	if(db->tagcache == NULL) {
+		_alpm_db_load_tagcache(db);
+	}
+
+	return(db->tagcache);
+}
+
+pmtag_t *_alpm_db_get_tagfromcache(pmdb_t *db, const char *target)
+{
+	alpm_list_t *i;
+
+	ALPM_LOG_FUNC;
+
+	if(db == NULL || target == NULL || strlen(target) == 0) {
+		return(NULL);
+	}
+
+	for(i = _alpm_db_get_tagcache(db); i; i = i->next) {
+		pmtag_t *info = i->data;
+
+		if(strcmp(info->name, target) == 0) {
+			return(info);
+		}
+	}
+
+	return(NULL);
+}
 
 /* vim: set ts=2 sw=2 noet: */

--- lib/libalpm/Makefile.am.old	2008-08-20 22:45:23.144008783 +0200
+++ lib/libalpm/Makefile.am	2008-08-20 22:44:27.195152217 +0200
@@ -36,6 +36,7 @@
 	error.c \
 	graph.h \
 	group.h group.c \
+	tag.h tag.c \
 	handle.h handle.c \
 	log.h log.c \
 	md5.h md5.c \

--- lib/libalpm/Makefile.in.old	2008-08-20 22:44:36.660673116 +0200
+++ lib/libalpm/Makefile.in	2008-08-20 22:45:09.800661155 +0200
@@ -60,7 +60,7 @@
 libalpm_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
 am_libalpm_la_OBJECTS = add.lo alpm.lo alpm_list.lo backup.lo \
 	be_files.lo be_package.lo cache.lo conflict.lo db.lo delta.lo \
-	deps.lo dload.lo error.lo group.lo handle.lo log.lo md5.lo \
+	deps.lo dload.lo error.lo group.lo tag.lo handle.lo log.lo md5.lo \
 	package.lo remove.lo sync.lo trans.lo util.lo
 libalpm_la_OBJECTS = $(am_libalpm_la_OBJECTS)
 libalpm_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
@@ -246,6 +246,7 @@
 	error.c \
 	graph.h \
 	group.h group.c \
+	tag.h tag.c \
 	handle.h handle.c \
 	log.h log.c \
 	md5.h md5.c \
@@ -340,6 +341,7 @@
 @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
 @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
 @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
[EMAIL PROTECTED]@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
 @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
 @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
 @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@

Reply via email to