xbps-repo: indent pkgs from all repos with longest pkgver found.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2008-2011 Juan Romero Pardines.
|
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
struct repo_search_data {
|
struct repo_search_data {
|
||||||
int npatterns;
|
int npatterns;
|
||||||
char **patterns;
|
char **patterns;
|
||||||
|
void *arg;
|
||||||
size_t pkgver_len;
|
size_t pkgver_len;
|
||||||
size_t maxcols;
|
size_t maxcols;
|
||||||
};
|
};
|
||||||
@@ -54,6 +55,7 @@ void release_repo_lock(char **, int);
|
|||||||
int repo_find_files_in_packages(struct xbps_handle *, int, char **);
|
int repo_find_files_in_packages(struct xbps_handle *, int, char **);
|
||||||
|
|
||||||
/* From list.c */
|
/* From list.c */
|
||||||
|
size_t repo_find_longest_pkgver(struct xbps_handle *);
|
||||||
int repo_pkg_list_cb(struct xbps_handle *,
|
int repo_pkg_list_cb(struct xbps_handle *,
|
||||||
struct xbps_rpool_index *,
|
struct xbps_rpool_index *,
|
||||||
void *,
|
void *,
|
||||||
|
@@ -34,6 +34,37 @@
|
|||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "../xbps-bin/defs.h"
|
#include "../xbps-bin/defs.h"
|
||||||
|
|
||||||
|
static int
|
||||||
|
repo_longest_pkgver(struct xbps_handle *xhp,
|
||||||
|
struct xbps_rpool_index *rpi,
|
||||||
|
void *arg,
|
||||||
|
bool *done)
|
||||||
|
{
|
||||||
|
size_t *len = arg, olen = 0;
|
||||||
|
|
||||||
|
(void)done;
|
||||||
|
|
||||||
|
if (*len == 0) {
|
||||||
|
*len = find_longest_pkgver(xhp, rpi->repo);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
olen = find_longest_pkgver(xhp, rpi->repo);
|
||||||
|
if (olen > *len)
|
||||||
|
*len = olen;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
repo_find_longest_pkgver(struct xbps_handle *xhp)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
xbps_rpool_foreach(xhp, repo_longest_pkgver, &len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
repo_pkg_list_cb(struct xbps_handle *xhp,
|
repo_pkg_list_cb(struct xbps_handle *xhp,
|
||||||
struct xbps_rpool_index *rpi,
|
struct xbps_rpool_index *rpi,
|
||||||
@@ -41,16 +72,16 @@ repo_pkg_list_cb(struct xbps_handle *xhp,
|
|||||||
bool *done)
|
bool *done)
|
||||||
{
|
{
|
||||||
struct list_pkgver_cb lpc;
|
struct list_pkgver_cb lpc;
|
||||||
const char *repo = arg;
|
struct repo_search_data *rsd = arg;
|
||||||
|
|
||||||
(void)done;
|
(void)done;
|
||||||
if (repo && strcmp(rpi->uri, repo))
|
if (rsd->arg && strcmp(rpi->uri, rsd->arg))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lpc.check_state = false;
|
lpc.check_state = false;
|
||||||
lpc.state = 0;
|
lpc.state = 0;
|
||||||
lpc.pkgver_len = find_longest_pkgver(xhp, rpi->repo);
|
lpc.pkgver_len = rsd->pkgver_len;
|
||||||
lpc.maxcols = get_maxcols();
|
lpc.maxcols = rsd->maxcols;
|
||||||
|
|
||||||
(void)xbps_callback_array_iter(xhp, rpi->repo, list_pkgs_in_dict, &lpc);
|
(void)xbps_callback_array_iter(xhp, rpi->repo, list_pkgs_in_dict, &lpc);
|
||||||
|
|
||||||
@@ -82,9 +113,6 @@ repo_search_pkgs_cb(struct xbps_handle *xhp,
|
|||||||
struct repo_search_data *rsd = arg;
|
struct repo_search_data *rsd = arg;
|
||||||
(void)done;
|
(void)done;
|
||||||
|
|
||||||
rsd->maxcols = get_maxcols();
|
|
||||||
rsd->pkgver_len = find_longest_pkgver(xhp, rpi->repo);
|
|
||||||
|
|
||||||
(void)xbps_callback_array_iter(xhp, rpi->repo, show_pkg_namedesc, rsd);
|
(void)xbps_callback_array_iter(xhp, rpi->repo, show_pkg_namedesc, rsd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -90,7 +90,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
struct xbps_handle xh;
|
struct xbps_handle xh;
|
||||||
struct xferstat xfer;
|
struct xferstat xfer;
|
||||||
struct repo_search_data *rsd = NULL;
|
struct repo_search_data rsd;
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
const char *rootdir, *cachedir, *conffile, *option;
|
const char *rootdir, *cachedir, *conffile, *option;
|
||||||
int flags = 0, c, rv = 0;
|
int flags = 0, c, rv = 0;
|
||||||
@@ -170,7 +170,11 @@ main(int argc, char **argv)
|
|||||||
if (argc < 1 || argc > 2)
|
if (argc < 1 || argc > 2)
|
||||||
usage(true);
|
usage(true);
|
||||||
|
|
||||||
rv = xbps_rpool_foreach(&xh, repo_pkg_list_cb, argv[1]);
|
rsd.arg = argv[1];
|
||||||
|
rsd.pkgver_len = repo_find_longest_pkgver(&xh);
|
||||||
|
rsd.maxcols = get_maxcols();
|
||||||
|
|
||||||
|
rv = xbps_rpool_foreach(&xh, repo_pkg_list_cb, &rsd);
|
||||||
if (rv == ENOTSUP)
|
if (rv == ENOTSUP)
|
||||||
xbps_error_printf("xbps-repo: no repositories "
|
xbps_error_printf("xbps-repo: no repositories "
|
||||||
"currently registered!\n");
|
"currently registered!\n");
|
||||||
@@ -185,15 +189,12 @@ main(int argc, char **argv)
|
|||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
usage(true);
|
usage(true);
|
||||||
|
|
||||||
rsd = malloc(sizeof(*rsd));
|
rsd.npatterns = argc;
|
||||||
if (rsd == NULL) {
|
rsd.patterns = argv;
|
||||||
rv = ENOMEM;
|
rsd.pkgver_len = repo_find_longest_pkgver(&xh);
|
||||||
goto out;
|
rsd.maxcols = get_maxcols();
|
||||||
}
|
|
||||||
rsd->npatterns = argc;
|
rv = xbps_rpool_foreach(&xh, repo_search_pkgs_cb, &rsd);
|
||||||
rsd->patterns = argv;
|
|
||||||
rv = xbps_rpool_foreach(&xh, repo_search_pkgs_cb, rsd);
|
|
||||||
free(rsd);
|
|
||||||
if (rv == ENOTSUP)
|
if (rv == ENOTSUP)
|
||||||
xbps_error_printf("xbps-repo: no repositories "
|
xbps_error_printf("xbps-repo: no repositories "
|
||||||
"currently registered!\n");
|
"currently registered!\n");
|
||||||
|
Reference in New Issue
Block a user