in ForgeGit/forgegit/model/git_repo.py [0:0]
def paged_diffs(self, commit_id, start=0, end=None, onlyChangedFiles=False):
result = {'added': [], 'removed': [], 'changed': [], 'copied': [], 'renamed': []}
cmd_args = ['--no-commit-id',
'--name-status',
'--no-abbrev',
'--root',
# show tree entry itself as well as subtrees (Commit.added_paths relies on this)
'-t',
'-z' # don't escape filenames and use \x00 as fields delimiter
]
if onlyChangedFiles:
cmd_args[4] = '-r'
if asbool(tg.config.get('scm.commit.git.detect_copies', True)):
cmd_args += ['-M', '-C']
cmd_output = self._git.git.diff_tree(commit_id, *cmd_args).split('\x00')[:-1] # don't escape filenames and use \x00 as fields delimiter
''' cmd_output will be like:
[
'A',
'filename',
'D',
'another filename',
'M',
'po',
'R100', # <-- These next three lines would only show up with 'detect_copies' enabled
'po/sr.po',
'po/sr_Latn.po',
]
'''
x = 0
files = []
while x < len(cmd_output):
status = cmd_output[x][0]
if status in ('R', 'C'):
ratio = float(cmd_output[x][1:4]) / 100.0
files.append((status, {
'new': h.really_unicode(cmd_output[x + 2]),
'old': h.really_unicode(cmd_output[x + 1]),
'ratio': ratio,
}))
x += 3
else:
files.append((status, h.really_unicode(cmd_output[x + 1])))
x += 2
for status, name in files[start:end]:
change_list_types = {
'R': result['renamed'],
'C': result['copied'],
'A': result['added'],
'D': result['removed'],
'M': result['changed'],
'T': result['changed'],
}
if status in change_list_types:
change_list = change_list_types[status]
change_list.append(name)
else:
log.error('Unexpected git change status: "%s" on file %s commit %s repo %s',
status, name, commit_id, self._repo.full_fs_path)
result['total'] = len(files)
return result