<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def ext_pillar(minion_id, pillar, repo, branch='default', root=None):
    '''
    Extract pillar from an hg repository
    '''
    with Repo(repo) as repo:
        repo.update(branch)
    envname = 'base' if branch == 'default' else branch
    if root:
        path = os.path.normpath(os.path.join(repo.working_dir, root))
    else:
        path = repo.working_dir

    opts = copy.deepcopy(__opts__)
    opts['pillar_roots'][envname] = [path]
    pil = salt.pillar.Pillar(opts, __grains__, minion_id, envname)
    return pil.compile_pillar(ext=False)