def get_tree(self, tgt_env):
        '''
        Return a dulwich.objects.Tree object if the branch/tag/SHA is found,
        otherwise None
        '''
        if tgt_env == 'base':
            tgt_ref = self.base
        else:
            tgt_ref = tgt_env
        refs = self.repo.get_refs()
        # Sorting ensures we check heads (branches) before tags
        for ref in sorted(self.get_env_refs(refs)):
            # ref will be something like 'refs/remotes/origin/master'
            try:
                rtype, rspec = re.split('^refs/(remotes/origin|tags)/',
                                        ref,
                                        1)[-2:]
            except __HOLE__:
                # No match was fount for the split regex, we don't care about
                # this ref. We shouldn't see any of these as the refs are being
                # filtered through self.get_env_refs(), but just in case, this
                # will avoid a traceback.
                continue
            if rspec == tgt_ref and self.env_is_exposed(tgt_env):
                if rtype == 'remotes/origin':
                    commit = self.repo.get_object(refs[ref])
                elif rtype == 'tags':
                    tag = self.repo.get_object(refs[ref])
                    if isinstance(tag, dulwich.objects.Tag):
                        # Tag.get_object() returns a 2-tuple, the 2nd element
                        # of which is the commit SHA to which the tag refers
                        commit = self.repo.get_object(tag.object[1])
                    elif isinstance(tag, dulwich.objects.Commit):
                        commit = tag
                    else:
                        log.error(
                            'Unhandled object type \'{0}\' in '
                            'Dulwich get_tree. This is a bug, please '
                            'report it.'.format(tag.type_name)
                        )
                return self.repo.get_object(commit.tree)

        # Branch or tag not matched, check if 'tgt_env' is a commit. This is more
        # difficult with Dulwich because of its inability to deal with shortened
        # SHA-1 hashes.
        if not self.env_is_exposed(tgt_env):
            return None
        try:
            int(tgt_ref, 16)
        except ValueError:
            # Not hexidecimal, likely just a non-matching environment
            return None

        try:
            if len(tgt_ref) == 40:
                sha_obj = self.repo.get_object(tgt_ref)
                if isinstance(sha_obj, dulwich.objects.Commit):
                    sha_commit = sha_obj
            else:
                matches = set([
                    x for x in (
                        self.repo.get_object(y)
                        for y in self.repo.object_store
                        if y.startswith(tgt_ref)
                    )
                    if isinstance(x, dulwich.objects.Commit)
                ])
                if len(matches) > 1:
                    log.warning('Ambiguous commit ID \'{0}\''.format(tgt_ref))
                    return None
                try:
                    sha_commit = matches.pop()
                except IndexError:
                    pass
        except TypeError as exc:
            log.warning('Invalid environment {0}: {1}'.format(tgt_env, exc))
        except KeyError:
            # No matching SHA
            return None

        try:
            return self.repo.get_object(sha_commit.tree)
        except NameError:
            # No matching sha_commit object was created. Unable to find SHA.
            pass
        return None
dataset/ETHPy150Open saltstack/salt/salt/utils/gitfs.py/Dulwich.get_tree