Exemple #1
0
def patch(patchname, ui, strip=1, cwd=None, files={}, eolmode='strict'):
    """Apply <patchname> to the working directory.

    'eolmode' specifies how end of lines should be handled. It can be:
    - 'strict': inputs are read in binary mode, EOLs are preserved
    - 'crlf': EOLs are ignored when patching and reset to CRLF
    - 'lf': EOLs are ignored when patching and reset to LF
    - None: get it from user settings, default to 'strict'
    'eolmode' is ignored when using an external patcher program.

    Returns whether patch was applied with fuzz factor.
    """
    patcher = ui.config('ui', 'patch')
    args = []
    try:
        if patcher:
            return externalpatch(patcher, args, patchname, ui, strip, cwd,
                                 files)
        else:
            try:
                return internalpatch(patchname, ui, strip, cwd, files, eolmode)
            except NoHunks:
                patcher = util.find_exe('gpatch') or util.find_exe('patch') or 'patch'
                ui.debug(_('no valid hunks found; trying with %r instead\n') %
                         patcher)
                if util.needbinarypatch():
                    args.append('--binary')
                return externalpatch(patcher, args, patchname, ui, strip, cwd,
                                     files)
    except PatchError, err:
        s = str(err)
        if s:
            raise util.Abort(s)
        else:
            raise util.Abort(_('patch failed to apply'))
Exemple #2
0
def patch(patchname, ui, strip=1, cwd=None, files={}):
    """apply <patchname> to the working directory.
    returns whether patch was applied with fuzz factor."""
    patcher = ui.config('ui', 'patch')
    args = []
    try:
        if patcher:
            return externalpatch(patcher, args, patchname, ui, strip, cwd,
                                 files)
        else:
            try:
                return internalpatch(patchname, ui, strip, cwd, files)
            except NoHunks:
                patcher = util.find_exe('gpatch') or util.find_exe('patch')
                ui.debug('no valid hunks found; trying with %r instead\n' %
                         patcher)
                if util.needbinarypatch():
                    args.append('--binary')
                return externalpatch(patcher, args, patchname, ui, strip, cwd,
                                     files)
    except PatchError, err:
        s = str(err)
        if s:
            raise util.Abort(s)
        else:
            raise util.Abort(_('patch failed to apply'))
Exemple #3
0
def patch(patchname, ui, strip=1, cwd=None, files={}):
    """apply <patchname> to the working directory.
    returns whether patch was applied with fuzz factor."""
    patcher = ui.config('ui', 'patch')
    args = []
    try:
        if patcher:
            return externalpatch(patcher, args, patchname, ui, strip, cwd,
                                 files)
        else:
            try:
                return internalpatch(patchname, ui, strip, cwd, files)
            except NoHunks:
                patcher = util.find_exe('gpatch') or util.find_exe('patch')
                ui.debug('no valid hunks found; trying with %r instead\n' %
                         patcher)
                if util.needbinarypatch():
                    args.append('--binary')
                return externalpatch(patcher, args, patchname, ui, strip, cwd,
                                     files)
    except PatchError, err:
        s = str(err)
        if s:
            raise util.Abort(s)
        else:
            raise util.Abort(_('patch failed to apply'))
Exemple #4
0
def _findtool(ui, tool):
    if tool in _internal:
        return tool
    k = _toolstr(ui, tool, "regkey")
    if k:
        p = util.lookup_reg(k, _toolstr(ui, tool, "regname"))
        if p:
            p = util.find_exe(p + _toolstr(ui, tool, "regappend"))
            if p:
                return p
    return util.find_exe(_toolstr(ui, tool, "executable", tool))
Exemple #5
0
def _findtool(ui, tool):
    if tool in _internal:
        return tool
    k = _toolstr(ui, tool, "regkey")
    if k:
        p = util.lookup_reg(k, _toolstr(ui, tool, "regname"))
        if p:
            p = util.find_exe(p + _toolstr(ui, tool, "regappend"))
            if p:
                return p
    return util.find_exe(_toolstr(ui, tool, "executable", tool))
Exemple #6
0
def _findtool(ui, tool):
    if tool in _internal:
        return tool
    for kn in ("regkey", "regkeyalt"):
        k = _toolstr(ui, tool, kn)
        if not k:
            continue
        p = util.lookup_reg(k, _toolstr(ui, tool, "regname"))
        if p:
            p = util.find_exe(p + _toolstr(ui, tool, "regappend"))
            if p:
                return p
    return util.find_exe(_toolstr(ui, tool, "executable", tool))
Exemple #7
0
def diffstat(patchlines):
    if not util.find_exe('diffstat'):
        return
    fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
    try:
        p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name)
        try:
            for line in patchlines:
                p.tochild.write(line + "\n")
            p.tochild.close()
            if p.wait(): return
            fp = os.fdopen(fd, 'r')
            stat = []
            for line in fp:
                stat.append(line.lstrip())
            last = stat.pop()
            stat.insert(0, last)
            stat = ''.join(stat)
            return stat
        except:
            raise
    finally:
        try:
            os.unlink(name)
        except:
            pass
Exemple #8
0
def validateconfig(ui):
    '''determine if we have enough config data to try sending email.'''
    method = ui.config('email', 'method', 'smtp')
    if method == 'smtp':
        if not ui.config('smtp', 'host'):
            raise util.Abort(_('smtp specified as email transport, '
                               'but no smtp host configured'))
    else:
        if not util.find_exe(method):
            raise util.Abort(_('%r specified as email transport, '
                               'but not in PATH') % method)
Exemple #9
0
def validateconfig(ui):
    '''determine if we have enough config data to try sending email.'''
    method = ui.config('email', 'method', 'smtp')
    if method == 'smtp':
        if not ui.config('smtp', 'host'):
            raise util.Abort(_('smtp specified as email transport, '
                               'but no smtp host configured'))
    else:
        if not util.find_exe(method):
            raise util.Abort(_('%r specified as email transport, '
                               'but not in PATH') % method)
Exemple #10
0
def pytest_configure(config):
    javahome = config.getoption('javahome')
    javahome = environ.get('JAVA_HOME') if (javahome is None) else javahome
    java = config.getoption('java')
    javac = config.getoption('javac')
    if javahome and path.exists(javahome):
        Env['java'] = path.join(javahome, 'bin', 'java')
        Env['javac'] = path.join(javahome, 'bin', 'javac')
        Env['javahome'] = javahome
    else:
        Env['javac'] = find_exe('javac') if (not javac) else javac
        Env['java'] = find_exe('java') if (not java) else java
    if (not Env['javac']) or (not path.exists(Env['javac'])):
        raise Exception('javac does not exists')
    if (not Env['java']) or (not path.exists(Env['java'])):
        raise Exception('java does not exists')
    print('')
    print(f"Using java:  {Env['java']}")
    print(f"Using javac: {Env['javac']}")
    print('')
Exemple #11
0
def diffstat(patchlines):
    if not util.find_exe('diffstat'):
        return
    fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
    try:
        p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name)
        try:
            for line in patchlines:
                p.tochild.write(line + "\n")
            p.tochild.close()
            if p.wait(): return
            fp = os.fdopen(fd, 'r')
            stat = []
            for line in fp: stat.append(line.lstrip())
            last = stat.pop()
            stat.insert(0, last)
            stat = ''.join(stat)
            return stat
        except: raise
    finally:
        try: os.unlink(name)
        except: pass