diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-04-27 22:51:20 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-04-27 22:51:20 +0200 |
| commit | 264aa902424b64a2c82270b78863bcb845891a98 (patch) | |
| tree | 313786b625c70cbc34601cc3601dda8af6eee409 | |
| parent | 9981534f24937f25a50168dff0e27223a2eb8051 (diff) | |
Simplify obtaining version numbers from git.
If there's a tag pointing at HEAD, we use that, otherwise
just use the git hash.
| -rwxr-xr-x | cdist | 73 |
1 files changed, 5 insertions, 68 deletions
@@ -327,61 +327,6 @@ class TreeDirectory: def __exit__(self, type, value, traceback): os.chdir(self.cwd) -# -# Version -# - -class Version: - def __init__(self, s): - self.devel = False - - if s.startswith("'"): - s = s[1:] - if s.endswith("'"): - s = s[0:-1] - - if s.endswith('devel'): - s = s[0:-5] - self.devel = True - - if s.endswith('pre'): - s = s[0:-3] - - p = s.split('.') - self.major = int(p[0]) - self.minor = int(p[1]) - if len(p) == 3: - self.micro = int(p[2]) - else: - self.micro = 0 - - @classmethod - def from_git_tag(cls, tag): - bits = tag.split('-') - c = cls(bits[0]) - if len(bits) > 1 and int(bits[1]) > 0: - c.devel = True - return c - - def bump_minor(self): - self.minor += 1 - self.micro = 0 - - def bump_micro(self): - self.micro += 1 - - def to_devel(self): - self.devel = True - - def to_release(self): - self.devel = False - - def __str__(self): - s = '%d.%d.%d' % (self.major, self.minor, self.micro) - if self.devel: - s += 'devel' - - return s # # Targets @@ -1069,19 +1014,11 @@ class Tree: path = path.split(' ')[1] command('git -c protocol.file.allow=always submodule --quiet update %s %s' % (ref, path)) - if os.path.exists('%s/wscript' % proj): - v = read_wscript_variable(proj, "VERSION"); - if v is not None: - try: - self.version = Version(v) - except: - try: - tag = command_and_read('git -C %s describe --match v* --tags' % proj)[0][1:] - self.version = Version.from_git_tag(tag) - except: - # We'll leave version as None if we can't read it; maybe this is a bad idea - # Should probably just install git on the Windows VM - pass + head_tag = command_and_read(f'git -C {proj} tag -l --points-at HEAD') + if head_tag: + self.version = head_tag[0] + else: + self.version = command_and_read(f'git -C {proj} rev-parse --short HEAD')[0] os.chdir(cwd) |
