# Path: cygit2/pygit2/object.py
# class Object(object):
# 
#     TYPE_CONVERSIONS = None
# 
#     def __init__(self, object_):
#         super(Object, self).__setattr__('_object', object_)
# 
#     def __setattr__(self, key, value):
#         raise AttributeError(key)
# 
#     @property
#     def oid(self):
#         return self._object.oid
# 
#     @property
#     def type(self):
#         return self._object.type
# 
#     @property
#     def hex(self):
#         return self._object.hex
# 
#     @classmethod
#     def convert(cls, object_):
#         if Object.TYPE_CONVERSIONS is None:
#             from .blob import Blob
#             from .commit import Commit
#             from .tree import Tree
#             Object.TYPE_CONVERSIONS = {
#                 GitObjectType.BLOB: Blob,
#                 GitObjectType.COMMIT: Commit,
#                 GitObjectType.TREE: Tree,
#             }
# 
#         type_ = object_.type
#         if type_ not in Object.TYPE_CONVERSIONS:
#             raise TypeError('{!r} not in pygit2 type registry'.format(type_))
#         klass = Object.TYPE_CONVERSIONS[type_]
#         return klass(object_)
# 
# Path: cygit2/pygit2/reference.py
# class Reference(object):
# 
#     def __init__(self, reference):
#         self._reference = reference
# 
#     def __eq__(self, other):
#         return self._reference == other._reference
# 
#     def __ne__(self, other):
#         return not (self == other)
# 
#     def __gt__(self, other):
#         return self._reference > other._reference
# 
#     def __ge__(self, other):
#         return not (self < other)
# 
#     def __lt__(self, other):
#         return self._reference < other._reference
# 
#     def __le__(self, other):
#         return not (self > other)
# 
#     def get_object(self):
#         return Object.convert(self._reference.get_object())
# 
#     def has_log(self):
#         return self._reference.has_log()
# 
#     def logs(self):
#         for entry in self._reference.logs():
#             yield entry
# 
#     def is_branch(self):
#         return self._reference.is_branch()
# 
#     def is_remote(self):
#         return self._reference.is_remote()
# 
#     def resolve(self):
#         ref = self._reference.resolve()
#         if ref is self._reference:
#             return self
#         return Reference(ref)
# 
#     @property
#     def name(self):
#         return self._reference.name
# 
#     @property
#     def target(self):
#         return self._reference.target
# 
#     @property
#     def oid(self):
#         return self._reference.oid
# 
#     @property
#     def hex(self):
#         return self._reference.hex
# 
#     @property
#     def type(self):
#         return self._reference.type
# 
# Path: cygit2/pygit2/remote.py
# class Remote(object):
# 
#     def __init__(self, remote):
#         self._remote = remote
# 
#     @property
#     def name(self):
#         return self._remote.name
# 
#     @name.setter
#     def name(self, value):
#         try:
#             self._remote.name = value
#         except LibGit2ConfigError as e:
#             raise ValueError(e)
# 
#     @property
#     def refspec_count(self):
#         return self._remote.refspec_count
# 
#     @property
#     def url(self):
#         return self._remote.url
# 
#     @url.setter
#     def url(self, value):
#         try:
#             self._remote.url = value
#         except LibGit2ConfigError as e:
#             raise ValueError(e)
# 
#     def get_refspec(self, number):
#         refspec = self._remote.get_refspec(number)
#         return (refspec.source, refspec.dest)
# 
#     def save(self):
#         self._remote.save()


import logging
from cygit2._cygit2 import (
    GitOid,
    Repository as BaseRepository,
)
from cygit2._cygit2 import (
    LibGit2ConfigError,
    LibGit2Error,
    LibGit2OSError,
)
from .object import Object
from .reference import Reference
from .remote import Remote

    def __contains__(self, oid):
        if not isinstance(oid, GitOid):
            oid = GitOid(hex=oid)
        try:
            return super(Repository, self).__contains__(oid)
        except KeyError:
            return False

    def read(self, oid):
        if not isinstance(oid, GitOid):
            oid = GitOid(hex=oid)
        try:
            return super(Repository, self).read(oid)
        except LibGit2Error:
            raise KeyError(oid)

    def create_blob_fromworkdir(self, path):
        try:
            return super(Repository, self).create_blob_fromworkdir(path)
        except LibGit2OSError:
            raise KeyError(path)

    def create_remote(self, name, url):
        try:
            return Remote(super(Repository, self).create_remote(name, url))
        except LibGit2ConfigError as e:
            raise ValueError(e)

    def lookup_reference(self, name):

# Path: cygit2/pygit2/object.py
# class Object(object):
# 
#     TYPE_CONVERSIONS = None
# 
#     def __init__(self, object_):
#         super(Object, self).__setattr__('_object', object_)
# 
#     def __setattr__(self, key, value):
#         raise AttributeError(key)
# 
#     @property
#     def oid(self):
#         return self._object.oid
# 
#     @property
#     def type(self):
#         return self._object.type
# 
#     @property
#     def hex(self):
#         return self._object.hex
# 
#     @classmethod
#     def convert(cls, object_):
#         if Object.TYPE_CONVERSIONS is None:
#             from .blob import Blob
#             from .commit import Commit
#             from .tree import Tree
#             Object.TYPE_CONVERSIONS = {
#                 GitObjectType.BLOB: Blob,
#                 GitObjectType.COMMIT: Commit,
#                 GitObjectType.TREE: Tree,
#             }
# 
#         type_ = object_.type
#         if type_ not in Object.TYPE_CONVERSIONS:
#             raise TypeError('{!r} not in pygit2 type registry'.format(type_))
#         klass = Object.TYPE_CONVERSIONS[type_]
#         return klass(object_)
# 
# Path: cygit2/pygit2/reference.py
# class Reference(object):
# 
#     def __init__(self, reference):
#         self._reference = reference
# 
#     def __eq__(self, other):
#         return self._reference == other._reference
# 
#     def __ne__(self, other):
#         return not (self == other)
# 
#     def __gt__(self, other):
#         return self._reference > other._reference
# 
#     def __ge__(self, other):
#         return not (self < other)
# 
#     def __lt__(self, other):
#         return self._reference < other._reference
# 
#     def __le__(self, other):
#         return not (self > other)
# 
#     def get_object(self):
#         return Object.convert(self._reference.get_object())
# 
#     def has_log(self):
#         return self._reference.has_log()
# 
#     def logs(self):
#         for entry in self._reference.logs():
#             yield entry
# 
#     def is_branch(self):
#         return self._reference.is_branch()
# 
#     def is_remote(self):
#         return self._reference.is_remote()
# 
#     def resolve(self):
#         ref = self._reference.resolve()
#         if ref is self._reference:
#             return self
#         return Reference(ref)
# 
#     @property
#     def name(self):
#         return self._reference.name
# 
#     @property
#     def target(self):
#         return self._reference.target
# 
#     @property
#     def oid(self):
#         return self._reference.oid
# 
#     @property
#     def hex(self):
#         return self._reference.hex
# 
#     @property
#     def type(self):
#         return self._reference.type
# 
# Path: cygit2/pygit2/remote.py
# class Remote(object):
# 
#     def __init__(self, remote):
#         self._remote = remote
# 
#     @property
#     def name(self):
#         return self._remote.name
# 
#     @name.setter
#     def name(self, value):
#         try:
#             self._remote.name = value
#         except LibGit2ConfigError as e:
#             raise ValueError(e)
# 
#     @property
#     def refspec_count(self):
#         return self._remote.refspec_count
# 
#     @property
#     def url(self):
#         return self._remote.url
# 
#     @url.setter
#     def url(self, value):
#         try:
#             self._remote.url = value
#         except LibGit2ConfigError as e:
#             raise ValueError(e)
# 
#     def get_refspec(self, number):
#         refspec = self._remote.get_refspec(number)
#         return (refspec.source, refspec.dest)
# 
#     def save(self):
#         self._remote.save()


# Path: cygit2/pygit2/repository.py
import logging
from cygit2._cygit2 import (
    GitOid,
    Repository as BaseRepository,
)
from cygit2._cygit2 import (
    LibGit2ConfigError,
    LibGit2Error,
    LibGit2OSError,
)
from .object import Object
from .reference import Reference
from .remote import Remote


    def __contains__(self, oid):
        if not isinstance(oid, GitOid):
            oid = GitOid(hex=oid)
        try:
            return super(Repository, self).__contains__(oid)
        except KeyError:
            return False

    def read(self, oid):
        if not isinstance(oid, GitOid):
            oid = GitOid(hex=oid)
        try:
            return super(Repository, self).read(oid)
        except LibGit2Error:
            raise KeyError(oid)

    def create_blob_fromworkdir(self, path):
        try:
            return super(Repository, self).create_blob_fromworkdir(path)
        except LibGit2OSError:
            raise KeyError(path)

    def create_remote(self, name, url):
        try:
            return Remote(super(Repository, self).create_remote(name, url))
        except LibGit2ConfigError as e:
            raise ValueError(e)

    def lookup_reference(self, name):

        return Reference(super(Repository, self).lookup_reference(name))