def get_commit_for_refspec(repo, branch_or_tag_or_sha): # Precedence order GitHub uses (& that we copy): # 1. Branch 2. Tag 3. Commit SHA commit_sha = None # branch? branch_ref = lookup_ref(repo, branch_or_tag_or_sha) if branch_ref is not None: commit_sha = branch_ref.resolve().target.hex # tag? if commit_sha is None: ref_to_tag = lookup_ref(repo, "tags/" + branch_or_tag_or_sha) if ref_to_tag is not None: commit_sha = ref_to_tag.get_object().hex # commit? if commit_sha is None: commit_sha = branch_or_tag_or_sha try: return get_commit(repo, commit_sha) except (ValueError, NotFound): raise NotFound("no such branch, tag, or commit SHA")
def get_commit_for_refspec(repo, branch_or_tag_or_sha): # Precedence order GitHub uses (& that we copy): # 1. Branch 2. Tag 3. Commit SHA commit_sha = None # branch? branch_ref = lookup_ref(repo, branch_or_tag_or_sha) if branch_ref is not None: commit_sha = branch_ref.resolve().target # tag? if commit_sha is None: ref_to_tag = lookup_ref(repo, "tags/" + branch_or_tag_or_sha) if ref_to_tag is not None: commit_sha = ref_to_tag.get_object().id # commit? if commit_sha is None: commit_sha = branch_or_tag_or_sha try: return get_commit(repo, commit_sha) except (ValueError, NotFound): raise NotFound("no such branch, tag, or commit SHA")
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 } }