Commit 22f8b2d6 authored by Gustavo Padovan's avatar Gustavo Padovan

contribution-stats: add --output option

parent 8fda64ee
......@@ -24,7 +24,16 @@ docs instructions.
### Contributions stats
To use it run the below from within your kernel directory:
```
git log --pretty='format:%h,"%s",,' <range> | <path to>/contribution-stats.py
```
Options:
* `-s, --summary`: show only a summary with the numbers for each person, but no details
* `-o, --output`: output result to a file instead of stdout
### Generating HTML tree view
......
......@@ -54,19 +54,32 @@ def is_maintainer(commit, email, name):
def total_commits(d):
return sum((v[0] for v in d.values()))
def print_commits(dict, args):
def print_commits(f, dict, summary):
for email, data in sorted(dict.items(), key=lambda item: item[1], reverse=True):
print("%s <%s> %d" % (contributors[email], email, data[0]))
if not args.summary:
f.write("%s <%s> (%d):\n" % (contributors[email], email, data[0]))
if not summary:
for c in data[1]:
print("\t%s %s" % (c[0][0:9], c[1]))
print("")
f.write("\t%s %s\n" % (c[0][0:9], c[1]))
f.write("\n")
def print_all(results, args):
f = open(args.output, "w") if args.output else sys.stdout
for r in results:
f.write("{}\n\n".format(r[0]))
print_commits(f, r[1], args.summary)
f.write("\n")
if f is not sys.stdout:
f.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.set_defaults(func=lambda x: parser.print_help())
parser.add_argument('-s', '--summary', action='store_true',
help="enable details for each section")
parser.add_argument('-o', '--output', metavar="FILE",
help="output to a file instead of stdout")
args = parser.parse_args(sys.argv[1:])
repo = Repository(os.getcwd())
......@@ -96,24 +109,13 @@ if __name__ == "__main__":
for m in match:
add_contributor(contributors, m[1], m[0])
add_commit(tag[1], m[1], commit)
print("# Authored (%d)\n" % total_commits(authored))
print_commits(authored, args)
print("")
print("# Maintainer Committed (%d)\n" % total_commits(committed))
print_commits(committed, args)
print("")
print("# Signed-off-by: (%d)\n" % total_commits(signed))
print_commits(signed, args)
print("")
print("# On behalf of: (%d)\n" % total_commits(onbehalf))
print_commits(onbehalf, args)
print("")
results = []
results.append(("Authored ({}):".format(total_commits(authored)), authored))
results.append(("Maintainer Committed ({}):".format(total_commits(committed)), committed))
results.append(("Signed-off-by ({}):".format(total_commits(signed)), signed))
results.append(("On behalf of ({}):".format(total_commits(onbehalf)), onbehalf))
for tag in OTHER_TAGS:
print("# %s (%d)\n" % (tag[0],total_commits(tag[1])))
print_commits(tag[1], args)
print("")
results.append(("{} ({}):".format(tag[0],total_commits(tag[1])), tag[1]))
print_all(results, args)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment