Make dump_pkg_full a little less insane

The various "level" values were a bit crazy to decipher, and we were
doing some very interesting comparisons in certain places. Break it out
into two parameters instead so we can seperate the type from the extra
information display, and do things accordingly.

Nothing changes with the display of any of the five types we currently
show: -Si, -Sii, -Qi, -Qii, -Qip.

Something to note- we should expose the PKG_FROM enum type somehow, this
patch leaves the door open to do that quite easily.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-04-21 19:51:51 -05:00
parent 9579879b1b
commit 8b34aa50b9
5 changed files with 36 additions and 40 deletions

View file

@ -567,9 +567,9 @@ alpm_list_t *alpm_pkg_get_files(pmpkg_t *pkg);
*/ */
alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg); alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg);
/** Returns the database containing pkg /** Returns the database containing pkg.
* Returns a pointer to the pmdb_t structure the package is * Returns a pointer to the pmdb_t structure the package is
* originating from, or NULL is the package was loaded from a file. * originating from, or NULL if the package was loaded from a file.
* @param pkg a pointer to package * @param pkg a pointer to package
* @return a pointer to the DB containing pkg, or NULL. * @return a pointer to the DB containing pkg, or NULL.
*/ */

View file

@ -36,16 +36,15 @@
#define CLBUF_SIZE 4096 #define CLBUF_SIZE 4096
/* Display the content of a package /**
* * Display the details of a package.
* levels: * Extra information entails 'required by' info for sync packages and backup
* <-1 - sync package, extra information (required by) [-Sii] * files info for local packages.
* -1 - sync package, normal level [-Si] * @param pkg package to display information for
* =0 - file query [-Qip] * @param from the type of package we are dealing with
* 1 - localdb query, normal level [-Qi] * @param extra should we show extra information
* >1 - localdb query, extra information (backup files) [-Qii]
*/ */
void dump_pkg_full(pmpkg_t *pkg, int level) void dump_pkg_full(pmpkg_t *pkg, enum pkg_from from, int extra)
{ {
const char *reason; const char *reason;
time_t bdate, idate; time_t bdate, idate;
@ -87,12 +86,16 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep)); depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep));
} }
if(level > 0 || level < -1) { if(extra || from == PKG_FROM_LOCALDB) {
/* compute this here so we don't get a pause in the middle of output */ /* compute this here so we don't get a pause in the middle of output */
requiredby = alpm_pkg_compute_requiredby(pkg); requiredby = alpm_pkg_compute_requiredby(pkg);
} }
/* actual output */ /* actual output */
if(from == PKG_FROM_SYNCDB) {
string_display(_("Repository :"),
alpm_db_get_name(alpm_pkg_get_db(pkg)));
}
string_display(_("Name :"), alpm_pkg_get_name(pkg)); string_display(_("Name :"), alpm_pkg_get_name(pkg));
string_display(_("Version :"), alpm_pkg_get_version(pkg)); string_display(_("Version :"), alpm_pkg_get_version(pkg));
string_display(_("URL :"), alpm_pkg_get_url(pkg)); string_display(_("URL :"), alpm_pkg_get_url(pkg));
@ -101,16 +104,16 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
list_display(_("Provides :"), alpm_pkg_get_provides(pkg)); list_display(_("Provides :"), alpm_pkg_get_provides(pkg));
list_display(_("Depends On :"), depstrings); list_display(_("Depends On :"), depstrings);
list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg)); list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
if(level > 0 || level < -1) { if(extra || from == PKG_FROM_LOCALDB) {
list_display(_("Required By :"), requiredby); list_display(_("Required By :"), requiredby);
} }
list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
size = humanize_size(alpm_pkg_get_size(pkg), 'K', 1, &label); size = humanize_size(alpm_pkg_get_size(pkg), 'K', 1, &label);
if(level < 0) { if(from == PKG_FROM_SYNCDB) {
printf(_("Download Size : %6.2f %s\n"), size, label); printf(_("Download Size : %6.2f %s\n"), size, label);
} else if(level == 0) { } else if(from == PKG_FROM_FILE) {
printf(_("Compressed Size: %6.2f %s\n"), size, label); printf(_("Compressed Size: %6.2f %s\n"), size, label);
} }
@ -120,23 +123,22 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
string_display(_("Packager :"), alpm_pkg_get_packager(pkg)); string_display(_("Packager :"), alpm_pkg_get_packager(pkg));
string_display(_("Architecture :"), alpm_pkg_get_arch(pkg)); string_display(_("Architecture :"), alpm_pkg_get_arch(pkg));
string_display(_("Build Date :"), bdatestr); string_display(_("Build Date :"), bdatestr);
if(level > 0) { if(from == PKG_FROM_LOCALDB) {
string_display(_("Install Date :"), idatestr); string_display(_("Install Date :"), idatestr);
string_display(_("Install Reason :"), reason); string_display(_("Install Reason :"), reason);
} }
if(level >= 0) { if(from == PKG_FROM_FILE || from == PKG_FROM_LOCALDB) {
string_display(_("Install Script :"), string_display(_("Install Script :"),
alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No")); alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"));
} }
/* MD5 Sum for sync package */ if(from == PKG_FROM_SYNCDB) {
if(level < 0) {
string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg)); string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg));
} }
string_display(_("Description :"), alpm_pkg_get_desc(pkg)); string_display(_("Description :"), alpm_pkg_get_desc(pkg));
/* Print additional package info if info flag passed more than once */ /* Print additional package info if info flag passed more than once */
if(level > 1) { if(from == PKG_FROM_LOCALDB && extra) {
dump_pkg_backups(pkg); dump_pkg_backups(pkg);
} }
@ -147,18 +149,6 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
FREELIST(requiredby); FREELIST(requiredby);
} }
/* Display the content of a sync package
*/
void dump_pkg_sync(pmpkg_t *pkg, const char *treename, int level)
{
if(pkg == NULL) {
return;
}
string_display(_("Repository :"), treename);
/* invert the level since we are a sync package */
dump_pkg_full(pkg, -level);
}
static const char *get_backup_file_status(const char *root, static const char *get_backup_file_status(const char *root,
const char *filename, const char *expected_md5) const char *filename, const char *expected_md5)
{ {

View file

@ -22,8 +22,14 @@
#include <alpm.h> #include <alpm.h>
void dump_pkg_full(pmpkg_t *pkg, int level); /* TODO it would be nice if we didn't duplicate a backend type */
void dump_pkg_sync(pmpkg_t *pkg, const char *treename, int level); enum pkg_from {
PKG_FROM_FILE = 1,
PKG_FROM_LOCALDB,
PKG_FROM_SYNCDB
};
void dump_pkg_full(pmpkg_t *pkg, enum pkg_from from, int extra);
void dump_pkg_backups(pmpkg_t *pkg); void dump_pkg_backups(pmpkg_t *pkg);
void dump_pkg_files(pmpkg_t *pkg, int quiet); void dump_pkg_files(pmpkg_t *pkg, int quiet);

View file

@ -450,10 +450,9 @@ static int display(pmpkg_t *pkg)
if(config->op_q_info) { if(config->op_q_info) {
if(config->op_q_isfile) { if(config->op_q_isfile) {
/* omit info that isn't applicable for a file package */ dump_pkg_full(pkg, PKG_FROM_FILE, 0);
dump_pkg_full(pkg, 0);
} else { } else {
dump_pkg_full(pkg, config->op_q_info); dump_pkg_full(pkg, PKG_FROM_LOCALDB, config->op_q_info > 1);
} }
} }
if(config->op_q_list) { if(config->op_q_list) {

View file

@ -465,7 +465,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
pmpkg_t *pkg = alpm_list_getdata(k); pmpkg_t *pkg = alpm_list_getdata(k);
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) { if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
dump_pkg_sync(pkg, alpm_db_get_name(db), config->op_s_info); dump_pkg_full(pkg, PKG_FROM_SYNCDB, config->op_s_info > 1);
foundpkg = 1; foundpkg = 1;
break; break;
} }
@ -486,7 +486,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
pmpkg_t *pkg = alpm_list_getdata(k); pmpkg_t *pkg = alpm_list_getdata(k);
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) { if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
dump_pkg_sync(pkg, alpm_db_get_name(db), config->op_s_info); dump_pkg_full(pkg, PKG_FROM_SYNCDB, config->op_s_info > 1);
foundpkg = 1; foundpkg = 1;
break; break;
} }
@ -504,7 +504,8 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
pmdb_t *db = alpm_list_getdata(i); pmdb_t *db = alpm_list_getdata(i);
for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) { for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
dump_pkg_sync(alpm_list_getdata(j), alpm_db_get_name(db), config->op_s_info); pmpkg_t *pkg = alpm_list_getdata(j);
dump_pkg_full(pkg, PKG_FROM_SYNCDB, config->op_s_info > 1);
} }
} }
} }