X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/blobdiff_plain/78e5af69d99659769b052e4c00fe5b23a8356231..b9756849c9297b23f0628bcb08bad9a52a8aacf8:/stgit/git.py diff --git a/stgit/git.py b/stgit/git.py index 570003c..4d01fc2 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -190,8 +190,24 @@ def ls_files(files, tree = 'HEAD', full_name = True): 'Some of the given paths are either missing or not known to GIT' return list(fileset) +def parse_git_ls(output): + """Parse the output of git diff-index, diff-files, etc. Doesn't handle + rename/copy output, so don't feed it output generated with the -M + or -C flags.""" + t = None + for line in output.split('\0'): + if not line: + # There's a zero byte at the end of the output, which + # gives us an empty string as the last "line". + continue + if t == None: + mode_a, mode_b, sha1_a, sha1_b, t = line.split(' ') + else: + yield (t, line) + t = None + def tree_status(files = None, tree_id = 'HEAD', unknown = False, - noexclude = True, verbose = False, diff_flags = []): + noexclude = True, verbose = False): """Get the status of all changed files, or of a selected set of files. Returns a list of pairs - (status, filename). @@ -236,16 +252,15 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False, # specified when calling the function (i.e. report all files) or # files were specified but already found in the previous step if not files or files_left: - args = diff_flags + [tree_id] + args = [tree_id] if files_left: args += ['--'] + files_left - for line in GRun('diff-index', *args).output_lines(): - fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1)) + for t, fn in parse_git_ls(GRun('diff-index', '-z', *args).raw_output()): # the condition is needed in case files is emtpy and # diff-index lists those already reported - if fs[1] not in reported_files: - cache_files.append(fs) - reported_files.add(fs[1]) + if not fn in reported_files: + cache_files.append((t, fn)) + reported_files.add(fn) files_left = [f for f in files if f not in reported_files] # files in the index but changed on (or removed from) disk. Only @@ -253,16 +268,15 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False, # function (i.e. report all files) or files were specified but # already found in the previous step if not files or files_left: - args = list(diff_flags) + args = [] if files_left: args += ['--'] + files_left - for line in GRun('diff-files', *args).output_lines(): - fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1)) + for t, fn in parse_git_ls(GRun('diff-files', '-z', *args).raw_output()): # the condition is needed in case files is empty and # diff-files lists those already reported - if fs[1] not in reported_files: - cache_files.append(fs) - reported_files.add(fs[1]) + if not fn in reported_files: + cache_files.append((t, fn)) + reported_files.add(fn) if verbose: out.done() @@ -655,10 +669,6 @@ def diff(files = None, rev1 = 'HEAD', rev2 = None, diff_flags = [], else: return '' -def diffstat(diff): - """Return the diffstat of the supplied diff.""" - return GRun('apply', '--stat', '--summary').raw_input(diff).raw_output() - def files(rev1, rev2, diff_flags = []): """Return the files modified between rev1 and rev2 """