Rev 1375: Implement send_stream to delta function in Python. in http://people.samba.org/bzr/jelmer/bzr-svn/0.4
Jelmer Vernooij
jelmer at samba.org
Fri Jun 27 16:37:23 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-svn/0.4
------------------------------------------------------------
revno: 1375
revision-id: jelmer at samba.org-20080627153722-zlllf1p4yodxxqxq
parent: jelmer at samba.org-20080627153705-hw31usrbrap2r6et
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Fri 2008-06-27 17:37:22 +0200
message:
Implement send_stream to delta function in Python.
modified:
delta.py delta.py-20080316001917-xyng7m3jlxvdc4c9-1
=== modified file 'delta.py'
--- a/delta.py 2008-06-21 20:50:13 +0000
+++ b/delta.py 2008-06-27 15:37:22 +0000
@@ -15,8 +15,16 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Subversion delta operations."""
+import md5
+
+TXDELTA_SOURCE = 0
+TXDELTA_TARGET = 1
+TXDELTA_NEW = 2
+
def apply_txdelta_handler(sbuf, target_stream):
def apply_window(window):
+ if window is None:
+ return # Last call
(sview_offset, sview_len, tview_len, src_ops, ops, new_data) = window
sview = sbuf[sview_offset:sview_offset+sview_len]
tview = txdelta_apply_ops(src_ops, ops, new_data, sview)
@@ -28,15 +36,30 @@
def txdelta_apply_ops(src_ops, ops, new_data, sview):
tview = ""
for (action, offset, length) in ops:
- if action == 0:
+ if action == TXDELTA_SOURCE:
# Copy from source area.
tview += sview[offset:offset+length]
- elif action == 1:
+ elif action == TXDELTA_TARGET:
for i in xrange(length):
tview += tview[offset+i]
- elif action == 2:
+ elif action == TXDELTA_NEW:
tview += new_data[offset:offset+length]
else:
raise Exception("Invalid delta instruction code")
return tview
+
+
+SEND_STREAM_BLOCK_SIZE = 1024 * 1024 # 1 Mb
+
+
+def send_stream(stream, handler, block_size=SEND_STREAM_BLOCK_SIZE):
+ hash = md5.new()
+ text = stream.read(block_size)
+ while text != "":
+ hash.update(text)
+ window = (0, 0, len(text), 0, [(TXDELTA_NEW, 0, len(text))], text)
+ handler(window)
+ text = stream.read(block_size)
+ handler(None)
+ return hash.digest()
More information about the bazaar-commits
mailing list