summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2016-05-12 14:07:05 +0200
committerPeter Rajnoha <prajnoha@redhat.com>2016-06-02 14:38:14 +0200
commitc6dd96e7e61a57683613286461393cd87496f45d (patch)
tree141a7d91b292e576358480c88149c33a1de3c85a
parent585d8c9b1d50a5528d71d8a0348919b2795b962b (diff)
downloadlvm2-c6dd96e7e61a57683613286461393cd87496f45d.tar.gz
refactor: move field width calculation and sort preparation from _do_report_object to dm_report_output
-rw-r--r--libdm/libdm-report.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 350a3e9bc..a3ca20b75 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -1913,7 +1913,6 @@ static int _do_report_object(struct dm_report *rh, void *object, int do_output,
struct row *row = NULL;
struct dm_report_field *field;
void *data = NULL;
- int len;
int r = 0;
if (!rh) {
@@ -2021,17 +2020,6 @@ static int _do_report_object(struct dm_report *rh, void *object, int do_output,
dm_list_add(&rh->rows, &row->list);
- dm_list_iterate_items(field, &row->fields) {
- len = (int) strlen(field->report_string);
- if ((len > field->props->width))
- field->props->width = len;
-
- if ((rh->flags & RH_SORT_REQUIRED) &&
- (field->props->flags & FLD_SORT_KEY)) {
- (*row->sort_fields)[field->props->sort_posn] = field;
- }
- }
-
if (!(rh->flags & DM_REPORT_OUTPUT_BUFFERED))
return dm_report_output(rh);
out:
@@ -4607,6 +4595,9 @@ static int _prepare_json_report_output(struct dm_report *rh)
int dm_report_output(struct dm_report *rh)
{
+ struct row *row;
+ struct dm_report_field *field;
+ int len;
int r;
if (_is_json_report(rh) &&
@@ -4618,6 +4609,19 @@ int dm_report_output(struct dm_report *rh)
goto out;
}
+ dm_list_iterate_items(row, &rh->rows) {
+ dm_list_iterate_items(field, &row->fields) {
+ len = (int) strlen(field->report_string);
+ if ((len > field->props->width))
+ field->props->width = len;
+
+ if ((rh->flags & RH_SORT_REQUIRED) &&
+ (field->props->flags & FLD_SORT_KEY)) {
+ (*row->sort_fields)[field->props->sort_posn] = field;
+ }
+ }
+ }
+
if ((rh->flags & RH_SORT_REQUIRED))
_sort_rows(rh);
if (_is_native_report(rh)) {