diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-04 17:30:31 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-04 17:30:31 +0200 |
commit | 6fbb69306c0e14bacb8dcb92a89af27d3d5d631f (patch) | |
tree | 4a6e0c14b412315c13cc4ac6466f4888644195a3 /lib/git/utils.py | |
parent | 25dca42bac17d511b7e2ebdd9d1d679e7626db5f (diff) | |
parent | e746f96bcc29238b79118123028ca170adc4ff0f (diff) | |
download | gitpython-6fbb69306c0e14bacb8dcb92a89af27d3d5d631f.tar.gz |
Merge branch 'odb'
Conflicts:
lib/git/cmd.py
Diffstat (limited to 'lib/git/utils.py')
-rw-r--r-- | lib/git/utils.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/git/utils.py b/lib/git/utils.py index c21528b1..60a7de48 100644 --- a/lib/git/utils.py +++ b/lib/git/utils.py @@ -27,6 +27,21 @@ def make_sha(source=''): sha1 = sha.sha(source) return sha1 +def stream_copy(source, destination, chunk_size=512*1024): + """Copy all data from the source stream into the destination stream in chunks + of size chunk_size + :return: amount of bytes written""" + br = 0 + while True: + chunk = source.read(chunk_size) + destination.write(chunk) + br += len(chunk) + if len(chunk) < chunk_size: + break + # END reading output stream + return br + + def join_path(a, *p): """Join path tokens together similar to os.path.join, but always use '/' instead of possibly '\' on windows.""" @@ -61,12 +76,14 @@ def join_path_native(a, *p): return to_native_path(join_path(a, *p)) -class SHA1Writer(object): +class IndexFileSHA1Writer(object): """ Wrapper around a file-like object that remembers the SHA1 of the data written to it. It will write a sha when the stream is closed or if the asked for explicitly usign write_sha. + Only useful to the indexfile + Note: Based on the dulwich project """ @@ -78,7 +95,7 @@ class SHA1Writer(object): def write(self, data): self.sha1.update(data) - self.f.write(data) + return self.f.write(data) def write_sha(self): sha = self.sha1.digest() |