Repository: activeloopai/Hub
File: deeplake/util/version_control.py (Python)

Code before:
                    base_storage[
                        "/".join(
                            [
                                tensor.key,
                                "chunks",
                                ChunkIdEncoder.name_from_id(chunk_id),
                            ]
                        )
                    ] = chunk.tobytes()

            base_storage[
                get_chunk_id_encoder_key(chunk_engine.key, FIRST_COMMIT_ID)
            ] = storage.get_bytes(
                get_chunk_id_encoder_key(chunk_engine.key, dataset.pending_commit_id)
            )
            base_storage[
                get_tensor_tile_encoder_key(chunk_engine.key, FIRST_COMMIT_ID)
            ] = storage.get_bytes(
                get_tensor_tile_encoder_key(chunk_engine.key, dataset.pending_commit_id)
            )
            base_storage[
                get_tensor_meta_key(chunk_engine.key, FIRST_COMMIT_ID)
            ] = storage.get_bytes(
                get_tensor_meta_key(chunk_engine.key, dataset.pending_commit_id)
            )
            # print(tensor.key, chunk_engine.chunk_id_encoder.name_from_id(chunk_id))

        commits_to_delete = [
            commit_id
            for commit_id in version_state["commit_node_map"].keys()
            if commit_id != FIRST_COMMIT_ID
        ]

        dataset.version_state["commit_node_map"] = {
            FIRST_COMMIT_ID: dataset.version_state["commit_node_map"][FIRST_COMMIT_ID],
        }
        dataset.version_state["commit_node_map"][FIRST_COMMIT_ID].children = []
        dataset.version_state["commit_node_map"][FIRST_COMMIT_ID].commit_message = None
        dataset.version_state["commit_node_map"][FIRST_COMMIT_ID].commit_time = None
        dataset.version_state["commit_node_map"][
            FIRST_COMMIT_ID
        ].commit_user_name = None

        dataset.version_state["branch_commit_map"]["main"] = FIRST_COMMIT_ID
        dataset.version_state["commit_id"] = FIRST_COMMIT_ID
        dataset.version_state["commit_node"] = dataset.version_state["commit_node_map"][
            FIRST_COMMIT_ID
        ]

        base_storage[get_version_control_info_key()] = json.dumps(
            _version_info_to_json(

Review comment (suggestion):
There should be other encoders too which would need to be merged. For example `sequence` and `creds_key`

Code after:
            for chunk_id in [row[0] for row in chunk_engine.chunk_id_encoder._encoded]:
                chunk = chunk_engine.get_chunk_from_chunk_id(chunk_id)
                if chunk.key.startswith("versions"):
                    base_storage[
                        "/".join(
                            [
                                tensor.key,
                                "chunks",
                                ChunkIdEncoder.name_from_id(chunk_id),
                            ]
                        )
                    ] = chunk.tobytes()

            for key_fn in [
                get_tensor_info_key,
                get_tensor_meta_key,
                get_creds_encoder_key,
                get_chunk_id_encoder_key,
                get_pad_encoder_key,
                get_sequence_encoder_key,
                get_tensor_tile_encoder_key,
            ]:
                try:
                    data_bytes = storage.get_bytes(
                        key_fn(chunk_engine.key, dataset.pending_commit_id)
                    )
                except KeyError:
                    continue

                base_storage[key_fn(chunk_engine.key, FIRST_COMMIT_ID)] = data_bytes

        commits_to_delete = [
            commit_id
            for commit_id in version_state["commit_node_map"].keys()
            if commit_id != FIRST_COMMIT_ID
        ]

        dataset.version_state["commit_node_map"] = {
            FIRST_COMMIT_ID: dataset.version_state["commit_node_map"][FIRST_COMMIT_ID],
        }
        dataset.version_state["commit_node_map"][FIRST_COMMIT_ID].children = []
        dataset.version_state["commit_node_map"][FIRST_COMMIT_ID].commit_message = None
        dataset.version_state["commit_node_map"][FIRST_COMMIT_ID].commit_time = None
        dataset.version_state["commit_node_map"][
            FIRST_COMMIT_ID
        ].commit_user_name = None

        dataset.version_state["branch_commit_map"]["main"] = FIRST_COMMIT_ID
        dataset.version_state["commit_id"] = FIRST_COMMIT_ID
        dataset.version_state["commit_node"] = dataset.version_state["commit_node_map"][
            FIRST_COMMIT_ID