'Read a reference file and return its contents.
If the reference file a symbolic reference, only read the first line of
the file. Otherwise, only read the first 40 bytes.
:param name: the refname to read, relative to refpath
:return: The contents of the ref file, or None if the file does not
exist.
:raises IOError: if any other error occurs'

def read_loose_ref(self, name):

    filename = self.refpath(name)
    try:
        with GitFile(filename, 'rb') as f:
            header = f.read(len(SYMREF))
            if (header == SYMREF):
                return (header + next(iter(f)).rstrip('\r\n'))
            else:
                return (header + f.read((40 - len(SYMREF))))
    except IOError as e:
        if (e.errno in (errno.ENOENT, errno.EISDIR)):
            return None
        raise
