Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/version, etc: fix version number detection stuff.
Gabriel Filion pointed out that bup's version number (which we added to the man pages automatically) was not detected when you used a bup tarball generated from 'git archive' (or more likely, you let GitHub call 'git archive' for you). That makes sense, since our version detection was based on having a .git directory around, which the tarball doesn't. Instead, let's create a .gitattributes file and have it auto-substitute some version information during 'git archive'. Of course, if we actually *do* have a .git directory, continue to use that. While we're here, add a new 'bup version' command and alias "bup --version" and "bup -V" to call it, since those options are pretty standard.
- Loading branch information
Showing
8 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/bup | ||
/cmd/bup-* | ||
/lib/bup/_version.py | ||
randomgen | ||
memtest | ||
*.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
import sys, os, glob | ||
from bup import options, _version | ||
|
||
optspec = """ | ||
bup version [--date|--commit|--tag] | ||
-- | ||
date display the date this version of bup was created | ||
commit display the git commit id of this version of bup | ||
tag display the tag name of this version. If no tag is available, display the commit id | ||
""" | ||
o = options.Options('bup version', optspec) | ||
(opt, flags, extra) = o.parse(sys.argv[1:]) | ||
|
||
def autoname(names): | ||
names = names.strip() | ||
assert(names[0] == '(') | ||
assert(names[-1] == ')') | ||
names = names[1:-1] | ||
l = [n.strip() for n in names.split(',')] | ||
for n in l: | ||
if n.startswith('tag: bup-'): | ||
return n[9:] | ||
|
||
|
||
total = (opt.date or 0) + (opt.commit or 0) + (opt.tag or 0) | ||
if total > 1: | ||
o.fatal('at most one option expected') | ||
|
||
if opt.date: | ||
print _version.DATE.split(' ')[0] | ||
elif opt.commit: | ||
print _version.COMMIT | ||
else: | ||
print autoname(_version.NAMES) or 'unknown-%s' % _version.COMMIT[:7] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env perl | ||
use warnings; | ||
use strict; | ||
|
||
sub fix($) { | ||
my $s = shift; | ||
chomp $s; | ||
return $s; | ||
} | ||
|
||
while (<>) { | ||
s{ | ||
\$Format:\%d\$ | ||
}{ | ||
my $tag = fix(`git describe --match="bup-*"`); | ||
"(tag: $tag)" | ||
}ex; | ||
|
||
s{ | ||
\$Format:([^\$].*)\$ | ||
}{ | ||
fix(`git log -1 --format="$1"`) | ||
}ex; | ||
print; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_version.py.pre export-subst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
COMMIT='$Format:%H$' | ||
NAMES='$Format:%d$' | ||
DATE='$Format:%ci$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters