comparison mercurial/hg.py @ 434:08f00b6494f4

Replace difflib with bdiff for annotate -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Replace difflib with bdiff for annotate This is a quick hack to get bdiff working for annotate, can still be optimized quite a bit. manifest hash: 380ae3092c73b7e1946952edec3588248bc13c5e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCubxGywK+sNU5EO8RAv7RAJ9lTdxRAVqzGs4XnPoZAmx/fbeUZwCfWar2 RqLGipS5JmMOy1pL1ehNxqY= =KLgM -----END PGP SIGNATURE-----
author mpm@selenic.com
date Wed, 22 Jun 2005 11:30:14 -0800
parents 688d03d6997a
children 6aeb4fee51f6
comparison
equal deleted inserted replaced
433:79c694462294 434:08f00b6494f4
8 import sys, struct, os 8 import sys, struct, os
9 import util 9 import util
10 from revlog import * 10 from revlog import *
11 from demandload import * 11 from demandload import *
12 demandload(globals(), "re lock urllib urllib2 transaction time socket") 12 demandload(globals(), "re lock urllib urllib2 transaction time socket")
13 demandload(globals(), "tempfile httprangereader difflib") 13 demandload(globals(), "tempfile httprangereader bdiff")
14 14
15 def is_exec(f): 15 def is_exec(f):
16 return (os.stat(f).st_mode & 0100 != 0) 16 return (os.stat(f).st_mode & 0100 != 0)
17 17
18 def set_exec(f, mode): 18 def set_exec(f, mode):
64 64
65 def decorate(text, rev): 65 def decorate(text, rev):
66 return [(rev, l) for l in text.splitlines(1)] 66 return [(rev, l) for l in text.splitlines(1)]
67 67
68 def strip(annotation): 68 def strip(annotation):
69 return [e[1] for e in annotation] 69 return "".join([e[1] for e in annotation])
70 70
71 def pair(parent, child): 71 def pair(parent, child):
72 new = [] 72 new = []
73 sm = difflib.SequenceMatcher(None, strip(parent), strip(child)) 73 lb = 0
74 for o, m, n, s, t in sm.get_opcodes(): 74 for a1, a2, b1, b2 in bdiff.blocks(strip(parent), strip(child)):
75 if o == 'equal': 75 new += child[lb:b1]
76 new += parent[m:n] 76 new += parent[a1:a2]
77 else: 77 lb = b2
78 new += child[s:t]
79 return new 78 return new
80 79
81 # find all ancestors 80 # find all ancestors
82 needed = {node:1} 81 needed = {node:1}
83 visit = [node] 82 visit = [node]