Exemplo n.º 1
0
 def test_delta_medium_object(self):
     # This tests an object set that will have a copy operation
     # 2**20 in size.
     with self.get_pack(pack1_sha) as orig_pack:
         orig_blob = orig_pack[a_sha]
         new_blob = Blob()
         new_blob.data = orig_blob.data + (b'x' * 2**20)
         new_blob_2 = Blob()
         new_blob_2.data = new_blob.data + b'y'
         all_to_pack = list(orig_pack.pack_tuples()) + [(new_blob, None),
                                                        (new_blob_2, None)]
     pack_path = os.path.join(self._tempdir, 'pack_with_deltas')
     write_pack(pack_path, all_to_pack, deltify=True)
     output = run_git_or_fail(['verify-pack', '-v', pack_path])
     self.assertEqual(set(x[0].id for x in all_to_pack),
                      _git_verify_pack_object_list(output))
     # We specifically made a new blob that should be a delta
     # against the blob a_sha, so make sure we really got only 3
     # non-delta objects:
     got_non_delta = int(_NON_DELTA_RE.search(output).group('non_delta'))
     self.assertEqual(
         3, got_non_delta,
         'Expected 3 non-delta objects, got %d' % got_non_delta)
     # We expect one object to have a delta chain length of two
     # (new_blob_2), so let's verify that actually happens:
     self.assertIn(b'chain length = 2', output)
Exemplo n.º 2
0
    def test_copy(self):
        origpack = self.get_pack(pack1_sha)

        try:
            self.assertSucceeds(origpack.index.check)
            basename = os.path.join(self.tempdir, 'Elch')
            write_pack(basename, [(x, '') for x in origpack.iterobjects()],
                       len(origpack))
            newpack = Pack(basename)

            try:
                self.assertEquals(origpack, newpack)
                self.assertSucceeds(newpack.index.check)
                self.assertEquals(origpack.name(), newpack.name())
                self.assertEquals(origpack.index.get_pack_checksum(),
                                  newpack.index.get_pack_checksum())

                wrong_version = origpack.index.version != newpack.index.version
                orig_checksum = origpack.index.get_stored_checksum()
                new_checksum = newpack.index.get_stored_checksum()
                self.assertTrue(wrong_version or orig_checksum == new_checksum)
            finally:
                newpack.close()
        finally:
            origpack.close()
Exemplo n.º 3
0
 def test_delta_large_object(self):
     # This tests an object set that will have a copy operation
     # 2**25 in size. This is a copy large enough that it requires
     # two copy operations in git's binary delta format.
     raise SkipTest('skipping slow, large test')
     with self.get_pack(pack1_sha) as orig_pack:
         orig_blob = orig_pack[a_sha]
         new_blob = Blob()
         new_blob.data = 'big blob' + ('x' * 2 ** 25)
         new_blob_2 = Blob()
         new_blob_2.data = new_blob.data + 'y'
         all_to_pack = list(orig_pack.pack_tuples()) + [(new_blob, None),
                                                        (new_blob_2, None)]
     pack_path = os.path.join(self._tempdir, "pack_with_deltas")
     write_pack(pack_path, all_to_pack, deltify=True)
     output = run_git_or_fail(['verify-pack', '-v', pack_path])
     self.assertEqual(set(x[0].id for x in all_to_pack),
                      _git_verify_pack_object_list(output))
     # We specifically made a new blob that should be a delta
     # against the blob a_sha, so make sure we really got only 4
     # non-delta objects:
     got_non_delta = int(_NON_DELTA_RE.search(output).group('non_delta'))
     self.assertEqual(
         4, got_non_delta,
         'Expected 4 non-delta objects, got %d' % got_non_delta)
Exemplo n.º 4
0
 def test_delta_medium_object(self):
     # This tests an object set that will have a copy operation
     # 2**20 in size.
     with self.get_pack(pack1_sha) as orig_pack:
         orig_blob = orig_pack[a_sha]
         new_blob = Blob()
         new_blob.data = orig_blob.data + (b'x' * 2 ** 20)
         new_blob_2 = Blob()
         new_blob_2.data = new_blob.data + b'y'
         all_to_pack = list(orig_pack.pack_tuples()) + [(new_blob, None),
                                                        (new_blob_2, None)]
     pack_path = os.path.join(self._tempdir, b'pack_with_deltas')
     write_pack(pack_path, all_to_pack, deltify=True)
     output = run_git_or_fail(['verify-pack', '-v', pack_path])
     self.assertEqual(set(x[0].id for x in all_to_pack),
                      _git_verify_pack_object_list(output))
     # We specifically made a new blob that should be a delta
     # against the blob a_sha, so make sure we really got only 3
     # non-delta objects:
     got_non_delta = int(_NON_DELTA_RE.search(output).group('non_delta'))
     self.assertEqual(
         3, got_non_delta,
         'Expected 3 non-delta objects, got %d' % got_non_delta)
     # We expect one object to have a delta chain length of two
     # (new_blob_2), so let's verify that actually happens:
     self.assertIn(b'chain length = 2', output)
Exemplo n.º 5
0
 def test_delta_large_object(self):
     # This tests an object set that will have a copy operation
     # 2**25 in size. This is a copy large enough that it requires
     # two copy operations in git's binary delta format.
     raise SkipTest('skipping slow, large test')
     orig_pack = self.get_pack(pack1_sha)
     orig_blob = orig_pack[a_sha]
     new_blob = Blob()
     new_blob.data = 'big blob' + ('x' * 2**25)
     new_blob_2 = Blob()
     new_blob_2.data = new_blob.data + 'y'
     all_to_pack = list(orig_pack.pack_tuples()) + [(new_blob, None),
                                                    (new_blob_2, None)]
     pack_path = os.path.join(self._tempdir, "pack_with_deltas")
     write_pack(pack_path, all_to_pack, deltify=True)
     output = run_git_or_fail(['verify-pack', '-v', pack_path])
     self.assertEqual(set(x[0].id for x in all_to_pack),
                      _git_verify_pack_object_list(output))
     # We specifically made a new blob that should be a delta
     # against the blob a_sha, so make sure we really got only 4
     # non-delta objects:
     got_non_delta = int(_NON_DELTA_RE.search(output).group('non_delta'))
     self.assertEqual(
         4, got_non_delta,
         'Expected 4 non-delta objects, got %d' % got_non_delta)
Exemplo n.º 6
0
 def test_delta_large_object(self):
     # This tests an object set that will have a copy operation
     # 2**25 in size. This is a copy large enough that it requires
     # two copy operations in git's binary delta format.
     raise SkipTest("skipping slow, large test")
     with self.get_pack(pack1_sha) as orig_pack:
         new_blob = Blob()
         new_blob.data = "big blob" + ("x" * 2**25)
         new_blob_2 = Blob()
         new_blob_2.data = new_blob.data + "y"
         all_to_pack = list(orig_pack.pack_tuples()) + [
             (new_blob, None),
             (new_blob_2, None),
         ]
     pack_path = os.path.join(self._tempdir, "pack_with_deltas")
     write_pack(pack_path, all_to_pack, deltify=True)
     output = run_git_or_fail(["verify-pack", "-v", pack_path])
     self.assertEqual(
         {x[0].id
          for x in all_to_pack},
         _git_verify_pack_object_list(output),
     )
     # We specifically made a new blob that should be a delta
     # against the blob a_sha, so make sure we really got only 4
     # non-delta objects:
     got_non_delta = int(_NON_DELTA_RE.search(output).group("non_delta"))
     self.assertEqual(
         4,
         got_non_delta,
         "Expected 4 non-delta objects, got %d" % got_non_delta,
     )
Exemplo n.º 7
0
    def move_in_thin_pack(self, path):
        """Move a specific file containing a pack into the pack directory.

        :note: The file should be on the same file system as the 
            packs directory.

        :param path: Path to the pack file.
        """
        data = PackData(path)

        # Write index for the thin pack (do we really need this?)
        temppath = os.path.join(self.pack_dir, 
            sha_to_hex(urllib2.randombytes(20))+".tempidx")
        data.create_index_v2(temppath, self.get_raw)
        p = Pack.from_objects(data, load_pack_index(temppath))

        # Write a full pack version
        temppath = os.path.join(self.pack_dir, 
            sha_to_hex(urllib2.randombytes(20))+".temppack")
        write_pack(temppath, ((o, None) for o in p.iterobjects(self.get_raw)), 
                len(p))
        pack_sha = load_pack_index(temppath+".idx").objects_sha1()
        newbasename = os.path.join(self.pack_dir, "pack-%s" % pack_sha)
        os.rename(temppath+".pack", newbasename+".pack")
        os.rename(temppath+".idx", newbasename+".idx")
        self._add_known_pack(newbasename)
    def move_in_thin_pack(self, path):
        """Move a specific file containing a pack into the pack directory.

        :note: The file should be on the same file system as the 
            packs directory.

        :param path: Path to the pack file.
        """
        data = PackData(path)

        # Write index for the thin pack (do we really need this?)
        temppath = os.path.join(self.pack_dir, 
            sha_to_hex(urllib2.randombytes(20))+".tempidx")
        data.create_index_v2(temppath, self.get_raw)
        p = Pack.from_objects(data, load_pack_index(temppath))

        # Write a full pack version
        temppath = os.path.join(self.pack_dir, 
            sha_to_hex(urllib2.randombytes(20))+".temppack")
        write_pack(temppath, ((o, None) for o in p.iterobjects(self.get_raw)), 
                len(p))
        pack_sha = load_pack_index(temppath+".idx").objects_sha1()
        newbasename = os.path.join(self.pack_dir, "pack-%s" % pack_sha)
        os.rename(temppath+".pack", newbasename+".pack")
        os.rename(temppath+".idx", newbasename+".idx")
        self._add_known_pack(newbasename)
Exemplo n.º 9
0
 def test_copy(self):
     with self.get_pack(pack1_sha) as origpack:
         self.assertSucceeds(origpack.index.check)
         pack_path = os.path.join(self._tempdir, "Elch")
         write_pack(pack_path, origpack.pack_tuples())
         output = run_git_or_fail(['verify-pack', '-v', pack_path])
         orig_shas = set(o.id for o in origpack.iterobjects())
         self.assertEqual(orig_shas, _git_verify_pack_object_list(output))
Exemplo n.º 10
0
 def test_copy(self):
     with self.get_pack(pack1_sha) as origpack:
         self.assertSucceeds(origpack.index.check)
         pack_path = os.path.join(self._tempdir, b'Elch')
         write_pack(pack_path, origpack.pack_tuples())
         output = run_git_or_fail(['verify-pack', '-v', pack_path])
         orig_shas = set(o.id for o in origpack.iterobjects())
         self.assertEqual(orig_shas, _git_verify_pack_object_list(output))
Exemplo n.º 11
0
    def test_copy(self):
        origpack = self.get_pack(pack1_sha)
        self.assertEquals(True, origpack.idx.check())
        write_pack("Elch", [(x, "") for x in origpack.iterobjects()], len(origpack))
        newpack = Pack("Elch")
        self.assertEquals(origpack, newpack)
        self.assertEquals(True, newpack.idx.check())
        self.assertEquals(origpack.name(), newpack.name())
        self.assertEquals(origpack.idx.get_pack_checksum(), newpack.idx.get_pack_checksum())

        self.assertTrue(
            (origpack.idx.version != newpack.idx.version)
            or (origpack.idx.get_stored_checksum() == newpack.idx.get_stored_checksum())
        )
Exemplo n.º 12
0
    def test_copy(self):
        origpack = self.get_pack(pack1_sha)
        self.assertEquals(True, origpack.index.check())
        write_pack("Elch", [(x, "") for x in origpack.iterobjects()],
                   len(origpack))
        newpack = Pack("Elch")
        self.assertEquals(origpack, newpack)
        self.assertEquals(True, newpack.index.check())
        self.assertEquals(origpack.name(), newpack.name())
        self.assertEquals(origpack.index.get_pack_checksum(),
                          newpack.index.get_pack_checksum())

        self.assertTrue((origpack.index.version != newpack.index.version)
                        or (origpack.index.get_stored_checksum()
                            == newpack.index.get_stored_checksum()))
Exemplo n.º 13
0
 def test_deltas_work(self):
     orig_pack = self.get_pack(pack1_sha)
     orig_blob = orig_pack[a_sha]
     new_blob = Blob()
     new_blob.data = orig_blob.data + "x"
     all_to_pack = list(orig_pack.pack_tuples()) + [(new_blob, None)]
     pack_path = os.path.join(self._tempdir, "pack_with_deltas")
     write_pack(pack_path, all_to_pack, deltify=True)
     output = run_git_or_fail(["verify-pack", "-v", pack_path])
     self.assertEqual(set(x[0].id for x in all_to_pack), _git_verify_pack_object_list(output))
     # We specifically made a new blob that should be a delta
     # against the blob a_sha, so make sure we really got only 3
     # non-delta objects:
     got_non_delta = int(_NON_DELTA_RE.search(output).group("non_delta"))
     self.assertEqual(3, got_non_delta, "Expected 3 non-delta objects, got %d" % got_non_delta)
Exemplo n.º 14
0
    def test_copy(self):
        with self.get_pack(pack1_sha) as origpack:
            self.assertSucceeds(origpack.index.check)
            basename = os.path.join(self.tempdir, 'Elch')
            write_pack(basename, origpack.pack_tuples())
            with Pack(basename) as newpack:
                self.assertEqual(origpack, newpack)
                self.assertSucceeds(newpack.index.check)
                self.assertEqual(origpack.name(), newpack.name())
                self.assertEqual(origpack.index.get_pack_checksum(),
                                  newpack.index.get_pack_checksum())

                wrong_version = origpack.index.version != newpack.index.version
                orig_checksum = origpack.index.get_stored_checksum()
                new_checksum = newpack.index.get_stored_checksum()
                self.assertTrue(wrong_version or orig_checksum == new_checksum)
Exemplo n.º 15
0
    def test_copy(self):
        origpack = self.get_pack(pack1_sha)
        self.assertSucceeds(origpack.index.check)
        pack_path = os.path.join(self._tempdir, "Elch")
        write_pack(pack_path, origpack.pack_tuples())
        output = run_git_or_fail(['verify-pack', '-v', pack_path])

        pack_shas = set()
        for line in output.splitlines():
            sha = line[:40]
            try:
                binascii.unhexlify(sha)
            except TypeError:
                continue  # non-sha line
            pack_shas.add(sha)
        orig_shas = set(o.id for o in origpack.iterobjects())
        self.assertEqual(orig_shas, pack_shas)
Exemplo n.º 16
0
    def test_copy(self):
        with self.get_pack(pack1_sha) as origpack:
            self.assertSucceeds(origpack.index.check)
            basename = os.path.join(self.tempdir, 'Elch')
            write_pack(basename, origpack.pack_tuples())

            with Pack(basename) as newpack:
                self.assertEqual(origpack, newpack)
                self.assertSucceeds(newpack.index.check)
                self.assertEqual(origpack.name(), newpack.name())
                self.assertEqual(origpack.index.get_pack_checksum(),
                                 newpack.index.get_pack_checksum())

                wrong_version = origpack.index.version != newpack.index.version
                orig_checksum = origpack.index.get_stored_checksum()
                new_checksum = newpack.index.get_stored_checksum()
                self.assertTrue(wrong_version or orig_checksum == new_checksum)
Exemplo n.º 17
0
    def test_copy(self):
        origpack = self.get_pack(pack1_sha)
        self.assertSucceeds(origpack.index.check)
        pack_path = os.path.join(self._tempdir, "Elch")
        write_pack(pack_path, origpack.pack_tuples())
        output = run_git_or_fail(['verify-pack', '-v', pack_path])

        pack_shas = set()
        for line in output.splitlines():
            sha = line[:40]
            try:
                binascii.unhexlify(sha)
            except TypeError:
                continue  # non-sha line
            pack_shas.add(sha)
        orig_shas = set(o.id for o in origpack.iterobjects())
        self.assertEquals(orig_shas, pack_shas)
Exemplo n.º 18
0
 def test_deltas_work(self):
     with self.get_pack(pack1_sha) as orig_pack:
         orig_blob = orig_pack[a_sha]
         new_blob = Blob()
         new_blob.data = orig_blob.data + b'x'
         all_to_pack = list(orig_pack.pack_tuples()) + [(new_blob, None)]
     pack_path = os.path.join(self._tempdir, 'pack_with_deltas')
     write_pack(pack_path, all_to_pack, deltify=True)
     output = run_git_or_fail(['verify-pack', '-v', pack_path])
     self.assertEqual(set(x[0].id for x in all_to_pack),
                      _git_verify_pack_object_list(output))
     # We specifically made a new blob that should be a delta
     # against the blob a_sha, so make sure we really got only 3
     # non-delta objects:
     got_non_delta = int(_NON_DELTA_RE.search(output).group('non_delta'))
     self.assertEqual(
         3, got_non_delta,
         'Expected 3 non-delta objects, got %d' % got_non_delta)
Exemplo n.º 19
0
    def test_copy(self):
        origpack = self.get_pack(pack1_sha)
        self.assertEquals(True, origpack.index.check())
        pack_path = os.path.join(self._tempdir, "Elch")
        write_pack(pack_path, [(x, "") for x in origpack.iterobjects()],
                   len(origpack))

        returncode, output = run_git(['verify-pack', '-v', pack_path],
                                     capture_stdout=True)
        self.assertEquals(0, returncode)

        pack_shas = set()
        for line in output.splitlines():
            sha = line[:40]
            try:
                binascii.unhexlify(sha)
            except TypeError:
                continue  # non-sha line
            pack_shas.add(sha)
        orig_shas = set(o.id for o in origpack.iterobjects())
        self.assertEquals(orig_shas, pack_shas)
Exemplo n.º 20
0
 def write_pack(self, pack_name, objects):
      write_pack('pack-' + pack_name, [(x, "") for x in objects], 
         len(objects))
Exemplo n.º 21
0
 def _copy_pack(self, origpack):
     basename = os.path.join(self.tempdir, 'somepack')
     write_pack(basename, [(x, '') for x in origpack.iterobjects()],
                len(origpack))
     return Pack(basename)
Exemplo n.º 22
0
 def write_pack(self, pack_name, objects):
     write_pack('pack-' + pack_name, [(x, "") for x in objects],
                len(objects))
Exemplo n.º 23
0
 def _copy_pack(self, origpack):
     basename = os.path.join(self.tempdir, 'somepack')
     write_pack(basename, origpack.pack_tuples())
     return Pack(basename)
Exemplo n.º 24
0
 def _copy_pack(self, origpack):
     basename = os.path.join(self.tempdir, 'somepack')
     write_pack(basename, origpack.pack_tuples())
     return Pack(basename)
Exemplo n.º 25
0
 def test_copy(self):
     p = self.get_pack(pack1_sha)
     write_pack("Elch", p.iterobjects(), len(p))
     self.assertEquals(p, Pack("Elch"))
Exemplo n.º 26
0
 def test_copy(self):
     p = self.get_pack(pack1_sha)
     write_pack("Elch", p.iterobjects(), len(p))
     self.assertEquals(p, Pack("Elch"))