示例#1
0
文件: kiln.py 项目: szechyjs/dotfiles
def remember_path(ui, repo, path, value):
    '''appends the path to the working copy's hgrc and backs up the original'''

    paths = dict(ui.configitems('paths'))
    # This should never happen.
    if path in paths:
        return
    # ConfigParser only cares about these three characters.
    if re.search(r'[:=\s]', path):
        return

    try:
        audit_path = scmutil.pathauditor(repo.root)
    except ImportError:
        audit_path = getattr(repo.opener, 'audit_path', util.path_auditor(repo.root))

    audit_path('hgrc')
    audit_path('hgrc.backup')
    base = repo.opener.base

    hgrc, backup = [os.path.join(base, x) for x in 'hgrc', 'hgrc.backup']
    if os.path.exists(hgrc):
        util.copyfile(hgrc, backup)

    ui.setconfig('paths', path, value)

    try:
        fp = repo.opener('hgrc', 'a', text=True)
        # Mercurial assumes Unix newlines by default and so do we.
        fp.write('\n[paths]\n%s = %s\n' % (path, value))
        fp.close()
    except IOError:
        return
示例#2
0
文件: kiln.py 项目: istruble/dotfiles
def remember_path(ui, repo, path, value):
    '''appends the path to the working copy's hgrc and backs up the original'''

    paths = dict(ui.configitems('paths'))
    # This should never happen.
    if path in paths: return
    # ConfigParser only cares about these three characters.
    if re.search(r'[:=\s]', path): return

    try:
        audit_path = scmutil.pathauditor(repo.root)
    except ImportError:
        audit_path = getattr(repo.opener, 'audit_path',
                             util.path_auditor(repo.root))

    audit_path('hgrc')
    audit_path('hgrc.backup')
    base = repo.opener.base

    hgrc, backup = [os.path.join(base, x) for x in 'hgrc', 'hgrc.backup']
    if os.path.exists(hgrc):
        util.copyfile(hgrc, backup)

    ui.setconfig('paths', path, value)

    try:
        fp = repo.opener('hgrc', 'a', text=True)
        # Mercurial assumes Unix newlines by default and so do we.
        fp.write('\n[paths]\n%s = %s\n' % (path, value))
        fp.close()
    except IOError:
        return
示例#3
0
def build_audit_path(repo):
    try:
        # Mercurial 2.9
        return pathutil.pathauditor(repo.root)
    except ImportError:
        try:
            # Mercurial 1.9 to 2.9
            return scmutil.pathauditor(repo.root)
        except ImportError:
            # Mercurial < 1.9
            return getattr(repo.opener, 'audit_path', util.path_auditor(repo.root))
示例#4
0
文件: kiln.py 项目: szechyjs/dotfiles
def unremember_path(ui, repo):
    '''restores the working copy's hgrc'''

    try:
        audit_path = scmutil.pathauditor(repo.root)
    except ImportError:
        audit_path = getattr(repo.opener, 'audit_path', util.path_auditor(repo.root))

    audit_path('hgrc')
    audit_path('hgrc.backup')
    base = repo.opener.base

    hgrc, backup = [os.path.join(base, x) for x in 'hgrc', 'hgrc.backup']
    if os.path.exists(backup):
        util.copyfile(backup, hgrc)
    else:
        os.remove(hgrc)
示例#5
0
文件: kiln.py 项目: istruble/dotfiles
def unremember_path(ui, repo):
    '''restores the working copy's hgrc'''

    try:
        audit_path = scmutil.pathauditor(repo.root)
    except ImportError:
        audit_path = getattr(repo.opener, 'audit_path',
                             util.path_auditor(repo.root))

    audit_path('hgrc')
    audit_path('hgrc.backup')
    base = repo.opener.base

    hgrc, backup = [os.path.join(base, x) for x in 'hgrc', 'hgrc.backup']
    if os.path.exists(backup):
        util.copyfile(backup, hgrc)
    else:
        os.remove(hgrc)