def convert_commit(repo_key, repo, commit, include_diff=False): plain_commit_json = _plumbing_convert_commit(repo_key, commit, porcelain=True) result = { "commit": plain_commit_json, "sha": plain_commit_json['sha'], "author": plain_commit_json['author'], "committer": plain_commit_json['committer'], "url": url_for('porcelain.get_commit', _external=True, repo_key=repo_key, branch_or_tag_or_sha=unicode(commit.id)), "parents": [{ "sha": unicode(c.id), "url": url_for('porcelain.get_commit', _external=True, repo_key=repo_key, branch_or_tag_or_sha=unicode(c.id)) } for c in commit.parents], } if include_diff: diff = get_diff(repo, commit) patches = list(diff) filename_to_patch = _filename_to_patch_from(diff) patches_additions = sum(patch.additions for patch in patches) patches_deletions = sum(patch.deletions for patch in patches) result.update({ "stats": { "additions": patches_additions, "deletions": patches_deletions, "total": patches_additions + patches_deletions, }, "files": [_convert_patch(repo_key, commit, patch, filename_to_patch) for patch in patches], }) return result
def convert_commit(repo_key, repo, commit, include_diff=False): plain_commit_json = _plumbing_convert_commit(repo_key, commit, porcelain=True) result = { "commit": plain_commit_json, "sha": plain_commit_json['sha'], "author": plain_commit_json['author'], "committer": plain_commit_json['committer'], "url": url_for('porcelain.get_commit', _external=True, repo_key=repo_key, branch_or_tag_or_sha=unicode(commit.id)), "parents": [{ "sha": unicode(c.id), "url": url_for('porcelain.get_commit', _external=True, repo_key=repo_key, branch_or_tag_or_sha=unicode(c.id)) } for c in commit.parents], } if include_diff: diff = get_diff(repo, commit) patches = list(diff) filename_to_patch = _filename_to_patch_from(diff) patches_additions = sum(patch.additions for patch in patches) patches_deletions = sum(patch.deletions for patch in patches) result.update({ "stats": { "additions": patches_additions, "deletions": patches_deletions, "total": patches_additions + patches_deletions, }, "files": [ _convert_patch(repo_key, commit, patch, filename_to_patch) for patch in patches ], }) return result
def convert_blame(repo_key, repo, blame, raw_lines, start_line): annotated_lines = [] commit_shas = set() for line_num, line in enumerate(raw_lines, start=start_line): hunk = blame.for_line(line_num) commit_sha = hunk.final_commit_id commit_shas.add(commit_sha) annotated_lines.append({ 'commit': commit_sha, 'origPath': hunk.orig_path, 'lineNum': line_num, 'line': line, }) return { 'lines': annotated_lines, 'commits': { commit_sha: _plumbing_convert_commit(repo_key, get_commit(repo, commit_sha)) for commit_sha in commit_shas } }
def convert_blame(repo_key, repo, blame, raw_lines, start_line): annotated_lines = [] commit_shas = set() for line_num, line in enumerate(raw_lines, start=start_line): hunk = blame.for_line(line_num) commit_sha = hunk.final_commit_id commit_shas.add(commit_sha) annotated_lines.append({ 'commit': commit_sha, 'origPath': hunk.orig_path, 'lineNum': line_num, 'line': line, }) return { 'lines': annotated_lines, 'commits': { commit_sha: _plumbing_convert_commit(repo_key, get_commit(repo, commit_sha)) for commit_sha in commit_shas } }