Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 5453:9d77f2b47eb7
fix UnboundLocalError, refactor a bit
bin wasn't defined in all branches (bug introduced in 82b4ff3abbcd
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Thu, 11 Oct 2007 12:16:55 +0200 |
parents | 0a43875677b1 |
children | 686899a7de5b |
comparison
equal
deleted
inserted
replaced
5452:82b4ff3abbcd | 5453:9d77f2b47eb7 |
---|---|
60 def compress(text): | 60 def compress(text): |
61 """ generate a possibly-compressed representation of text """ | 61 """ generate a possibly-compressed representation of text """ |
62 if not text: | 62 if not text: |
63 return ("", text) | 63 return ("", text) |
64 l = len(text) | 64 l = len(text) |
65 bin = None | |
65 if l < 44: | 66 if l < 44: |
66 if text[0] == '\0': | 67 pass |
67 return ("", text) | |
68 return ('u', text) | |
69 elif l > 1000000: | 68 elif l > 1000000: |
70 # zlib makes an internal copy, thus doubling memory usage for | 69 # zlib makes an internal copy, thus doubling memory usage for |
71 # large files, so lets do this in pieces | 70 # large files, so lets do this in pieces |
72 z = zlib.compressobj() | 71 z = zlib.compressobj() |
73 p = [] | 72 p = [] |
79 p.append(z.flush()) | 78 p.append(z.flush()) |
80 if sum(map(len, p)) < l: | 79 if sum(map(len, p)) < l: |
81 bin = "".join(p) | 80 bin = "".join(p) |
82 else: | 81 else: |
83 bin = _compress(text) | 82 bin = _compress(text) |
84 if len(bin) > l: | 83 if bin is None or len(bin) > l: |
85 if text[0] == '\0': | 84 if text[0] == '\0': |
86 return ("", text) | 85 return ("", text) |
87 return ('u', text) | 86 return ('u', text) |
88 return ("", bin) | 87 return ("", bin) |
89 | 88 |