Mercurial > hg
comparison mercurial/pure/mpatch.py @ 28589:c4c7be9f0554
mpatch: move collect() to module level
This helps the code read a little more clearly.
author | Augie Fackler <augie@google.com> |
---|---|
date | Sat, 19 Mar 2016 16:45:52 -0400 |
parents | 6546afde350e |
children | f736f98e16ca |
comparison
equal
deleted
inserted
replaced
28588:6546afde350e | 28589:c4c7be9f0554 |
---|---|
40 m.seek(src) | 40 m.seek(src) |
41 buf = m.read(count) | 41 buf = m.read(count) |
42 m.seek(dest) | 42 m.seek(dest) |
43 m.write(buf) | 43 m.write(buf) |
44 | 44 |
45 def _collect(m, buf, list): | |
46 start = buf | |
47 for l, p in reversed(list): | |
48 _move(m, buf, p, l) | |
49 buf += l | |
50 return (buf - start, start) | |
51 | |
45 def patches(a, bins): | 52 def patches(a, bins): |
46 if not bins: | 53 if not bins: |
47 return a | 54 return a |
48 | 55 |
49 plens = [len(x) for x in bins] | 56 plens = [len(x) for x in bins] |
64 # copy all the patches into our segment so we can memmove from them | 71 # copy all the patches into our segment so we can memmove from them |
65 pos = b2 + bl | 72 pos = b2 + bl |
66 m.seek(pos) | 73 m.seek(pos) |
67 for p in bins: m.write(p) | 74 for p in bins: m.write(p) |
68 | 75 |
69 def collect(buf, list): | |
70 start = buf | |
71 for l, p in reversed(list): | |
72 _move(m, buf, p, l) | |
73 buf += l | |
74 return (buf - start, start) | |
75 | |
76 for plen in plens: | 76 for plen in plens: |
77 # if our list gets too long, execute it | 77 # if our list gets too long, execute it |
78 if len(frags) > 128: | 78 if len(frags) > 128: |
79 b2, b1 = b1, b2 | 79 b2, b1 = b1, b2 |
80 frags = [collect(b1, frags)] | 80 frags = [_collect(m, b1, frags)] |
81 | 81 |
82 new = [] | 82 new = [] |
83 end = pos + plen | 83 end = pos + plen |
84 last = 0 | 84 last = 0 |
85 while pos < end: | 85 while pos < end: |
90 new.append((l, pos + 12)) # what got added | 90 new.append((l, pos + 12)) # what got added |
91 pos += l + 12 | 91 pos += l + 12 |
92 last = p2 | 92 last = p2 |
93 frags.extend(reversed(new)) # what was left at the end | 93 frags.extend(reversed(new)) # what was left at the end |
94 | 94 |
95 t = collect(b2, frags) | 95 t = _collect(m, b2, frags) |
96 | 96 |
97 m.seek(t[1]) | 97 m.seek(t[1]) |
98 return m.read(t[0]) | 98 return m.read(t[0]) |
99 | 99 |
100 def patchedsize(orig, delta): | 100 def patchedsize(orig, delta): |