def commit_diff(sha1, git=git): commit = git.show(sha1) first_newline = commit.index("\n") if commit[first_newline + 1 :].startswith("Merge:"): return core.decode(commit) + "\n\n" + core.decode(diff_helper(commit=sha1, cached=False, suppress_header=False)) else: return core.decode(commit)
def commit_diff(sha1, git=git): commit = git.show(sha1) first_newline = commit.index('\n') if commit[first_newline + 1:].startswith('Merge:'): return (core.decode(commit) + '\n\n' + core.decode( diff_helper(commit=sha1, cached=False, suppress_header=False))) else: return core.decode(commit)
def commits_selected(self, commits): if not commits: return commit = commits[0] sha1 = commit.sha1 status, out, err = git.show(sha1, numstat=True, oneline=True, no_renames=True) if status == 0: paths = [f for f in out.splitlines() if f] if paths: paths = paths[1:] else: paths = [] self.list_files(paths)
def commits_selected(self, commits): if not commits: return commit = commits[0] sha1 = commit.sha1 status, out, err = git.show(sha1, z=True, numstat=True, oneline=True, no_renames=True) if status == 0: paths = [f for f in out.rstrip('\0').split('\0') if f] if paths: paths = paths[1:] else: paths = [] self.list_files(paths)
def sha1_diff(git, sha1, filename=None): """Return the diff for a sha1""" # Naively "$sha1^!" is what we'd like to use but that doesn't # give the correct result for merges--the diff is reversed. # Be explicit and compare sha1 against its first parent. args = [sha1 + '~', sha1] opts = common_diff_opts() _add_filename(args, filename) status, out, err = git.diff(*args, **opts) if status != 0: # We probably don't have "$sha1~" because this is the root commit. # "git show" is clever enough to handle the root commit. args = [sha1 + '^!'] _add_filename(args, filename) status, out, err = git.show(pretty='format:', *args, **opts) out = out.lstrip() return out