Sfoglia il codice sorgente

New upstream snapshot.

Jelmer Vernooij 13 anni fa
parent
commit
36a9e3b191

+ 12 - 0
NEWS

@@ -1,3 +1,15 @@
+0.8.2	UNRELEASED
+
+ BUG FIXES
+
+  * Cope with different zlib buffer sizes in sha1 file parser.
+    (Jelmer Vernooij)
+
+  * Fix get_transport_and_path for HTTP/HTTPS URLs.
+    (Bruno Renié)
+
+  * Avoid calling free_objects() on NULL in error cases. (Chris Eberle)
+
 0.8.1	2011-10-31
 
  FEATURES

+ 1 - 1
bin/dulwich

@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python -u
 # dulwich - Simple command-line interface to Dulwich
 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
 #

+ 2 - 1
debian/changelog

@@ -1,6 +1,7 @@
-dulwich (0.8.1-2) UNRELEASED; urgency=low
+dulwich (0.8.1~bzr973-1) UNRELEASED; urgency=low
 
   * Fix Vcs URL.
+  * New upstream snapshot.
 
  -- Jelmer Vernooij <jelmer@debian.org>  Thu, 17 Nov 2011 04:37:28 +0100
 

+ 1 - 1
dulwich/__init__.py

@@ -23,4 +23,4 @@
 
 from dulwich import (client, protocol, repo, server)
 
-__version__ = (0, 8, 1)
+__version__ = (0, 8, 2)

+ 6 - 3
dulwich/_diff_tree.c

@@ -135,7 +135,8 @@ static PyObject **tree_entries(char *path, Py_ssize_t path_len, PyObject *tree,
 	return result;
 
 error:
-	free_objects(result, i);
+	if (result)
+		free_objects(result, i);
 	Py_DECREF(items);
 	return NULL;
 }
@@ -243,8 +244,10 @@ error:
 	result = NULL;
 
 done:
-	free_objects(entries1, n1);
-	free_objects(entries2, n2);
+	if (entries1)
+		free_objects(entries1, n1);
+	if (entries2)
+		free_objects(entries2, n2);
 	return result;
 }
 

+ 9 - 6
dulwich/client.py

@@ -35,6 +35,7 @@ from dulwich.errors import (
     UpdateRefsError,
     )
 from dulwich.protocol import (
+    _RBUFSIZE,
     PktLineParser,
     Protocol,
     TCP_GIT_PORT,
@@ -350,7 +351,7 @@ class GitClient(object):
         proto.write_pkt_line('done\n')
 
     def _handle_upload_pack_tail(self, proto, capabilities, graph_walker,
-                                 pack_data, progress):
+                                 pack_data, progress, rbufsize=_RBUFSIZE):
         """Handle the tail of a 'git-upload-pack' request.
 
         :param proto: Protocol object to read from
@@ -358,6 +359,7 @@ class GitClient(object):
         :param graph_walker: GraphWalker instance to call .ack() on
         :param pack_data: Function to call with pack data
         :param progress: Optional progress reporting function
+        :param rbufsize: Read buffer size
         """
         pkt = proto.read_pkt_line()
         while pkt:
@@ -375,9 +377,11 @@ class GitClient(object):
             if data:
                 raise Exception('Unexpected response %r' % data)
         else:
-            # FIXME: Buffering?
-            pack_data(self.read())
-
+            while True:
+                data = self.read(rbufsize)
+                if data == "":
+                    break
+                pack_data(data)
 
 
 class TraditionalGitClient(GitClient):
@@ -715,8 +719,7 @@ def get_transport_and_path(uri):
         return SSHGitClient(parsed.hostname, port=parsed.port,
                             username=parsed.username), parsed.path
     elif parsed.scheme in ('http', 'https'):
-        return HttpGitClient(urlparse.urlunparse(
-            parsed.scheme, parsed.netloc, path='/'))
+        return HttpGitClient(urlparse.urlunparse(parsed)), parsed.path
 
     if parsed.scheme and not parsed.netloc:
         # SSH with no user@, zero or one leading slash.

+ 1 - 1
dulwich/objects.py

@@ -294,7 +294,7 @@ class ShaFile(object):
     def _is_legacy_object(cls, magic):
         b0, b1 = map(ord, magic)
         word = (b0 << 8) + b1
-        return b0 == 0x78 and (word % 31) == 0
+        return (b0 & 0x8F) == 0x08 and (word % 31) == 0
 
     @classmethod
     def _parse_file_header(cls, f):

+ 10 - 5
dulwich/pack.py

@@ -605,9 +605,11 @@ class PackIndex2(FilePackIndex):
 
     def __init__(self, filename, file=None, contents=None, size=None):
         super(PackIndex2, self).__init__(filename, file, contents, size)
-        assert self._contents[:4] == '\377tOc', 'Not a v2 pack index file'
+        if self._contents[:4] != '\377tOc':
+            raise AssertionError('Not a v2 pack index file')
         (self.version, ) = unpack_from('>L', self._contents, 4)
-        assert self.version == 2, 'Version was %d' % self.version
+        if self.version != 2:
+            raise AssertionError('Version was %d' % self.version)
         self._fan_out_table = self._read_fan_out_table(8)
         self._name_table_offset = 8 + 0x100 * 4
         self._crc32_table_offset = self._name_table_offset + 20 * len(self)
@@ -641,9 +643,11 @@ def read_pack_header(read):
     header = read(12)
     if not header:
         return None, None
-    assert header[:4] == 'PACK'
+    if header[:4] != 'PACK':
+        raise AssertionError('Invalid pack header %r' % header)
     (version,) = unpack_from('>L', header, 4)
-    assert version in (2, 3), 'Version was %d' % version
+    if version not in (2, 3):
+        raise AssertionError('Version was %d' % version)
     (num_objects,) = unpack_from('>L', header, 8)
     return (version, num_objects)
 
@@ -693,7 +697,8 @@ def unpack_object(read_all, read_some=None, compute_crc32=False,
     if type_num == OFS_DELTA:
         bytes, crc32 = take_msb_bytes(read_all, crc32=crc32)
         raw_base += len(bytes)
-        assert not (bytes[-1] & 0x80)
+        if bytes[-1] & 0x80:
+            raise AssertionError
         delta_base_offset = bytes[0] & 0x7f
         for byte in bytes[1:]:
             delta_base_offset += 1

+ 14 - 5
dulwich/server.py

@@ -36,6 +36,7 @@ from dulwich.errors import (
     ApplyDeltaError,
     ChecksumMismatch,
     GitProtocolError,
+    NotGitRepository,
     UnexpectedCommandError,
     ObjectFormatException,
     )
@@ -72,14 +73,19 @@ class Backend(object):
     """A backend for the Git smart server implementation."""
 
     def open_repository(self, path):
-        """Open the repository at a path."""
+        """Open the repository at a path.
+
+        :param path: Path to the repository
+        :raise NotGitRepository: no git repository was found at path
+        :return: Instance of BackendRepo
+        """
         raise NotImplementedError(self.open_repository)
 
 
 class BackendRepo(object):
     """Repository abstraction used by the Git server.
-    
-    Please note that the methods required here are a 
+
+    Please note that the methods required here are a
     subset of those provided by dulwich.repo.Repo.
     """
 
@@ -125,8 +131,11 @@ class DictBackend(Backend):
 
     def open_repository(self, path):
         logger.debug('Opening repository at %s', path)
-        # FIXME: What to do in case there is no repo ?
-        return self.repos[path]
+        try:
+            return self.repos[path]
+        except KeyError:
+            raise NotGitRepository("No git repository was found at %(path)s",
+                path=path)
 
 
 class FileSystemBackend(Backend):

+ 2 - 0
dulwich/tests/__init__.py

@@ -104,10 +104,12 @@ def tutorial_test_suite():
         ]
     tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial]
     def setup(test):
+        test.__old_cwd = os.getcwd()
         test.__dulwich_tempdir = tempfile.mkdtemp()
         os.chdir(test.__dulwich_tempdir)
     def teardown(test):
         shutil.rmtree(test.__dulwich_tempdir)
+        os.chdir(test.__old_cwd)
     return doctest.DocFileSuite(setUp=setup, tearDown=teardown,
         *tutorial_files)
 

+ 2 - 5
dulwich/tests/compat/test_pack.py

@@ -43,12 +43,9 @@ class TestPack(PackTests):
 
     def setUp(self):
         require_git_version((1, 5, 0))
-        PackTests.setUp(self)
+        super(TestPack, self).setUp()
         self._tempdir = tempfile.mkdtemp()
-
-    def tearDown(self):
-        shutil.rmtree(self._tempdir)
-        PackTests.tearDown(self)
+        self.addCleanup(shutil.rmtree, self._tempdir)
 
     def test_copy(self):
         origpack = self.get_pack(pack1_sha)

+ 2 - 5
dulwich/tests/compat/test_repository.py

@@ -45,12 +45,9 @@ class ObjectStoreTestCase(CompatTestCase):
     """Tests for git repository compatibility."""
 
     def setUp(self):
-        CompatTestCase.setUp(self)
+        super(ObjectStoreTestCase, self).setUp()
         self._repo = import_repo('server_new.export')
-
-    def tearDown(self):
-        CompatTestCase.tearDown(self)
-        tear_down_repo(self._repo)
+        self.addCleanup(tear_down_repo, self._repo)
 
     def _run_git(self, args):
         return run_git_or_fail(args, cwd=self._repo.path)

+ 3 - 2
dulwich/tests/compat/utils.py

@@ -133,8 +133,9 @@ def run_git_or_fail(args, git_path=_DEFAULT_GIT, input=None, **popen_kwargs):
     popen_kwargs['stderr'] = subprocess.STDOUT
     returncode, stdout = run_git(args, git_path=git_path, input=input,
                                  capture_stdout=True, **popen_kwargs)
-    assert returncode == 0, "git with args %r failed with %d" % (
-        args, returncode)
+    if returncode != 0:
+        raise AssertionError("git with args %r failed with %d" % (
+            args, returncode))
     return stdout
 
 

+ 7 - 0
dulwich/tests/test_client.py

@@ -23,6 +23,7 @@ from dulwich.client import (
     TCPGitClient,
     SubprocessGitClient,
     SSHGitClient,
+    HttpGitClient,
     ReportStatusParser,
     SendPackError,
     UpdateRefsError,
@@ -137,6 +138,12 @@ class GitClientTests(TestCase):
         self.assertRaises(ValueError, get_transport_and_path,
         'prospero://bar/baz')
 
+    def test_get_transport_and_path_http(self):
+        url = 'https://github.com/jelmer/dulwich'
+        client, path = get_transport_and_path(url)
+        self.assertTrue(isinstance(client, HttpGitClient))
+        self.assertEquals('/jelmer/dulwich', path)
+
 
 class SSHGitClientTests(TestCase):
 

+ 27 - 0
dulwich/tests/test_objects.py

@@ -38,6 +38,7 @@ from dulwich.objects import (
     Blob,
     Tree,
     Commit,
+    ShaFile,
     Tag,
     format_timezone,
     hex_to_sha,
@@ -229,6 +230,31 @@ class ShaFileCheckTests(TestCase):
         self.assertEqual(None, obj.check())
 
 
+small_buffer_zlib_object = (
+ "\x48\x89\x15\xcc\x31\x0e\xc2\x30\x0c\x40\x51\xe6"
+ "\x9c\xc2\x3b\xaa\x64\x37\xc4\xc1\x12\x42\x5c\xc5"
+ "\x49\xac\x52\xd4\x92\xaa\x78\xe1\xf6\x94\xed\xeb"
+ "\x0d\xdf\x75\x02\xa2\x7c\xea\xe5\x65\xd5\x81\x8b"
+ "\x9a\x61\xba\xa0\xa9\x08\x36\xc9\x4c\x1a\xad\x88"
+ "\x16\xba\x46\xc4\xa8\x99\x6a\x64\xe1\xe0\xdf\xcd"
+ "\xa0\xf6\x75\x9d\x3d\xf8\xf1\xd0\x77\xdb\xfb\xdc"
+ "\x86\xa3\x87\xf1\x2f\x93\xed\x00\xb7\xc7\xd2\xab"
+ "\x2e\xcf\xfe\xf1\x3b\x50\xa4\x91\x53\x12\x24\x38"
+ "\x23\x21\x86\xf0\x03\x2f\x91\x24\x52"
+ )
+
+
+class ShaFileTests(TestCase):
+
+    def test_deflated_smaller_window_buffer(self):
+        # zlib on some systems uses smaller buffers,
+        # resulting in a different header.
+        # See https://github.com/libgit2/libgit2/pull/464
+        sf = ShaFile.from_file(StringIO(small_buffer_zlib_object))
+        self.assertEquals(sf.type_name, "tag")
+        self.assertEquals(sf.tagger, " <@localhost>")
+
+
 class CommitSerializationTests(TestCase):
 
     def make_commit(self, **kwargs):
@@ -582,6 +608,7 @@ OK2XeQOiEeXtT76rV4t2WR4=
 
 
 class TagParseTests(ShaFileCheckTests):
+
     def make_tag_lines(self,
                        object_sha="a38d6181ff27824c79fc7df825164a212eff6a3f",
                        object_type_name="commit",

+ 1 - 1
setup.py

@@ -10,7 +10,7 @@ except ImportError:
     has_setuptools = False
 from distutils.core import Distribution
 
-dulwich_version_string = '0.8.1'
+dulwich_version_string = '0.8.2'
 
 include_dirs = []
 # Windows MSVC support