def diff(args): """Return a list of filenames for the given diff arguments :param args: list of arguments to pass to "git diff --name-only" """ out = git.diff(name_only=True, z=True, *args)[STDOUT] return _parse_diff_filenames(out)
def renamed_files(start, end, git=git): difflines = git.diff('%s..%s' % (start, end), M=True, **_common_diff_opts()).splitlines() return [ eval_path(r[12:].rstrip()) for r in difflines if r.startswith('rename from ') ]
def diff_helper(commit=None, ref=None, endref=None, filename=None, cached=True, head=None, amending=False, with_diff_header=False, suppress_header=True, reverse=False, git=git): "Invokes git diff on a filepath." encode = core.encode if commit: ref, endref = commit + '^', commit argv = [] if ref and endref: argv.append('%s..%s' % (ref, endref)) elif ref: for r in utils.shell_split(ref.strip()): argv.append(r) elif head and amending and cached: argv.append(head) encoding = None if filename: argv.append('--') if type(filename) is list: argv.extend(filename) else: argv.append(filename) encoding = config.file_encoding(filename) if filename is not None: deleted = cached and not os.path.exists(encode(filename)) else: deleted = False status, diffoutput = git.diff(R=reverse, M=True, cached=cached, with_status=True, *argv, **_common_diff_opts()) if status != 0: # git init if with_diff_header: return ('', '') else: return '' return extract_diff_header(status, deleted, encoding, with_diff_header, suppress_header, diffoutput)
def diff_helper(commit=None, ref=None, endref=None, filename=None, cached=True, head=None, amending=False, with_diff_header=False, suppress_header=True, reverse=False, git=git): "Invokes git diff on a filepath." encode = core.encode if commit: ref, endref = commit+'^', commit argv = [] if ref and endref: argv.append('%s..%s' % (ref, endref)) elif ref: for r in utils.shell_split(ref.strip()): argv.append(r) elif head and amending and cached: argv.append(head) encoding = None if filename: argv.append('--') if type(filename) is list: argv.extend(filename) else: argv.append(filename) encoding = config.file_encoding(filename) if filename is not None: deleted = cached and not os.path.exists(encode(filename)) else: deleted = False status, diffoutput = git.diff(R=reverse, M=True, cached=cached, with_status=True, *argv, **_common_diff_opts()) if status != 0: # git init if with_diff_header: return ('', '') else: return '' return extract_diff_header(status, deleted, encoding, with_diff_header, suppress_header, diffoutput)
def diff_helper(commit=None, ref=None, endref=None, filename=None, cached=True, deleted=False, head=None, amending=False, with_diff_header=False, suppress_header=True, reverse=False, git=git): "Invokes git diff on a filepath." if commit: ref, endref = commit + '^', commit argv = [] if ref and endref: argv.append('%s..%s' % (ref, endref)) elif ref: for r in utils.shell_split(ref.strip()): argv.append(r) elif head and amending and cached: argv.append(head) encoding = None if filename: argv.append('--') if type(filename) is list: argv.extend(filename) else: argv.append(filename) cfg = gitcfg.current() encoding = cfg.file_encoding(filename) status, out, err = git.diff(R=reverse, M=True, cached=cached, _encoding=encoding, *argv, **common_diff_opts()) if status != 0: # git init if with_diff_header: return ('', '') else: return '' return extract_diff_header(status, deleted, with_diff_header, suppress_header, out)
def diff_helper( commit=None, ref=None, endref=None, filename=None, cached=True, head=None, amending=False, with_diff_header=False, suppress_header=True, reverse=False, git=git, ): "Invokes git diff on a filepath." if commit: ref, endref = commit + "^", commit argv = [] if ref and endref: argv.append("%s..%s" % (ref, endref)) elif ref: for r in utils.shell_split(ref.strip()): argv.append(r) elif head and amending and cached: argv.append(head) encoding = None if filename: argv.append("--") if type(filename) is list: argv.extend(filename) else: argv.append(filename) encoding = config.file_encoding(filename) if filename is not None: deleted = cached and not core.exists(filename) else: deleted = False status, out, err = git.diff(R=reverse, M=True, cached=cached, _encoding=encoding, *argv, **common_diff_opts()) if status != 0: # git init if with_diff_header: return ("", "") else: return "" return extract_diff_header(status, deleted, with_diff_header, suppress_header, out)
def diff_helper(commit=None, ref=None, endref=None, filename=None, cached=True, deleted=False, head=None, amending=False, with_diff_header=False, suppress_header=True, reverse=False, git=git): "Invokes git diff on a filepath." if commit: ref, endref = commit+'^', commit argv = [] if ref and endref: argv.append('%s..%s' % (ref, endref)) elif ref: for r in utils.shell_split(ref.strip()): argv.append(r) elif head and amending and cached: argv.append(head) encoding = None if filename: argv.append('--') if type(filename) is list: argv.extend(filename) else: argv.append(filename) cfg = gitcfg.current() encoding = cfg.file_encoding(filename) status, out, err = git.diff(R=reverse, M=True, cached=cached, _encoding=encoding, *argv, **common_diff_opts()) if status != 0: # git init if with_diff_header: return ('', '') else: return '' return extract_diff_header(status, deleted, with_diff_header, suppress_header, out)
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
def sha1_diff(git, sha1): return git.diff(sha1 + '^!', **common_diff_opts())[STDOUT]
def sha1_diff(git, sha1): return core.decode(git.diff(sha1+'~', sha1, **_common_diff_opts()))
def sha1_diff(git, sha1, filename=None): if filename is None: return git.diff(sha1 + '^!', **common_diff_opts())[STDOUT] else: return git.diff(sha1 + '^!', filename, **common_diff_opts())[STDOUT]
def sha1_diff(git, sha1, filename=None): if filename is None: return git.diff(sha1 + "^!", **common_diff_opts())[STDOUT] else: return git.diff(sha1 + "^!", filename, **common_diff_opts())[STDOUT]
def renamed_files(start, end, git=git): difflines = git.diff('%s..%s' % (start, end), M=True, **_common_diff_opts()).splitlines() return [eval_path(r[12:].rstrip()) for r in difflines if r.startswith('rename from ')]
def diff_helper( commit=None, ref=None, endref=None, filename=None, cached=True, with_diff_header=False, suppress_header=True, reverse=False, git=git, ): "Invokes git diff on a filepath." encode = core.encode if commit: ref, endref = commit + "^", commit argv = [] if ref and endref: argv.append("%s..%s" % (ref, endref)) elif ref: for r in utils.shell_split(ref.strip()): argv.append(r) if filename: argv.append("--") if type(filename) is list: argv.extend(filename) else: argv.append(filename) start = False del_tag = "deleted file mode " headers = [] deleted = cached and not os.path.exists(encode(filename)) status, diffoutput = git.diff(R=reverse, M=True, cached=cached, with_status=True, *argv, **_common_diff_opts()) if status != 0: # git init if with_diff_header: return ("", "") else: return "" if diffoutput.startswith("Submodule"): if with_diff_header: return ("", diffoutput) else: return diffoutput output = StringIO() diff = core.decode(diffoutput).split("\n") for line in diff: if not start and "@@" == line[:2] and "@@" in line[2:]: start = True if start or (deleted and del_tag in line): output.write(encode(line) + "\n") else: if with_diff_header: headers.append(encode(line)) elif not suppress_header: output.write(encode(line) + "\n") result = core.decode(output.getvalue()) output.close() if with_diff_header: return ("\n".join(headers), result) else: return result
def sha1_diff(sha1, git=git): return core.decode(git.diff(sha1 + '^!', **_common_diff_opts()))
def diff_helper(commit=None, branch=None, ref=None, endref=None, filename=None, cached=True, with_diff_header=False, suppress_header=True, reverse=False, git=git): "Invokes git diff on a filepath." encode = core.encode if commit: ref, endref = commit+'^', commit argv = [] if ref and endref: argv.append('%s..%s' % (ref, endref)) elif ref: for r in ref.strip().split(): argv.append(r) elif branch: argv.append(branch) if filename: argv.append('--') if type(filename) is list: argv.extend(filename) else: argv.append(filename) start = False del_tag = 'deleted file mode ' headers = [] deleted = cached and not os.path.exists(encode(filename)) diffoutput = git.diff(R=reverse, M=True, cached=cached, *argv, **_common_diff_opts()) # Handle 'git init' if diffoutput.startswith('fatal:'): if with_diff_header: return ('', '') else: return '' if diffoutput.startswith('Submodule'): if with_diff_header: return ('', diffoutput) else: return diffoutput output = StringIO() diff = core.decode(diffoutput).split('\n') for line in diff: if not start and '@@' == line[:2] and '@@' in line[2:]: start = True if start or (deleted and del_tag in line): output.write(encode(line) + '\n') else: if with_diff_header: headers.append(encode(line)) elif not suppress_header: output.write(encode(line) + '\n') result = core.decode(output.getvalue()) output.close() if with_diff_header: return('\n'.join(headers), result) else: return result
def sha1_diff(git, sha1): return core.decode(git.diff(sha1 + '~', sha1, **_common_diff_opts()))
def diff_helper(commit=None, ref=None, endref=None, filename=None, cached=True, head=None, amending=False, with_diff_header=False, suppress_header=True, reverse=False, git=git): "Invokes git diff on a filepath." encode = core.encode if commit: ref, endref = commit+'^', commit argv = [] if ref and endref: argv.append('%s..%s' % (ref, endref)) elif ref: for r in utils.shell_split(ref.strip()): argv.append(r) elif head and amending and cached: argv.append(head) encoding = None if filename: argv.append('--') if type(filename) is list: argv.extend(filename) else: argv.append(filename) encoding = config.file_encoding(filename) start = False del_tag = 'deleted file mode ' headers = [] if filename is not None: deleted = cached and not os.path.exists(encode(filename)) else: deleted = False status, diffoutput = git.diff(R=reverse, M=True, cached=cached, with_status=True, *argv, **_common_diff_opts()) if status != 0: # git init if with_diff_header: return ('', '') else: return '' if diffoutput.startswith('Submodule'): if with_diff_header: return ('', diffoutput) else: return diffoutput output = StringIO() diff = core.decode(diffoutput, encoding=encoding).split('\n') for line in diff: if not start and '@@' == line[:2] and '@@' in line[2:]: start = True if start or (deleted and del_tag in line): output.write(encode(line) + '\n') else: if with_diff_header: headers.append(encode(line)) elif not suppress_header: output.write(encode(line) + '\n') result = core.decode(output.getvalue()) output.close() if with_diff_header: return('\n'.join(headers), result) else: return result
def sha1_diff(git, sha1): return git.diff(sha1+'^!', **common_diff_opts())[STDOUT]