def get_diffs(history):
<EOL>mgr = plugins_get_mgr() <EOL>keys = mgr.search('<STR_LIT>')['<STR_LIT>']<EOL>representations = [mgr.get_by_key('<STR_LIT>', k) for k in keys]<EOL>for i in range(len(history)):<EOL><INDENT>if i+<NUM_LIT:1> > len(history) - <NUM_LIT:1>:<EOL><INDENT>continue<EOL><DEDENT>prev = history[i]<EOL>curr = history[i+<NUM_LIT:1>]<EOL>for c in curr['<STR_LIT>']:<EOL><INDENT>path = c['<STR_LIT:path>']<EOL>if c['<STR_LIT:path>'].endswith('<STR_LIT>'): <EOL><INDENT>continue <EOL><DEDENT>handler = None <EOL>for r in representations: <EOL><INDENT>if r.can_process(path): <EOL><INDENT>handler = r <EOL>break <EOL><DEDENT><DEDENT>if handler is None: <EOL><INDENT>continue <EOL><DEDENT>v1_hex = prev['<STR_LIT>']<EOL>v2_hex = curr['<STR_LIT>']<EOL>temp1 = tempfile.mkdtemp(prefix="<STR_LIT>") <EOL>try: <EOL><INDENT>for h in [v1_hex, v2_hex]: <EOL><INDENT>filename = '<STR_LIT>'.format(temp1, h)<EOL>try:<EOL><INDENT>os.makedirs(os.path.dirname(filename))<EOL><DEDENT>except:<EOL><INDENT>pass <EOL><DEDENT>extractcmd = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', filename, h, path]<EOL>output = run(extractcmd)<EOL>if '<STR_LIT>' in output: <EOL><INDENT>raise Exception("<STR_LIT>") <EOL><DEDENT>with cd(os.path.dirname(filename)): <EOL><INDENT>cmd = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>output = run(cmd) <EOL>if '<STR_LIT>' in output: <EOL><INDENT>print("<STR_LIT>", temp1)<EOL>shutil.rmtree(temp1)<EOL>continue <EOL><DEDENT><DEDENT><DEDENT>path1 = os.path.join(temp1, v1_hex, path) <EOL>path2 = os.path.join(temp1, v2_hex, path) <EOL>if not os.path.exists(path1) or not os.path.exists(path2): <EOL><INDENT>shutil.rmtree(temp1)<EOL>continue <EOL><DEDENT>diff = handler.get_diff(path1, path2)<EOL>c['<STR_LIT>'] = diff<EOL><DEDENT>except Exception as e: <EOL><INDENT>shutil.rmtree(temp1)<EOL><DEDENT><DEDENT><DEDENT>
Look at files and compute the diffs intelligently