summaryrefslogtreecommitdiff
path: root/lib/git/utils.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-22 13:48:49 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-22 13:48:49 +0200
commit25945899a0067a2dbeeae7a8362a6d68bbc5c6ba (patch)
treee2fb1864b34ae0a2838e3a3fae060c0fd0c6e598 /lib/git/utils.py
parent4fe5cfa0e063a8d51a1eb6f014e2aaa994e5e7d4 (diff)
parent1f2b19de3301e76ab3a6187a49c9c93ff78bafbd (diff)
downloadgitpython-25945899a0067a2dbeeae7a8362a6d68bbc5c6ba.tar.gz
Merge branch 'index' into improvements
* index: Removed index test marker for custom commits as this boils down to a good way to add files to the index/remove them and make commits which are possibly customized with custom parents index writing now creates a sha on the content making it possible to write valid indices after manually removing or altering entriesgst Implemented merge/resolve handling , but realized that index writing is not yet working properly as it is sha1 checked as well. This explains what my 20 byte 'extension_data' actually is ;) index: Added write_tree method including test index.iter_blobs method added including tests ( which have been improved generally for more coverage ) tree.traverse: Added prune functionality - previously the predciate did both, pruning and preventing to return items Improved testing of index against trees, tests succeed with next commit Initial version of merge including tests for one-way, two-way and tree-way merge index writing added including simple test, improved docs of IndexEntry improved IndexEntry type and added test for parsing of the stage Improved tuple access of EntryIndex class including test, stage and type access still needs to be decoded though Added initial version of the index reading from file - IndexEntry interface is to be improved though, writing needs to be implemented as well Added frame for index implementation and testing
Diffstat (limited to 'lib/git/utils.py')
-rw-r--r--lib/git/utils.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/git/utils.py b/lib/git/utils.py
index 2aa8d33e..cdc7c55b 100644
--- a/lib/git/utils.py
+++ b/lib/git/utils.py
@@ -6,6 +6,58 @@
import os
+try:
+ import hashlib
+except ImportError:
+ import sha
+
+def make_sha(source=''):
+ """
+ A python2.4 workaround for the sha/hashlib module fiasco
+
+ Note
+ From the dulwich project
+ """
+ try:
+ return hashlib.sha1(source)
+ except NameError:
+ sha1 = sha.sha(source)
+ return sha1
+
+
+class SHA1Writer(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.
+
+ Note:
+ Based on the dulwich project
+ """
+ __slots__ = ("f", "sha1")
+
+ def __init__(self, f):
+ self.f = f
+ self.sha1 = make_sha("")
+
+ def write(self, data):
+ self.sha1.update(data)
+ self.f.write(data)
+
+ def write_sha(self):
+ sha = self.sha1.digest()
+ self.f.write(sha)
+ return sha
+
+ def close(self):
+ sha = self.write_sha()
+ self.f.close()
+ return sha
+
+ def tell(self):
+ return self.f.tell()
+
+
class LazyMixin(object):
"""
Base class providing an interface to lazily retrieve attribute values upon