@@ -1205,38 +1205,32 @@ def context_diff(a, b, fromfile='', tofile='',
12051205 """
12061206
12071207 started = False
1208- prefixmap = dict ( insert = ' + ' , delete = ' - ' , replace = ' ! ' , equal = ' ')
1208+ prefixmap = { ' insert' : ' + ' , ' delete' : ' - ' , ' replace' : ' ! ' , ' equal' : ' '}
12091209 for group in SequenceMatcher (None ,a ,b ).get_grouped_opcodes (n ):
12101210 if not started :
12111211 yield '*** %s %s%s' % (fromfile , fromfiledate , lineterm )
12121212 yield '--- %s %s%s' % (tofile , tofiledate , lineterm )
12131213 started = True
1214+
12141215 yield '***************%s' % (lineterm ,)
12151216 if group [- 1 ][2 ] - group [0 ][1 ] >= 2 :
12161217 yield '*** %d,%d ****%s' % (group [0 ][1 ]+ 1 , group [- 1 ][2 ], lineterm )
12171218 else :
12181219 yield '*** %d ****%s' % (group [- 1 ][2 ], lineterm )
1219- empty = True
1220- for tag , i1 , i2 , j1 , j2 in group :
1221- if tag == 'replace' or tag == 'delete' :
1222- empty = False
1223- break
1224- if not empty :
1225- for tag , i1 , i2 , j1 , j2 in group :
1220+ visiblechanges = [e for e in group if e [0 ] in ('replace' , 'delete' )]
1221+ if visiblechanges :
1222+ for tag , i1 , i2 , _ , _ in group :
12261223 if tag != 'insert' :
12271224 for line in a [i1 :i2 ]:
12281225 yield prefixmap [tag ] + line
1226+
12291227 if group [- 1 ][4 ] - group [0 ][3 ] >= 2 :
12301228 yield '--- %d,%d ----%s' % (group [0 ][3 ]+ 1 , group [- 1 ][4 ], lineterm )
12311229 else :
12321230 yield '--- %d ----%s' % (group [- 1 ][4 ], lineterm )
1233- empty = True
1234- for tag , i1 , i2 , j1 , j2 in group :
1235- if tag == 'replace' or tag == 'insert' :
1236- empty = False
1237- break
1238- if not empty :
1239- for tag , i1 , i2 , j1 , j2 in group :
1231+ visiblechanges = [e for e in group if e [0 ] in ('replace' , 'insert' )]
1232+ if visiblechanges :
1233+ for tag , _ , _ , j1 , j2 in group :
12401234 if tag != 'delete' :
12411235 for line in b [j1 :j2 ]:
12421236 yield prefixmap [tag ] + line
0 commit comments