X-Git-Url: https://git.ralfj.de/mass-build.git/blobdiff_plain/cd1b16983d17b2cf8675166758c48fe4bfd0bb0a..f5fc2c7cd2999eb0af27dffb9d99b594940d463f:/vcs.py diff --git a/vcs.py b/vcs.py index 02a9192..89a4920 100644 --- a/vcs.py +++ b/vcs.py @@ -1,5 +1,5 @@ # mass-build - Easily Build Software Involving a Large Amount of Source Repositories -# Copyright (C) 2012 Ralf Jung +# Copyright (C) 2012-2013 Ralf Jung # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -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 get_non_digit_prefix(val): + return re.match('[^0-9]*', val).group(0) + # Fetch updates from git class Git: - - def __init__(self, folder, url, commit): + def __init__(self, folder, config): 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=''): @@ -84,24 +86,18 @@ class Git: 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 non-digit prefix from v (so that it starts with a number) def checkVersions(self): + self.update(mode = MODE_FETCH) repo = git.Repo(self.folder) - # get tag 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]) - # get sorted list of tag names + currentVersion = repo.git.describe() + # get sorted list of tag names with the same non-digit prefix and higher version number 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:" + print "Versions newer than "+currentVersion+" available:" print tags # Fetch updates via SVN @@ -110,10 +106,11 @@ class SVN: self.folder = os.path.abspath(folder) self.url = url - def update(self, forceVersion=False): + def update(self, mode = MODE_REBASE): + if mode == MODE_FETCH: raise Exception("Just fetching is not supported with SVN") if os.path.exists(self.folder): os.chdir(self.folder) # go into repository - if forceVersion: subprocess.check_call(['svn', 'revert', '-R', '.']) + if mode == MODE_RESET: subprocess.check_call(['svn', 'revert', '-R', '.']) subprocess.check_call(['svn', 'switch', self.url]) # and update to the URL we got else: os.makedirs(self.folder) # if even the parent folder does not exist, svn fails