Browse Source

Add encoding argument to Repo.do_commit().

Jelmer Vernooij 14 years ago
parent
commit
94bb421dc5
2 changed files with 14 additions and 1 deletions
  1. 4 1
      dulwich/repo.py
  2. 10 0
      dulwich/tests/test_repository.py

+ 4 - 1
dulwich/repo.py

@@ -1017,7 +1017,7 @@ class BaseRepo(object):
     def do_commit(self, message, committer=None,
                   author=None, commit_timestamp=None,
                   commit_timezone=None, author_timestamp=None,
-                  author_timezone=None, tree=None):
+                  author_timezone=None, tree=None, encoding=None):
         """Create a new commit.
 
         :param message: Commit message
@@ -1030,6 +1030,7 @@ class BaseRepo(object):
             (defaults to commit timestamp timezone)
         :param tree: SHA1 of the tree root to use (if not specified the
             current index will be committed).
+        :param encoding: Encoding
         :return: New commit SHA1
         """
         import time
@@ -1061,6 +1062,8 @@ class BaseRepo(object):
         if author_timezone is None:
             author_timezone = commit_timezone
         c.author_timezone = author_timezone
+        if encoding is not None:
+            c.encoding = encoding
         c.message = message
         try:
             old_head = self.refs["HEAD"]

+ 10 - 0
dulwich/tests/test_repository.py

@@ -420,6 +420,16 @@ class BuildRepoTests(TestCase):
         tree = r[r[commit_sha].tree]
         self.assertEqual([], list(tree.iteritems()))
 
+    def test_commit_encoding(self):
+        r = self._repo
+        commit_sha = r.do_commit('commit with strange character \xee',
+             committer='Test Committer <test@nodomain.com>',
+             author='Test Author <test@nodomain.com>',
+             commit_timestamp=12395, commit_timezone=0,
+             author_timestamp=12395, author_timezone=0,
+             encoding="iso8859-1")
+        self.assertEquals("iso8859-1", r[commit_sha].encoding)
+
     def test_commit_fail_ref(self):
         r = self._repo