def blame(filename): """Run git blame on a file and return a mapping from each author to the number of lines of code each author accounts for.""" try: output = captureSh('git blame -p %s' % filename, stderr=subprocess.PIPE) except subprocess.CalledProcessError: # may be a submodule print('Warning: Skipping', filename, '- could not git blame') return {} authors = {} current_commit = None commit_to_author = {} commit_to_num_lines = defaultdict(int) num_lines = None for line in output.split('\n'): m = re.search('^([0-9a-f]{40}) \d+ \d+ (\d+)$', line) if m is not None: current_commit = m.group(1) num_lines = int(m.group(2)) commit_to_num_lines[current_commit] += num_lines continue m = re.search('^author (.*)$', line) if m is not None: author = Author.get(m.group(1)) commit_to_author[current_commit] = author continue author_to_num_lines = defaultdict(int) for commit, num_lines in commit_to_num_lines.items(): author = commit_to_author[commit] author_to_num_lines[author] += num_lines return author_to_num_lines
from common import captureSh import os import re import subprocess import sys __all__ = ['coordinator_port', 'default_disk1','default_disk2', 'git_branch', 'git_ref', 'git_diff', 'hosts', 'obj_dir', 'obj_path', 'scripts_path', 'second_backup_port', 'server_port', 'top_path'] # git_branch is the name of the current git branch, which is used # for purposes such as computing objDir. try: git_branch = re.search('^refs/heads/(.*)$', captureSh('git symbolic-ref -q HEAD 2>/dev/null')) except subprocess.CalledProcessError: git_branch = None obj_dir = 'obj' else: git_branch = git_branch.group(1) obj_dir = 'obj.%s' % git_branch # git_ref is the id of the commit at the HEAD of the current branch. try: git_ref = captureSh('git rev-parse HEAD 2>/dev/null') except subprocess.CalledProcessError: git_ref = '{{unknown commit}}' # git_diff is None if the working directory and index are clean, otherwise # it is a string containing the unified diff of the uncommitted changes.
import os import re import subprocess import sys __all__ = [ 'coordinator_port', 'default_disk1', 'default_disk2', 'git_branch', 'git_ref', 'git_diff', 'hosts', 'obj_dir', 'obj_path', 'scripts_path', 'second_backup_port', 'server_port', 'top_path' ] # git_branch is the name of the current git branch, which is used # for purposes such as computing objDir. try: git_branch = re.search('^refs/heads/(.*)$', captureSh('git symbolic-ref -q HEAD 2>/dev/null')) except subprocess.CalledProcessError: git_branch = None obj_dir = 'obj' else: git_branch = git_branch.group(1) obj_dir = 'obj.%s' % git_branch # git_ref is the id of the commit at the HEAD of the current branch. try: git_ref = captureSh('git rev-parse HEAD 2>/dev/null') except subprocess.CalledProcessError: git_ref = '{{unknown commit}}' # git_diff is None if the working directory and index are clean, otherwise # it is a string containing the unified diff of the uncommitted changes.
from common import captureSh import os import re import subprocess import sys __all__ = ['git_branch', 'hosts', 'obj_dir', 'obj_path', 'scripts_path', 'top_path'] # git_branch is the name of the current git branch, which is used # for purposes such as computing objDir. try: git_branch = re.search('^refs/heads/(.*)$', captureSh('git symbolic-ref -q HEAD 2>/dev/null')) except subprocess.CalledProcessError: git_branch = None obj_dir = 'obj' else: git_branch = git_branch.group(1) obj_dir = 'obj.%s' % git_branch # obj_dir is the name of the directory containing binaries for the current # git branch (it's just a single name such as "obj.master", not a full path) obj_dir = 'build' # The full path name of the directory containing this script file. scripts_path = os.path.dirname(os.path.abspath(__file__)) # The full pathname of the parent of scriptsPath (the top-level directory
"git_branch", "git_ref", "git_diff", "obj_dir", "obj_path", "scripts_path", "second_backup_port", "server_port", "top_path", "getHosts", ] # git_branch is the name of the current git branch, which is used # for purposes such as computing objDir. try: git_branch = re.search("^refs/heads/(.*)$", captureSh("git symbolic-ref -q HEAD 2>/dev/null")) except subprocess.CalledProcessError: git_branch = None obj_dir = "obj" else: git_branch = git_branch.group(1) obj_dir = "obj.%s" % git_branch # git_ref is the id of the commit at the HEAD of the current branch. try: git_ref = captureSh("git rev-parse HEAD 2>/dev/null") except subprocess.CalledProcessError: git_ref = "{{unknown commit}}" # git_diff is None if the working directory and index are clean, otherwise # it is a string containing the unified diff of the uncommitted changes.
from common import captureSh import os import re import subprocess import sys __all__ = [ 'git_branch', 'hosts', 'obj_dir', 'obj_path', 'scripts_path', 'smokehosts', 'top_path' ] # git_branch is the name of the current git branch, which is used # for purposes such as computing objDir. try: git_branch = re.search('^refs/heads/(.*)$', captureSh('git symbolic-ref -q HEAD 2>/dev/null')) except subprocess.CalledProcessError: git_branch = None obj_dir = 'obj' else: git_branch = git_branch.group(1) obj_dir = 'obj.%s' % git_branch # obj_dir is the name of the directory containing binaries for the current # git branch (it's just a single name such as "obj.master", not a full path) obj_dir = 'build' # The full path name of the directory containing this script file. scripts_path = os.path.dirname(os.path.abspath(__file__)) # The full pathname of the parent of scriptsPath (the top-level directory
def get_commits_by_author(): """Return a map from author to the number of commits that author has made.""" output = captureSh('git log --pretty=format:%an').split('\n') return seq_to_freq(map(Author.get, output))
dumpstr.print_report(report) s = dumpstr.upload_report('gitrepo', report, trends) print('You can view your report at %s' % s['url']) def get_commits_by_author(): """Return a map from author to the number of commits that author has made.""" output = captureSh('git log --pretty=format:%an').split('\n') return seq_to_freq(map(Author.get, output)) if __name__ == '__main__': # A complete list of files in the repo. files = captureSh('git ls-files').split('\n') # Uncomment this during testing to skip about 90% of the files and make the # script run faster. #files = filter(lambda x: random.randrange(10) == 0, files) blame_data = dict([(filename, blame(filename)) for filename in files]) commits_by_author = get_commits_by_author() num_commits = sum(commits_by_author.values()) report = [] trends = [] summary_lines = []
return output.strip() # git_branch is the name of the current git branch, which is used # for purposes such as computing objDir. try: # git_branch = re.search('^refs/heads/(.*)$', captureSh('git symbolic-ref -q HEAD 2>/dev/null')) git_branch = "master" except subprocess.CalledProcessError: git_branch = None obj_dir = 'obj' obj_dir = 'obj.%s' % git_branch # git_ref is the id of the commit at the HEAD of the current branch. try: git_ref = captureSh('git rev-parse HEAD 2>/dev/null') except subprocess.CalledProcessError: git_ref = '{{unknown commit}}' # git_diff is None if the working directory and index are clean, otherwise # it is a string containing the unified diff of the uncommitted changes. try: git_diff = captureSh('git diff HEAD 2>/dev/null') if git_diff == '': git_diff = None except subprocess.CalledProcessError: git_diff = '{{using unknown diff against commit}}' # obj_dir is the name of the directory containing binaries for the current # git branch (it's just a single name such as "obj.master", not a full path) if git_branch == None:
s = dumpstr.upload_report('gitrepo', report, trends) print('You can view your report at %s' % s['url']) def get_commits_by_author(): """Return a map from author to the number of commits that author has made.""" output = captureSh('git log --pretty=format:%an').split('\n') return seq_to_freq(map(Author.get, output)) if __name__ == '__main__': # A complete list of files in the repo. files = captureSh('git ls-files').split('\n') # Uncomment this during testing to skip about 90% of the files and make the # script run faster. #files = filter(lambda x: random.randrange(10) == 0, files) blame_data = dict([(filename, blame(filename)) for filename in files]) commits_by_author = get_commits_by_author() num_commits = sum(commits_by_author.values()) report = [] trends = [] summary_lines = [] report.append({'key': 'Summary', 'lines': summary_lines})