From 0cf497d42f336e5945ff2a152b8f8be93558a579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Sun, 28 Feb 2016 14:25:30 +0100 Subject: [PATCH] Declare all CLI prog deps with _CMD variables Change all literal "git", "wc" and "grep" strings throughout gitstats with corresponding _CMD variables. (Also upper-case existing "gnuplot_cmd" variable while at it.) NixOS/nixpkgs[1] generally patch programs at build time to call their CLI deps with absolute paths (meaning: known versions of those deps). This makes packaging across different unix systems much more reliable. This patch makes it easier to do that build time patching :-) [1]: http://nixos.org/nix/ --- gitstats | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/gitstats b/gitstats index c71b0e4..43dbce5 100755 --- a/gitstats +++ b/gitstats @@ -32,9 +32,13 @@ time_start = time.time() # By default, gnuplot is searched from path, but can be overridden with the # environment variable "GNUPLOT" -gnuplot_cmd = 'gnuplot' +GNUPLOT_CMD = 'gnuplot' if 'GNUPLOT' in os.environ: - gnuplot_cmd = os.environ['GNUPLOT'] + GNUPLOT_CMD = os.environ['GNUPLOT'] + +GIT_CMD = 'git' +GREP_CMD = 'grep' +WC_CMD = 'wc' conf = { 'max_domains': 10, @@ -109,29 +113,29 @@ def getversion(): global VERSION if VERSION == 0: gitstats_repo = os.path.dirname(os.path.abspath(__file__)) - VERSION = getpipeoutput(["git --git-dir=%s/.git --work-tree=%s rev-parse --short %s" % + VERSION = getpipeoutput([GIT_CMD + " --git-dir=%s/.git --work-tree=%s rev-parse --short %s" % (gitstats_repo, gitstats_repo, getcommitrange('HEAD').split('\n')[0])]) return VERSION def getgitversion(): - return getpipeoutput(['git --version']).split('\n')[0] + return getpipeoutput([GIT_CMD + ' --version']).split('\n')[0] def getgnuplotversion(): - return getpipeoutput(['%s --version' % gnuplot_cmd]).split('\n')[0] + return getpipeoutput(['%s --version' % GNUPLOT_CMD]).split('\n')[0] def getnumoffilesfromrev(time_rev): """ Get number of files changed in commit """ time, rev = time_rev - return (int(time), rev, int(getpipeoutput(['git ls-tree -r --name-only "%s"' % rev, 'wc -l']).split('\n')[0])) + return (int(time), rev, int(getpipeoutput([GIT_CMD + ' ls-tree -r --name-only "%s"' % rev, WC_CMD + ' -l']).split('\n')[0])) def getnumoflinesinblob(ext_blob): """ Get number of lines in blob """ ext, blob_id = ext_blob - return (ext, blob_id, int(getpipeoutput(['git cat-file blob %s' % blob_id, 'wc -l']).split()[0])) + return (ext, blob_id, int(getpipeoutput([GIT_CMD + ' cat-file blob %s' % blob_id, WC_CMD + ' -l']).split()[0])) class DataCollector: """Manages data collection from a revision control repository.""" @@ -286,18 +290,18 @@ class GitDataCollector(DataCollector): def collect(self, dir): DataCollector.collect(self, dir) - self.total_authors += int(getpipeoutput(['git shortlog -s %s' % getlogrange(), 'wc -l'])) + self.total_authors += int(getpipeoutput([GIT_CMD + ' shortlog -s %s' % getlogrange(), WC_CMD + ' -l'])) #self.total_lines = int(getoutput('git-ls-files -z |xargs -0 cat |wc -l')) # tags - lines = getpipeoutput(['git show-ref --tags']).split('\n') + lines = getpipeoutput([GIT_CMD + ' show-ref --tags']).split('\n') for line in lines: if len(line) == 0: continue (hash, tag) = line.split(' ') tag = tag.replace('refs/tags/', '') - output = getpipeoutput(['git log "%s" --pretty=format:"%%at %%aN" -n 1' % hash]) + output = getpipeoutput([GIT_CMD + ' log "%s" --pretty=format:"%%at %%aN" -n 1' % hash]) if len(output) > 0: parts = output.split(' ') stamp = 0 @@ -311,7 +315,7 @@ class GitDataCollector(DataCollector): tags_sorted_by_date_desc = map(lambda el : el[1], reversed(sorted(map(lambda el : (el[1]['date'], el[0]), self.tags.items())))) prev = None for tag in reversed(tags_sorted_by_date_desc): - cmd = 'git shortlog -s "%s"' % tag + cmd = GIT_CMD + ' shortlog -s "%s"' % tag if prev != None: cmd += ' "^%s"' % prev output = getpipeoutput([cmd]) @@ -327,7 +331,7 @@ class GitDataCollector(DataCollector): # Collect revision statistics # Outputs "