make version check smarter: only compare to tags having the same non-digit prefix
authorRalf Jung <post@ralfj.de>
Wed, 13 Feb 2013 16:05:31 +0000 (17:05 +0100)
committerRalf Jung <post@ralfj.de>
Wed, 13 Feb 2013 16:05:31 +0000 (17:05 +0100)
mass_build.py
vcs.py

index 0060da2c5118597ab24eba73a82d9c2a648bc203..1732565259b308d04f93451eb8aecd2542e02fe0 100755 (executable)
@@ -28,7 +28,7 @@ class Project:
                # VCS
                vcsName = config['vcs']
                if vcsName == 'git':
                # VCS
                vcsName = config['vcs']
                if vcsName == 'git':
-                       self.vcs = vcs.Git(self.sourceFolder(), config['url'], config['version'])
+                       self.vcs = vcs.Git(self.sourceFolder(), config)
                elif vcsName == 'svn':
                        self.vcs = vcs.SVN(self.sourceFolder(), config['url'])
                else:
                elif vcsName == 'svn':
                        self.vcs = vcs.SVN(self.sourceFolder(), config['url'])
                else:
diff --git a/vcs.py b/vcs.py
index 3e04f465cd937a689a42fd802b0cd222c9e34c9b..d6e2028bd5be2bb48f9b35760ae6fefb0b36240e 100644 (file)
--- a/vcs.py
+++ b/vcs.py
@@ -27,13 +27,15 @@ MODE_RESET = 2
 def natural_sort_key(val):
        return [ (int(c) if c.isdigit() else c) for c in re.split('([0-9]+)', val) ]
 
 def natural_sort_key(val):
        return [ (int(c) if c.isdigit() else c) for c in re.split('([0-9]+)', val) ]
 
+def get_non_digit_prefix(val):
+       return re.match('[^0-9]*', val).group(0)
+
 # Fetch updates from git
 class Git:
 # Fetch updates from git
 class Git:
-       
-       def __init__(self, folder, url, commit):
+       def __init__(self, folder, config):
                self.folder = os.path.abspath(folder)
                self.folder = os.path.abspath(folder)
-               self.url = url
-               self.commit = commit
+               self.url = config['url']
+               self.commit = config['version']
 
        class _ProgressPrinter(git.remote.RemoteProgress):
                def update(self, op_code, cur_count, max_count=None, message=''):
 
        class _ProgressPrinter(git.remote.RemoteProgress):
                def update(self, op_code, cur_count, max_count=None, message=''):
@@ -84,21 +86,21 @@ class Git:
        def version(self):
                repo = git.Repo(self.folder)
                v = repo.git.describe()
        def version(self):
                repo = git.Repo(self.folder)
                v = repo.git.describe()
-               if v.startswith('v'): v = v[1:]
-               return v
+               return v[len(get_non_digit_prefix(v)):] # remove the letter prefix from v (so that it starts with a number)
 
        def checkVersions(self):
 
        def checkVersions(self):
+               self.update(mode =  MODE_FETCH)
                repo = git.Repo(self.folder)
                repo = git.Repo(self.folder)
-               # get tag for current commit, if any
+               # get tag name for current commit, if any
                commit = repo.commit(self.commit)
                commitTag = filter(lambda t: t.commit == commit, repo.tags)
                if not commitTag:
                        print "Version is not a tag"
                        return
                currentVersion = str(commitTag[0])
                commit = repo.commit(self.commit)
                commitTag = filter(lambda t: t.commit == commit, repo.tags)
                if not commitTag:
                        print "Version is not a tag"
                        return
                currentVersion = str(commitTag[0])
-               # get sorted list of tag names
+               # get sorted list of tag names with the same letter prefix and higher version number
                tags = map(str, repo.tags)
                tags = map(str, repo.tags)
-               tags = filter(lambda t: natural_sort_key(t) > natural_sort_key(currentVersion), tags)
+               tags = filter(lambda t: get_non_digit_prefix(t) == get_non_digit_prefix(currentVersion) and natural_sort_key(t) > natural_sort_key(currentVersion), tags)
                if not tags: return
                tags.sort(key = natural_sort_key)
                print "Versions newer than "+self.commit+" available:"
                if not tags: return
                tags.sort(key = natural_sort_key)
                print "Versions newer than "+self.commit+" available:"