summaryrefslogtreecommitdiff
path: root/src/pacman/package.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-03-16 17:57:04 -0500
committerDan McGee <dan@archlinux.org>2012-03-16 17:57:04 -0500
commit8da489eac53513841d62380a72aae1baecc44e61 (patch)
tree1526dbe3366f0d62d2749c3c5cd75eb80c96228e /src/pacman/package.c
parent0972b7acfd7c8fadb6aeec6606ea85bf6c5d3d3d (diff)
Reduce calls to getcols
This dramatically improves upon a much older attempt in 2008 in commit ce3d70aa99ab86. We don't need to call it once per line we print unless there is a reasonable expectation of being able to resize the terminal mid-operation; this is really only the case during our callback progress bars. Some before and after numbers of ioctl() calls, gleaned from strace of the following operations (no targets to any of them to maximize the amount of output): pacman -Qii : 37768 -> 2616 (93.1% decrease) pacman -Qs : 2616 -> 4 (99.8%) pacman -Sii : 133036 -> 10926 (91.8%) pacman -Ss : 10926 -> 14 (99.9%) Obviously the search results are astounding; we only call getcols() once in the case of -Qs, and once per repo in the case of -Ss. For -Qii and -Sii we are still calling it once per package, but this is much better than once per line of info output. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman/package.c')
-rw-r--r--src/pacman/package.c67
1 files changed, 34 insertions, 33 deletions
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 6e091d58..942797ad 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -40,14 +40,14 @@
* @param deps a list with items of type alpm_depend_t
*/
static void deplist_display(const char *title,
- alpm_list_t *deps)
+ alpm_list_t *deps, unsigned short cols)
{
alpm_list_t *i, *text = NULL;
for(i = deps; i; i = alpm_list_next(i)) {
alpm_depend_t *dep = i->data;
text = alpm_list_add(text, alpm_dep_compute_string(dep));
}
- list_display(title, text);
+ list_display(title, text, cols);
FREELIST(text);
}
@@ -55,14 +55,14 @@ static void deplist_display(const char *title,
* @param optdeps a list with items of type alpm_optdepend_t
*/
static void optdeplist_display(const char *title,
- alpm_list_t *optdeps)
+ alpm_list_t *optdeps, unsigned short cols)
{
alpm_list_t *i, *text = NULL;
for(i = optdeps; i; i = alpm_list_next(i)) {
alpm_depend_t *optdep = i->data;
text = alpm_list_add(text, alpm_dep_compute_string(optdep));
}
- list_display_linebreak(title, text);
+ list_display_linebreak(title, text, cols);
FREELIST(text);
}
@@ -76,14 +76,13 @@ static void optdeplist_display(const char *title,
*/
void dump_pkg_full(alpm_pkg_t *pkg, int extra)
{
- const char *reason;
- alpm_list_t *validation = NULL;
+ unsigned short cols;
time_t bdate, idate;
- char bdatestr[50] = "", idatestr[50] = "";
- const char *label;
- double size;
- alpm_list_t *requiredby = NULL;
alpm_pkgfrom_t from;
+ double size;
+ char bdatestr[50] = "", idatestr[50] = "";
+ const char *label, *reason;
+ alpm_list_t *validation = NULL, *requiredby = NULL;
from = alpm_pkg_get_origin(pkg);
@@ -133,24 +132,26 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
requiredby = alpm_pkg_compute_requiredby(pkg);
}
+ cols = getcols(fileno(stdout));
+
/* actual output */
if(from == PKG_FROM_SYNCDB) {
string_display(_("Repository :"),
- alpm_db_get_name(alpm_pkg_get_db(pkg)));
+ alpm_db_get_name(alpm_pkg_get_db(pkg)), cols);
}
- string_display(_("Name :"), alpm_pkg_get_name(pkg));
- string_display(_("Version :"), alpm_pkg_get_version(pkg));
- string_display(_("URL :"), alpm_pkg_get_url(pkg));
- list_display(_("Licenses :"), alpm_pkg_get_licenses(pkg));
- list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
- deplist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
- deplist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
- optdeplist_display(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
+ string_display(_("Name :"), alpm_pkg_get_name(pkg), cols);
+ string_display(_("Version :"), alpm_pkg_get_version(pkg), cols);
+ string_display(_("URL :"), alpm_pkg_get_url(pkg), cols);
+ list_display(_("Licenses :"), alpm_pkg_get_licenses(pkg), cols);
+ list_display(_("Groups :"), alpm_pkg_get_groups(pkg), cols);
+ deplist_display(_("Provides :"), alpm_pkg_get_provides(pkg), cols);
+ deplist_display(_("Depends On :"), alpm_pkg_get_depends(pkg), cols);
+ optdeplist_display(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg), cols);
if(extra || from == PKG_FROM_LOCALDB) {
- list_display(_("Required By :"), requiredby);
+ list_display(_("Required By :"), requiredby, cols);
}
- deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
- deplist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
+ deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg), cols);
+ deplist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg), cols);
size = humanize_size(alpm_pkg_get_size(pkg), 'K', 2, &label);
if(from == PKG_FROM_SYNCDB) {
@@ -162,35 +163,35 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 2, &label);
printf(_("Installed Size : %6.2f %s\n"), size, label);
- string_display(_("Packager :"), alpm_pkg_get_packager(pkg));
- string_display(_("Architecture :"), alpm_pkg_get_arch(pkg));
- string_display(_("Build Date :"), bdatestr);
+ string_display(_("Packager :"), alpm_pkg_get_packager(pkg), cols);
+ string_display(_("Architecture :"), alpm_pkg_get_arch(pkg), cols);
+ string_display(_("Build Date :"), bdatestr, cols);
if(from == PKG_FROM_LOCALDB) {
- string_display(_("Install Date :"), idatestr);
- string_display(_("Install Reason :"), reason);
+ string_display(_("Install Date :"), idatestr, cols);
+ string_display(_("Install Reason :"), reason, cols);
}
if(from == PKG_FROM_FILE || from == PKG_FROM_LOCALDB) {
string_display(_("Install Script :"),
- alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"));
+ alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"), cols);
}
- list_display(_("Validated By :"), validation);
+ list_display(_("Validated By :"), validation, cols);
if(from == PKG_FROM_FILE) {
alpm_siglist_t siglist;
int err = alpm_pkg_check_pgp_signature(pkg, &siglist);
if(err && alpm_errno(config->handle) == ALPM_ERR_SIG_MISSING) {
- string_display(_("Signatures :"), _("None"));
+ string_display(_("Signatures :"), _("None"), cols);
} else if(err) {
string_display(_("Signatures :"),
- alpm_strerror(alpm_errno(config->handle)));
+ alpm_strerror(alpm_errno(config->handle)), cols);
} else {
- signature_display(_("Signatures :"), &siglist);
+ signature_display(_("Signatures :"), &siglist, cols);
}
alpm_siglist_cleanup(&siglist);
}
- string_display(_("Description :"), alpm_pkg_get_desc(pkg));
+ string_display(_("Description :"), alpm_pkg_get_desc(pkg), cols);
/* Print additional package info if info flag passed more than once */
if(from == PKG_FROM_LOCALDB && extra) {