From b847751882c3ad217aee6e073aafac38495f8d34 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Tue, 8 Jul 2008 15:02:47 +0200 Subject: [PATCH] gitstats: Improved the output of 'branch -b' with '-d' The main difference is that the intermediate results (e.g. the dilution per-branch) is now also shown, instead of only showing the metrics of the best branch. As a bonus the branch names are now printed using prettyName, instead of printing their hashes. --- src/git_stats/branch.py | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/git_stats/branch.py b/src/git_stats/branch.py index 44c32b4..b1aadd4 100644 --- a/src/git_stats/branch.py +++ b/src/git_stats/branch.py @@ -8,23 +8,6 @@ from git import Repo from git_stats import parse -class Metric: - """This class represents a metric - - It is meant to store arbitrary data related to a specific metric. - """ - - def __init__(self): - self.branch = "" - self.commit = "" - self.dilution = "" - - def __str__(self): - res = "We found that on branch %s, commit %s has a dilution of %d." % \ - (self.branch, self.commit, self.dilution) - - return res - def prettyName(branch): """Looks up the name of a branch and returns it @@ -42,6 +25,23 @@ def prettyName(branch): return name +class Metric: + """This class represents a metric + + It is meant to store arbitrary data related to a specific metric. + """ + + def __init__(self): + self.branch = "" + self.commit = "" + self.dilution = "" + + def __str__(self): + res = "Branch %s, dilution: %d." % \ + (prettyName(self.branch), self.dilution) + + return res + def _bestMetric(metrics): """Finds the best metric from a set @@ -228,6 +228,13 @@ def belongsTo(commit, debug=False): metric = _calculateDilution(commit, metric, parent_lists, memory) metrics = metrics + metric + debugPrint(debug, "Done.\n") + + if debug: + print("Listing found metrics:") + for metric in metrics: + print(metric) + min, champs = _bestMetric(metrics) debugPrint(debug, "Done.\n") @@ -239,10 +246,7 @@ def belongsTo(commit, debug=False): # Loop over all the champs and exclude any subsets for metric in champs: - if debug: - results.append(metric) - else: - results.append(prettyName(metric.branch)) + results.append(prettyName(metric.branch)) return results -- 2.11.4.GIT