From 747ada77e639fcb5fa12a0378080ff9561a28a24 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 13 Dec 2017 04:33:50 +0100 Subject: [PATCH 1/5] fix building the "borg prune" man page, fixes #3398 will fix all ".. highlight:: none" issues (just killing it). also a slight punctuation fix, so there is a dot at the end of the prune man page. (cherry picked from commit 1f5b8c9219eb5e0d8c4799e8e3c984c6073d6f68) --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 891138ebe..1cd2bd006 100644 --- a/setup.py +++ b/setup.py @@ -651,6 +651,8 @@ class build_man(Command): examples = examples.replace(usage_include, '') examples = examples.replace('Examples\n~~~~~~~~', '') examples = examples.replace('Miscellaneous Help\n------------------', '') + examples = examples.replace('``docs/misc/prune-example.txt``:', '``docs/misc/prune-example.txt``.') + examples = examples.replace('.. highlight:: none\n', '') # we don't support highlight examples = re.sub('^(~+)$', lambda matches: '+' * len(matches.group(0)), examples, flags=re.MULTILINE) examples = examples.strip() if examples: From 981a936f47473e8c3a16595264a1be0b064fad12 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 13 Dec 2017 04:01:59 +0100 Subject: [PATCH 2/5] add parens for C preprocessor macro argument usages this is needed for correctness because the preprocessor is just doing text replacement. This is the correct way: #define MUL(x, y) ((x) * (y)) MUL(1+2, 3-4) -> ((1+2) * (3-4)) # not: (1+2 * 3-4) I didn't put parens around all arg usages for readability. Some stuff (like index) is not expected to be an expression. Also, when a arg is only used in another macro or function call, no parens are needed either. I reviewed the code: no harm was done (yet) due to this fault. Thanks to @rciorba who found this. (cherry picked from commit a3cecf599f42173b2fc485407aa439a9c6365d9c) --- src/borg/_chunker.c | 2 +- src/borg/_hashindex.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/borg/_chunker.c b/src/borg/_chunker.c index b72f6bd8b..4add32ac3 100644 --- a/src/borg/_chunker.c +++ b/src/borg/_chunker.c @@ -63,7 +63,7 @@ static uint32_t table_base[] = 0xc5ae37bb, 0xa76ce12a, 0x8150d8f3, 0x2ec29218, 0xa35f0984, 0x48c0647e, 0x0b5ff98c, 0x71893f7b }; -#define BARREL_SHIFT(v, shift) ( ((v) << shift) | ((v) >> ((32 - shift) & 0x1f)) ) +#define BARREL_SHIFT(v, shift) ( ((v) << (shift)) | ((v) >> ((32 - (shift)) & 0x1f)) ) size_t pagemask; diff --git a/src/borg/_hashindex.c b/src/borg/_hashindex.c index 9fbd1ebda..c7a5b0d0f 100644 --- a/src/borg/_hashindex.c +++ b/src/borg/_hashindex.c @@ -71,7 +71,7 @@ static int hash_sizes[] = { #define EMPTY _htole32(0xffffffff) #define DELETED _htole32(0xfffffffe) -#define BUCKET_ADDR(index, idx) (index->buckets + (idx * index->bucket_size)) +#define BUCKET_ADDR(index, idx) (index->buckets + ((idx) * index->bucket_size)) #define BUCKET_MATCHES_KEY(index, idx, key) (memcmp(key, BUCKET_ADDR(index, idx), index->key_size) == 0) From dbf8d582f92e4bdcb1904138ff28d0d223606ef5 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 11 Dec 2017 23:00:38 +0100 Subject: [PATCH 3/5] Add placeholder for fqdn in reverse notation (cherry picked from commit 85fb38e2f3d7c4df581f2aa58605a507003db492) --- docs/man/borg-placeholders.1 | 3 +++ docs/usage/help.rst.inc | 3 +++ src/borg/archiver.py | 3 +++ src/borg/helpers.py | 1 + 4 files changed, 10 insertions(+) diff --git a/docs/man/borg-placeholders.1 b/docs/man/borg-placeholders.1 index 3e61b7922..ba7a631a7 100644 --- a/docs/man/borg-placeholders.1 +++ b/docs/man/borg-placeholders.1 @@ -42,6 +42,9 @@ The (short) hostname of the machine. .B {fqdn} The full name of the machine. .TP +.B {reverse-fqdn} +The full name of the machine in reverse domain name notation. +.TP .B {now} The current local date and time, by default in ISO\-8601 format. You can also supply your own \fI\%format string\fP, e.g. {now:%Y\-%m\-%d_%H:%M:%S} diff --git a/docs/usage/help.rst.inc b/docs/usage/help.rst.inc index c5fb6a71e..bed681768 100644 --- a/docs/usage/help.rst.inc +++ b/docs/usage/help.rst.inc @@ -169,6 +169,9 @@ placeholders: {fqdn} The full name of the machine. +{reverse-fqdn} + The full name of the machine in reverse domain name notation. + {now} The current local date and time, by default in ISO-8601 format. You can also supply your own `format string `_, e.g. {now:%Y-%m-%d_%H:%M:%S} diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 9bc5db614..888e66025 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -2093,6 +2093,9 @@ class Archiver: {fqdn} The full name of the machine. + {reverse-fqdn} + The full name of the machine in reverse domain name notation. + {now} The current local date and time, by default in ISO-8601 format. You can also supply your own `format string `_, e.g. {now:%Y-%m-%d_%H:%M:%S} diff --git a/src/borg/helpers.py b/src/borg/helpers.py index e5f9de5ad..5008f0188 100644 --- a/src/borg/helpers.py +++ b/src/borg/helpers.py @@ -664,6 +664,7 @@ def replace_placeholders(text): data = { 'pid': os.getpid(), 'fqdn': socket.getfqdn(), + 'reverse-fqdn': '.'.join(reversed(socket.getfqdn().split('.'))), 'hostname': socket.gethostname(), 'now': DatetimeWrapper(current_time.now()), 'utcnow': DatetimeWrapper(current_time.utcnow()), From 96675e06c8c0acef9c67eddb912a5cd32524881c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 12 Dec 2017 12:44:17 +0100 Subject: [PATCH 4/5] Refactor: call getfqdn() once per call of replace_placeholders() (cherry picked from commit 294f06b565885f2e78d64fa6c26c90fd8d8c3431) --- src/borg/helpers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/borg/helpers.py b/src/borg/helpers.py index 5008f0188..cb3e10cac 100644 --- a/src/borg/helpers.py +++ b/src/borg/helpers.py @@ -661,10 +661,11 @@ def format_line(format, data): def replace_placeholders(text): """Replace placeholders in text with their values.""" current_time = datetime.now() + fqdn = socket.getfqdn() data = { 'pid': os.getpid(), - 'fqdn': socket.getfqdn(), - 'reverse-fqdn': '.'.join(reversed(socket.getfqdn().split('.'))), + 'fqdn': fqdn, + 'reverse-fqdn': '.'.join(reversed(fqdn.split('.'))), 'hostname': socket.gethostname(), 'now': DatetimeWrapper(current_time.now()), 'utcnow': DatetimeWrapper(current_time.utcnow()), From 00865ae89e075cd4844b3c191407987688bea42b Mon Sep 17 00:00:00 2001 From: Nils Steinger Date: Fri, 6 Oct 2017 02:09:17 +0200 Subject: [PATCH 5/5] List help topics when invalid topic is requested (cherry picked from commit 9e81a7617216e16adaefad83fb58e22af9ddc9f8) --- src/borg/archiver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 888e66025..b2db6cc98 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -2205,7 +2205,12 @@ class Archiver: else: commands[args.topic].print_help() else: - parser.error('No help available on %s' % (args.topic,)) + msg_lines = [] + msg_lines += ['No help available on %s.' % args.topic] + msg_lines += ['Try one of the following:'] + msg_lines += [' Commands: %s' % ', '.join(sorted(commands.keys()))] + msg_lines += [' Topics: %s' % ', '.join(sorted(self.helptext.keys()))] + parser.error('\n'.join(msg_lines)) return self.exit_code def do_subcommand_help(self, parser, args):