The branch, master has been updated via ad53a9b5 Also change dashes in the dict var names to make jq use easier. via 17502886 A few more tweaks. via 087fffaa Unify older protect-args capability to secluded-args name. via 5c1fa2a2 Use dict for capabilities & optimizations in json output. from 0efa63f2 Use JSON output if --version (-V) is repeated (client side only).
https://git.samba.org/?p=rsync.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit ad53a9b5a04829e84631ef633453b03d64684d1f Author: Wayne Davison <wa...@opencoder.net> Date: Sat Sep 10 17:30:54 2022 -0700 Also change dashes in the dict var names to make jq use easier. commit 1750288660ab92ce6ea8c6aead4ca4a3a5107bde Author: Wayne Davison <wa...@opencoder.net> Date: Sat Sep 10 16:19:21 2022 -0700 A few more tweaks. commit 087fffaa2be1029b7890b90a891fee6551aa4c1e Author: Wayne Davison <wa...@opencoder.net> Date: Sat Sep 10 16:17:32 2022 -0700 Unify older protect-args capability to secluded-args name. commit 5c1fa2a21dbce9745483e2ae81afdf1dd9f1fea2 Author: Wayne Davison <wa...@opencoder.net> Date: Sat Sep 10 15:39:25 2022 -0700 Use dict for capabilities & optimizations in json output. ----------------------------------------------------------------------- Summary of changes: NEWS.md | 10 ++++++---- support/json-rsync-version | 20 ++++++++++++++++---- usage.c | 34 +++++++++++++++++++++++++--------- 3 files changed, 47 insertions(+), 17 deletions(-) Changeset truncated at 500 lines: diff --git a/NEWS.md b/NEWS.md index 81d66b63..fe962ad0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,7 +13,7 @@ digests are at the highest priority in the new negotiation list. - Added support for SHA1, SHA256, and SHA512 digests in file checksums. While - This tends to be overkill, if someone needs it, it is available. These + this tends to be overkill, it is available if someone really needs it. These overly-long checksums are at the lowest priority in the normal checksum negotation list. @@ -21,9 +21,11 @@ output in a (still human-readable) JSON format (client side only). - The script `support/json-rsync-version` is available to get the JSON style - version output from any rsync. The script accepts the version output on - stdin **or** the name of an rsync to run as an arg. If the text isn't - already in JSON format, the text is translated into equivalent JSON. + version output from any rsync. The script accepts either text on stdin + **or** an arg that specifies an rsync executable to run with a doubled + `--version` option. If the text we get isn't already in JSON format, it is + converted into equivalent JSON as rsync 3.2.7 would output it (though some + info may be missing from older versions). ### PACKAGING RELATED: diff --git a/support/json-rsync-version b/support/json-rsync-version index 79050e48..afaf7382 100755 --- a/support/json-rsync-version +++ b/support/json-rsync-version @@ -30,17 +30,29 @@ def main(): elif line.startswith(' '): if not saw_comma and ',' in line: saw_comma = True + info[sect_name] = { } if saw_comma: - lst = line.strip(' ,').split(', ') + for x in line.strip(' ,').split(', '): + if ' ' in x: + val, var = x.split(' ', 1) + if var == 'protect-args': + var = 'secluded-args' + var = var.replace(' ', '_').replace('-', '_') + info[sect_name][var] = False if val == 'no' else val + else: + x = x.replace('-', '_') + info[sect_name][x] = True else: - lst = [ x for x in line.split() if not x.startswith('(') ] - info[sect_name] += lst + info[sect_name] += [ x for x in line.split() if not x.startswith('(') ] elif line == '': break else: - sect_name = line.strip(" \n:").replace(' ', '_').lower() + sect_name = line.strip(' :').replace(' ', '_').lower() info[sect_name] = [ ] saw_comma = False + for chk in 'capabilities optimizations'.split(): + if chk not in info: + info[chk] = { } for chk in 'checksum_list compress_list daemon_auth_list'.split(): if chk not in info: info[chk] = [ ] diff --git a/usage.c b/usage.c index dc66288f..a2c2a3f0 100644 --- a/usage.c +++ b/usage.c @@ -38,7 +38,7 @@ static void print_info_flags(enum logcode f) { STRUCT_STAT *dumstat; BOOL as_json = f == FNONE ? 1 : 0; /* We use 1 == first attribute, 2 == need closing array */ - char line_buf[75], *quot = as_json ? "\"" : ""; + char line_buf[75], item_buf[32]; int line_len, j; char *info_flags[] = { @@ -165,9 +165,25 @@ static void print_info_flags(enum logcode f) for (line_len = 0, j = 0; ; j++) { char *str = info_flags[j], *next_nfo = str ? info_flags[j+1] : NULL; - int str_len = str && *str != '*' ? strlen(str) + (as_json ? 2 : 0) : 1000; int need_comma = next_nfo && *next_nfo != '*' ? 1 : 0; - if (line_len && line_len + 1 + str_len + need_comma >= (int)sizeof line_buf) { + int item_len; + if (!str || *str == '*') + item_len = 1000; + else if (as_json) { + char *space = strchr(str, ' '); + int is_no = space && strncmp(str, "no ", 3) == 0; + char *quot = space && !is_no ? "\"" : ""; + char *item = space ? space + 1 : str; + char *val = !space ? "true" : is_no ? "false" : str; + int val_len = !space ? 4 : is_no ? 5 : space - str; + item_len = snprintf(item_buf, sizeof item_buf, + " \"%s\": %s%.*s%s%s", item, quot, val_len, val, quot, + need_comma ? "," : ""); + for (space = item; (space = strpbrk(space, " -")) != NULL; space++) + item_buf[space - item + 2] = '_'; + } else + item_len = snprintf(item_buf, sizeof item_buf, " %s%s", str, need_comma ? "," : ""); + if (line_len && line_len + item_len >= (int)sizeof line_buf) { if (as_json) printf(" %s\n", line_buf); else @@ -179,19 +195,19 @@ static void print_info_flags(enum logcode f) if (*str == '*') { if (as_json) { if (as_json == 2) - printf(" ]"); + printf(" }"); else as_json = 2; - printf(",\n \"%c%s\": [\n", toLower(str+1), str+2); + printf(",\n \"%c%s\": {\n", toLower(str+1), str+2); } else rprintf(f, "%s:\n", str+1); - continue; + } else { + strlcpy(line_buf + line_len, item_buf, sizeof line_buf - line_len); + line_len += item_len; } - line_len += snprintf(line_buf+line_len, sizeof line_buf - line_len, - " %s%s%s%s", quot, str, quot, need_comma ? "," : ""); } if (as_json == 2) - printf(" ]"); + printf(" }"); } static void output_nno_list(enum logcode f, const char *name, struct name_num_obj *nno) -- The rsync repository. _______________________________________________ rsync-cvs mailing list rsync-cvs@lists.samba.org https://lists.samba.org/mailman/listinfo/rsync-cvs