def realdiff(diff, ignore): files = {} stat = {} # Can happen with subproject-only commits if not diff.changes: return {}, {None: {'+': 0, '-': 0}} for id, file in enumerate(diff.changes['files']): if id in ignore: continue files[file[1]] = [] stat[file[1]] = {'-': 0, '+': 0} for hunk in diff.changes.get('hunks', []): if hunk.new_file not in files: continue files[hunk.new_file].append(hunk) s = stat[hunk.new_file] s['-'] += len( [x for x in hunk.data if x[1] == pygit2.GIT_DIFF_LINE_DELETION]) s['+'] += len( [x for x in hunk.data if x[1] == pygit2.GIT_DIFF_LINE_ADDITION]) s['%'] = int(100.0 * s['+'] / (s['-'] + s['+'])) stat[None] = { '-': sum([x['-'] for x in stat.values()]), '+': sum([x['+'] for x in stat.values()]) } return files, stat
def realdiff(diff): files = {} stat = {} # Can happen with subproject-only commits if not diff.changes: return {}, {None: {'+': 0, '-': 0}} for file in diff.changes['files']: files[file[1]] = [] stat[file[1]] = {'-': 0, '+': 0} for hunk in diff.changes.get('hunks', []): files[hunk.new_file].append(hunk) stat[hunk.new_file]['-'] += len([x for x in hunk.data if x[1] == pygit2.GIT_DIFF_LINE_DELETION]) stat[hunk.new_file]['+'] += len([x for x in hunk.data if x[1] == pygit2.GIT_DIFF_LINE_ADDITION]) stat[None] = {'-': sum([x['-'] for x in stat.values()]), '+': sum([x['+'] for x in stat.values()])} return files, stat
def handle_request(self, repo, ref=None): ref = self.lookup_ref(repo, ref) stat = {} if not ref.parents: diff = ref.tree.diff_to_tree(swap=True) else: diff = ref.parents[0].tree.diff_to_tree(ref.tree) for file in diff: s = stat[file.new_file_path] = {'-': 0, '+': 0} for hunk in file.hunks: hs = [x[0] for x in hunk.lines] s['-'] += hs.count('-') s['+'] += hs.count('+') s['%'] = int(100.0 * s['+'] / (s['-']+s['+'])) stat[None] = {'-': sum([x['-'] for x in stat.values()]), '+': sum([x['+'] for x in stat.values()])} return {'commit': ref, 'diff': diff, 'stat': stat}
def handle_request(self, repo, ref=None): ref = self.lookup_ref(repo, ref) stat = {} if not ref.parents: diff = ref.tree.diff_to_tree(swap=True) else: diff = ref.parents[0].tree.diff_to_tree(ref.tree) for file in diff: s = stat[file.new_file_path] = {"-": 0, "+": 0} for hunk in file.hunks: hs = [x[0] for x in hunk.lines] s["-"] += hs.count("-") s["+"] += hs.count("+") s["%"] = int(100.0 * s["+"] / (s["-"] + s["+"])) stat[None] = {"-": sum([x["-"] for x in stat.values()]), "+": sum([x["+"] for x in stat.values()])} return {"commit": ref, "diff": diff, "stat": stat}
def handle_request(self, repo, ref=None): if 'q' in request.args: return self.git_grep(repo, ref, '') ref = self.lookup_ref(repo, ref) stat = {} if not ref.parents: diff = ref.tree.diff_to_tree(swap=True) else: diff = ref.parents[0].tree.diff_to_tree(ref.tree) for file in diff: s = stat[file.new_file_path] = {'-': file.deletions, '+': file.additions} if s['-'] + s['+'] == 0: s['%'] = 0 else: s['%'] = int(100.0 * s['+'] / (s['-']+s['+'])) for hunk in file.hunks: self.mark_hunk_word_diff(hunk) stat[None] = {'-': sum([x['-'] for x in stat.values()]), '+': sum([x['+'] for x in stat.values()])} return {'commit': ref, 'diff': diff, 'stat': stat}
def realdiff(diff, ignore): files = {} stat = {} # Can happen with subproject-only commits if not diff.changes: return {}, {None: {'+': 0, '-': 0}} for id, file in enumerate(diff.changes['files']): if id in ignore: continue files[file[1]] = [] stat[file[1]] = {'-': 0, '+': 0} for hunk in diff.changes.get('hunks', []): if hunk.new_file not in files: continue files[hunk.new_file].append(hunk) s = stat[hunk.new_file] s['-'] += len([x for x in hunk.data if x[1] == pygit2.GIT_DIFF_LINE_DELETION]) s['+'] += len([x for x in hunk.data if x[1] == pygit2.GIT_DIFF_LINE_ADDITION]) s['%'] = int(100.0 * s['+'] / (s['-']+s['+'])) stat[None] = {'-': sum([x['-'] for x in stat.values()]), '+': sum([x['+'] for x in stat.values()])} return files, stat
def checkasm(self, code): self.magic.reset() stat = { 'mips64': 0, 'mips64el': 0, 'mipsel': 0, 'mips': 0, 'mips16e': 0, 'mipsel16e': 0, 'powerpcbe': 0, 'powerpcle': 0, 'armeb': 0, 'arm': 0, 'ubicom32': 0, 'avr8': 0, 'avr32': 0, 'sparc': 0, 'x86': 0, 'coldfire': 0, 'superh': 0, 'aarch64': 0, } for r in self.magic.scan(binwalk.core.compat.bytes2str(code)): desc = r.description.lower() if desc.startswith("mips 64 "): stat['mips64'] += 1 elif desc.startswith("mipsel 64 "): stat['mips64el'] += 1 elif desc.startswith("mipsel "): stat['mipsel'] += 1 elif desc.startswith("mips "): stat['mips'] += 1 elif desc.startswith("mips16e "): stat['mips16e'] += 1 elif desc.startswith("mipsel16e "): stat['mipsel16e'] += 1 elif desc.startswith("powerpc big endian"): stat['powerpcbe'] += 1 elif desc.startswith("powerpc little endian"): stat['powerpcle'] += 1 elif desc.startswith("armeb "): stat['armeb'] += 1 elif desc.startswith("arm "): stat['arm'] += 1 elif desc.startswith("ubicom32 "): stat['ubicom32'] += 1 elif desc.startswith("avr8 "): stat['avr8'] += 1 elif desc.startswith("avr32 "): stat['avr32'] += 1 elif desc.startswith("sparc "): stat['sparc'] += 1 elif desc.startswith("intel x86"): stat['x86'] += 1 elif desc.startswith("motorola coldfire"): stat['coldfire'] += 1 elif desc.startswith("superh "): stat['superh'] += 1 elif desc.startswith("aarch64 "): stat['aarch64'] += 1 if max(stat.values()) == 0: return None return max(stat, key=stat.get)