Repository: borgbackup/borg

Issue:
borgversionN placeholder
borgversion currently expands to e.g. `1.1.0b3.dev6+ng1030660.d20161007`.
that's correct, but for client / server multiple versions support, it is a bit much.

so, add some more placeholders, that expand like:

borgversion1 1
borgversion2 1.1
borgversion3 1.1.0

With this, I guess people would usually use borgversion2 on the client to select the borg version on the server via --remote-path borg-{borgversion2}. On the server, borg-1.1 would just symlink to the latest 1.1.x release.



Discussion:
Shouldn't it already be e.g. 1.0.7 with a tagged version?

{borgmajor} = 1, {borgminor} = 1.1 would make sense; we follow semver (I think?) so we can call it by name.

Yes, borgversion is 1.0.7 if you use 1.0.7 release.

But that's not as useful as 1.0, because one usually does not want to request a specific bugfix version, but just some compatible version.

@RonnyPfannschmidt Hmm, I suspect setuptools_scm assembles the version string from components, so it would be nice if it also offered a version tuple, so we do not need to do the split.

setuptools_scm does not work with components at all


Resolving patch:
diff --git a/borg/__init__.py b/borg/__init__.py
--- a/borg/__init__.py
+++ b/borg/__init__.py
@@ -1,3 +1,6 @@
-# This is a python package
+from distutils.version import LooseVersion
 
 from ._version import version as __version__
+
+
+__version_tuple__ = tuple(LooseVersion(__version__).version[:3])
diff --git a/borg/archiver.py b/borg/archiver.py
--- a/borg/archiver.py
+++ b/borg/archiver.py
@@ -949,7 +949,19 @@ def do_break_lock(self, args, repository):
 
         {borgversion}
 
-            The version of borg.
+            The version of borg, e.g.: 1.0.8rc1
+
+        {borgmajor}
+
+            The version of borg, only the major version, e.g.: 1
+
+        {borgminor}
+
+            The version of borg, only major and minor version, e.g.: 1.0
+
+        {borgpatch}
+
+            The version of borg, only major, minor and patch version, e.g.: 1.0.8
 
        Examples::
 
@@ -1229,8 +1241,8 @@ def build_parser(self, args=None, prog=None):
         '.checkpoint.N' (with N being a number), because these names are used for
         checkpoints and treated in special ways.
 
-        In the archive name, you may use the following format tags:
-        {now}, {utcnow}, {fqdn}, {hostname}, {user}, {pid}, {borgversion}
+        In the archive name, you may use the following placeholders:
+        {now}, {utcnow}, {fqdn}, {hostname}, {user} and some others.
 
         To speed up pulling backups over sshfs and similar network file systems which do
         not provide correct inode information the --ignore-inode flag can be used. This
diff --git a/borg/helpers.py b/borg/helpers.py
--- a/borg/helpers.py
+++ b/borg/helpers.py
@@ -28,6 +28,7 @@
 from operator import attrgetter
 
 from . import __version__ as borg_version
+from . import __version_tuple__ as borg_version_tuple
 from . import hashindex
 from . import chunker
 from . import crypto
@@ -585,6 +586,9 @@ def replace_placeholders(text):
         'utcnow': current_time.utcnow(),
         'user': uid2user(os.getuid(), os.getuid()),
         'borgversion': borg_version,
+        'borgmajor': '%d' % borg_version_tuple[:1],
+        'borgminor': '%d.%d' % borg_version_tuple[:2],
+        'borgpatch': '%d.%d.%d' % borg_version_tuple[:3],
     }
     return format_line(text, data)
 


Test patch: