diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-12-27 14:34:01 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2023-03-03 13:00:10 +0200 |
commit | d351992ad529dccb95fc1c8997cd328e9c694a92 (patch) | |
tree | d4d54f32b1254b779557eea82fd78391c0063661 /src/commit.c | |
parent | fd8f39f1d54c3b56d16a494898e5a753e2c71715 (diff) | |
download | apk-tools-2.12-stable.tar.gz apk-tools-2.12-stable.tar.bz2 apk-tools-2.12-stable.tar.xz apk-tools-2.12-stable.zip |
print: improve indented printing api2.12-stable
- make sure all commit errors go to stderr
- make it a bit more api like
(cherry picked and rebased from commit a662047e2c43604bc087ec4dda9a7358368d850b)
fixes #10879
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/commit.c b/src/commit.c index f9f14ba..f582ec2 100644 --- a/src/commit.c +++ b/src/commit.c @@ -130,12 +130,13 @@ static int dump_packages(struct apk_change_array *changes, { struct apk_change *change; struct apk_name *name; - struct apk_indent indent = { .indent = 2 }; + struct apk_indent indent; int match = 0; + apk_print_indented_init(&indent, 0); foreach_array_item(change, changes) { if (!cmp(change)) continue; - if (!match) printf("%s:\n", msg); + if (!match) apk_print_indented_group(&indent, 2, "%s:\n", msg); if (change->new_pkg != NULL) name = change->new_pkg->name; else @@ -144,7 +145,7 @@ static int dump_packages(struct apk_change_array *changes, apk_print_indented(&indent, APK_BLOB_STR(name->name)); match++; } - if (match) printf("\n"); + apk_print_indented_end(&indent); return match; } @@ -316,11 +317,11 @@ int apk_solver_commit_changeset(struct apk_database *db, "The following packages will be reinstalled"); if (download_size) { size_unit = apk_get_human_size(download_size, &humanized); - printf("Need to download %lld %s of packages.\n", + apk_message("Need to download %lld %s of packages.", (long long)humanized, size_unit); } size_unit = apk_get_human_size(llabs(size_diff), &humanized); - printf("After this operation, %lld %s of %s.\n", + apk_message("After this operation, %lld %s of %s.", (long long)humanized, size_unit, (size_diff < 0) ? @@ -417,22 +418,15 @@ struct print_state { static void label_start(struct print_state *ps, const char *text) { if (ps->label) { - printf(" %s:\n", ps->label); + apk_print_indented_line(&ps->i, " %s:\n", ps->label); ps->label = NULL; - ps->i.x = ps->i.indent = 0; ps->num_labels++; } - if (ps->i.x == 0) { - ps->i.x = printf(" %s", text); - ps->i.indent = ps->i.x + 1; - } + if (!ps->i.x) apk_print_indented_group(&ps->i, 0, " %s", text); } static void label_end(struct print_state *ps) { - if (ps->i.x != 0) { - printf("\n"); - ps->i.x = ps->i.indent = 0; - } + apk_print_indented_end(&ps->i); } static void print_pinning_errors(struct print_state *ps, struct apk_package *pkg, unsigned int tag) @@ -760,6 +754,7 @@ void apk_solver_print_errors(struct apk_database *db, .db = db, .world = world, }; + apk_print_indented_init(&ps.i, 1); analyze_deps(&ps, world); foreach_array_item(change, changeset->changes) { struct apk_package *pkg = change->new_pkg; @@ -768,8 +763,8 @@ void apk_solver_print_errors(struct apk_database *db, analyze_deps(&ps, pkg->depends); } - if (ps.num_labels == 0) - printf(" Huh? Error reporter did not find the broken constraints.\n"); + if (!ps.num_labels) + apk_print_indented_line(&ps.i, "Huh? Error reporter did not find the broken constraints.\n"); } int apk_solver_commit(struct apk_database *db, |