-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow --print-stats --null-output #649
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,21 +163,21 @@ chunks_delete_printstats(FILE * stream, CHUNKS_D * C, const char * name, | |
name = "This archive"; | ||
|
||
/* Print header. */ | ||
if (chunks_stats_printheader(stream, csv)) | ||
if (chunks_stats_printheader(stream, csv, 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we wanted to allow A small part of me thinks "hey, why not allow |
||
goto err0; | ||
|
||
/* Print the statistics we have. */ | ||
if (chunks_stats_print(stream, &C->stats_total, "All archives", | ||
&C->stats_extra, csv)) | ||
&C->stats_extra, csv, 0)) | ||
goto err0; | ||
if (chunks_stats_print(stream, &C->stats_unique, " (unique data)", | ||
&C->stats_extra, csv)) | ||
&C->stats_extra, csv, 0)) | ||
goto err0; | ||
if (chunks_stats_print(stream, &C->stats_tape, name, | ||
&C->stats_tapee, csv)) | ||
&C->stats_tapee, csv, 0)) | ||
goto err0; | ||
if (chunks_stats_print(stream, &C->stats_freed, "Deleted data", | ||
&C->stats_tapee, csv)) | ||
&C->stats_tapee, csv, 0)) | ||
goto err0; | ||
|
||
/* Success! */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
#include "asprintf.h" | ||
#include "humansize.h" | ||
#include "print_separator.h" | ||
#include "storage.h" | ||
#include "tarsnap_opt.h" | ||
#include "warnp.h" | ||
|
@@ -64,26 +65,43 @@ chunks_stats_addstats(struct chunkstats * to, struct chunkstats * from) | |
} | ||
|
||
/** | ||
* chunks_stats_printheader(stream, csv): | ||
* chunks_stats_printheader(stream, csv, print_nulls): | ||
* Print a header line for statistics to ${stream}, optionally in ${csv} | ||
* format. | ||
* format. If ${print_nulls} is non-zero, use '\0' for separators. | ||
*/ | ||
int | ||
chunks_stats_printheader(FILE * stream, int csv) | ||
chunks_stats_printheader(FILE * stream, int csv, int print_nulls) | ||
{ | ||
const char * first_field; | ||
|
||
if (csv) { | ||
if (csv || print_nulls) { | ||
first_field = csv ? "Archive name" : ""; | ||
if (fprintf(stream, "%s", first_field) < 0) { | ||
warnp("fprintf"); | ||
goto err0; | ||
} | ||
if (print_separator(stream, ",", print_nulls, 2)) | ||
goto err0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally we'd have
here, but we don't need the I normally try to have a "perfect" refactoring before changing code, but in this specific case I think it's worth skipping the warning in order to reduce the number of changed lines in the diff. |
||
#ifdef STATS_WITH_CHUNKS | ||
if (fprintf(stream, "%s,%s,%s,%s\n", | ||
"Archive name", "# of chunks", "Total size", | ||
"Compressed size") < 0) { | ||
#else | ||
if (fprintf(stream, "%s,%s,%s\n", | ||
"Archive name", "Total size", "Compressed size") < 0) { | ||
if (fprintf(stream, "%s", "# of chunks") < 0) { | ||
warnp("fprintf"); | ||
goto err0; | ||
} | ||
if (print_separator(stream, ",", print_nulls, 2)) | ||
goto err0; | ||
#endif | ||
if (fprintf(stream, "%s", "Total size") < 0) { | ||
warnp("fprintf"); | ||
goto err0; | ||
} | ||
if (print_separator(stream, ",", print_nulls, 2)) | ||
goto err0; | ||
if (fprintf(stream, "%s", "Compressed size") < 0) { | ||
warnp("fprintf"); | ||
goto err0; | ||
} | ||
if (print_separator(stream, "\n", print_nulls, 1)) | ||
goto err0; | ||
} else { | ||
#ifdef STATS_WITH_CHUNKS | ||
if (fprintf(stream, "%-32s %12s %15s %15s\n", | ||
|
@@ -106,13 +124,15 @@ chunks_stats_printheader(FILE * stream, int csv) | |
} | ||
|
||
/** | ||
* chunks_stats_print(stream, stats, name, stats_extra, csv): | ||
* chunks_stats_print(stream, stats, name, stats_extra, csv, print_nulls): | ||
* Print a line with ${name} and combined statistics from ${stats} and | ||
* ${stats_extra} to ${stream}, optionally in ${csv} format. | ||
* ${stats_extra} to ${stream}, optionally in ${csv} format. If ${print_nulls} | ||
* is non-zero, use '\0' as separators. | ||
*/ | ||
int | ||
chunks_stats_print(FILE * stream, struct chunkstats * stats, | ||
const char * name, struct chunkstats * stats_extra, int csv) | ||
const char * name, struct chunkstats * stats_extra, int csv, | ||
int print_nulls) | ||
{ | ||
struct chunkstats s; | ||
char * s_lenstr, * s_zlenstr; | ||
|
@@ -142,19 +162,33 @@ chunks_stats_print(FILE * stream, struct chunkstats * stats, | |
} | ||
|
||
/* Print output line. */ | ||
if (csv) { | ||
if (fprintf(stream, | ||
if (csv || print_nulls) { | ||
if (fprintf(stream, "%s", name) < 0) { | ||
warnp("fprintf"); | ||
goto err2; | ||
} | ||
if (print_separator(stream, ",", print_nulls, 2)) | ||
goto err2; | ||
#ifdef STATS_WITH_CHUNKS | ||
"%s,%" PRIu64 ",%s,%s\n", | ||
name, s.nchunks, | ||
#else | ||
"%s,%s,%s\n", | ||
name, | ||
if (fprintf(stream, "%" PRIu64, s.nchunks) < 0) { | ||
warnp("fprintf"); | ||
goto err2; | ||
} | ||
if (print_separator(stream, ",", print_nulls, 2)) | ||
goto err2; | ||
#endif | ||
s_lenstr, s_zlenstr) < 0) { | ||
if (fprintf(stream, "%s", s_lenstr) < 0) { | ||
warnp("fprintf"); | ||
goto err2; | ||
} | ||
if (print_separator(stream, ",", print_nulls, 2)) | ||
goto err2; | ||
if (fprintf(stream, "%s", s_zlenstr) < 0) { | ||
warnp("fprintf"); | ||
goto err2; | ||
} | ||
if (print_separator(stream, "\n", print_nulls, 1)) | ||
goto err2; | ||
} else { | ||
if (fprintf(stream, | ||
#ifdef STATS_WITH_CHUNKS | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,21 +284,21 @@ chunks_write_printstats(FILE * stream, CHUNKS_W * C, int csv) | |
{ | ||
|
||
/* Print header. */ | ||
if (chunks_stats_printheader(stream, csv)) | ||
if (chunks_stats_printheader(stream, csv, 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same argument for |
||
goto err0; | ||
|
||
/* Print the statistics we have. */ | ||
if (chunks_stats_print(stream, &C->stats_total, "All archives", | ||
&C->stats_extra, csv)) | ||
&C->stats_extra, csv, 0)) | ||
goto err0; | ||
if (chunks_stats_print(stream, &C->stats_unique, " (unique data)", | ||
&C->stats_extra, csv)) | ||
&C->stats_extra, csv, 0)) | ||
goto err0; | ||
if (chunks_stats_print(stream, &C->stats_tape, "This archive", | ||
&C->stats_tapee, csv)) | ||
&C->stats_tapee, csv, 0)) | ||
goto err0; | ||
if (chunks_stats_print(stream, &C->stats_new, "New data", | ||
&C->stats_tapee, csv)) | ||
&C->stats_tapee, csv, 0)) | ||
goto err0; | ||
|
||
/* Success! */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. In #643, I was so fixated on whether we'd allow
#define print_sep
that I missed that the API should takeconst
.