Ejemplo n.º 1
0
def _add(root, dirstate, paths, cwd):
    paths_to_add = map(lambda p: pathutil.canonpath(root, cwd, p), paths)
    if len(paths_to_add) == 0:
        paths_to_add.append(pathutil.canonpath(root, cwd, root))
    errors = dirstate.thrift_scm_add(paths_to_add)
    if len(errors):
        for error in errors:
            print(error.errorMessage)
        return 1
    return 0
Ejemplo n.º 2
0
def rename(ui, repoagent, source=None, dest=None, **opts):
    """rename dialog"""
    from tortoisehg.hgqt import rename as renamemod
    repo = repoagent.rawRepo()
    cwd = repo.getcwd()
    if source:
        source = hglib.tounicode(pathutil.canonpath(repo.root, cwd, source))
    if dest:
        dest = hglib.tounicode(pathutil.canonpath(repo.root, cwd, dest))
    iscopy = (opts.get('alias') == 'copy')
    return renamemod.RenameDialog(repoagent, None, source, dest, iscopy)
Ejemplo n.º 3
0
def rename(ui, repoagent, source=None, dest=None, **opts):
    """rename dialog"""
    from tortoisehg.hgqt import rename as renamemod
    repo = repoagent.rawRepo()
    cwd = repo.getcwd()
    if source:
        source = hglib.tounicode(pathutil.canonpath(repo.root, cwd, source))
    if dest:
        dest = hglib.tounicode(pathutil.canonpath(repo.root, cwd, dest))
    iscopy = (opts.get('alias') == 'copy')
    return renamemod.RenameDialog(repoagent, None, source, dest, iscopy)
Ejemplo n.º 4
0
def grepdiffpredicate(repo, subset, x):
    """grepdiff: a revset for code archeology

    Sample usages are:
      $ hg log --rev "grepdiff('add:command')" mercurial/commands.py
          will only match changesets that add 'command' somewhere in the diff
      $ hg log --rev "grepdiff('remove:command')" mercurial/commands.py
          will match changesets which remove 'command' somewhere in the diff
      $ hg log --rev "grepdiff('delta:command') mercurial/commands.py"
          will mathc changesets where the number of 'command' adds is different
          from the number of 'command' removes in the diff
      $ hg log --rev "grepdiff('touch:command')"
          will only match changesets which either add or remove 'command' at
          least once in the diff
      $ hg log --rev "grepdiff('inc:command')" folder/file1.py folder/file2.py
          will match changesets which increase the number of occurrences
          of 'command' in the specified files
      $ hg log --rev "grepdiff('dec:command')"
          will match changesets which decrease the number of occurrences
          of 'command'
    """
    err = _("wrong set of arguments passed to grepdiff revset")
    args = revset.getargs(x, 1, -1, err)
    files = None
    if len(args) > 1:
        files = set(pathutil.canonpath(repo.root, repo.getcwd(), arg[1])
                    for arg in args[1:])
    pattern, processor = getpatternandprocessor(repo, args)
    def matcher(rev):
        res = processor(*ctxaddsremoves(repo[rev], files, pattern))
        return res
    resset = subset.filter(matcher)
    return resset
Ejemplo n.º 5
0
def _remove(root, dirstate, paths, force, cwd):
    paths_to_remove = map(lambda p: pathutil.canonpath(root, cwd, p), paths)
    errors = dirstate.thrift_scm_remove(paths_to_remove, force)
    if len(errors):
        for error in errors:
            print(error.errorMessage)
        return 1
    return 0
Ejemplo n.º 6
0
 def haskwsource(dest):
     """Returns true if dest is a regular file and configured for
     expansion or a symlink which points to a file configured for
     expansion. """
     source = repo.dirstate.copied(dest)
     if "l" in wctx.flags(source):
         source = pathutil.canonpath(repo.root, cwd, os.path.realpath(source))
     return kwt.match(source)
Ejemplo n.º 7
0
 def haskwsource(dest):
     '''Returns true if dest is a regular file and configured for
     expansion or a symlink which points to a file configured for
     expansion. '''
     source = repo.dirstate.copied(dest)
     if 'l' in wctx.flags(source):
         source = pathutil.canonpath(repo.root, cwd,
                                    os.path.realpath(source))
     return kwt.match(source)
Ejemplo n.º 8
0
def canonpaths(list):
    'Get canonical paths (relative to root) for list of files'
    # This is a horrible hack.  Please remove this when HG acquires a
    # decent case-folding solution.
    canonpats = []
    cwd = os.getcwd()
    root = paths.find_root(cwd)
    for f in list:
        try:
            canonpats.append(pathutil.canonpath(root, cwd, f))
        except util.Abort:
            # Attempt to resolve case folding conflicts.
            fu = f.upper()
            cwdu = cwd.upper()
            if fu.startswith(cwdu):
                canonpats.append(
                    pathutil.canonpath(root, cwd, f[len(cwd + os.sep):]))
            else:
                # May already be canonical
                canonpats.append(f)
    return canonpats
Ejemplo n.º 9
0
def canonpaths(list):
    'Get canonical paths (relative to root) for list of files'
    # This is a horrible hack.  Please remove this when HG acquires a
    # decent case-folding solution.
    canonpats = []
    cwd = os.getcwd()
    root = paths.find_root(cwd)
    for f in list:
        try:
            canonpats.append(pathutil.canonpath(root, cwd, f))
        except util.Abort:
            # Attempt to resolve case folding conflicts.
            fu = f.upper()
            cwdu = cwd.upper()
            if fu.startswith(cwdu):
                canonpats.append(
                    pathutil.canonpath(root, cwd, f[len(cwd + os.sep):]))
            else:
                # May already be canonical
                canonpats.append(f)
    return canonpats
Ejemplo n.º 10
0
def get_files_from_listfile():
    global _lines
    global _linesutf8
    lines = []
    need_to_utf8 = False
    if os.name == 'nt':
        try:
            fixutf8 = extensions.find("fixutf8")
            if fixutf8:
                need_to_utf8 = True
        except KeyError:
            pass

    if need_to_utf8:
        lines += _linesutf8
        for l in _lines:
            lines.append(hglib.toutf(l))
    else:
        lines += _lines
        for l in _linesutf8:
            lines.append(hglib.fromutf(l))

    # Convert absolute file paths to repo/cwd canonical
    cwd = os.getcwd()
    root = paths.find_root(cwd)
    if not root:
        return lines
    if cwd == root:
        cwd_rel = ''
    else:
        cwd_rel = cwd[len(root+os.sep):] + os.sep
    files = []
    for f in lines:
        try:
            cpath = pathutil.canonpath(root, cwd, f)
            # canonpath will abort on .hg/ paths
        except util.Abort:
            continue
        if cpath.startswith(cwd_rel):
            cpath = cpath[len(cwd_rel):]
            files.append(cpath)
        else:
            files.append(f)
    return files
Ejemplo n.º 11
0
def get_files_from_listfile():
    global _lines
    global _linesutf8
    lines = []
    need_to_utf8 = False
    if os.name == 'nt':
        try:
            fixutf8 = extensions.find("fixutf8")
            if fixutf8:
                need_to_utf8 = True
        except KeyError:
            pass

    if need_to_utf8:
        lines += _linesutf8
        for l in _lines:
            lines.append(hglib.toutf(l))
    else:
        lines += _lines
        for l in _linesutf8:
            lines.append(hglib.fromutf(l))

    # Convert absolute file paths to repo/cwd canonical
    cwd = os.getcwd()
    root = paths.find_root(cwd)
    if not root:
        return lines
    if cwd == root:
        cwd_rel = ''
    else:
        cwd_rel = cwd[len(root + os.sep):] + os.sep
    files = []
    for f in lines:
        try:
            cpath = pathutil.canonpath(root, cwd, f)
            # canonpath will abort on .hg/ paths
        except util.Abort:
            continue
        if cpath.startswith(cwd_rel):
            cpath = cpath[len(cwd_rel):]
            files.append(cpath)
        else:
            files.append(f)
    return files
Ejemplo n.º 12
0
def cleanpath(repo, path):
    path = path.lstrip('/')
    return pathutil.canonpath(repo.root, '', path)
Ejemplo n.º 13
0
def fullpaths(ui, repo, paths):
    cwd = os.getcwd()
    return [ canonpath(repo.root, cwd, path) for path in paths ]
Ejemplo n.º 14
0
def _config(ui, repo, pats, opts, include=False, exclude=False, reset=False,
            delete=False, enableprofile=False, disableprofile=False,
            force=False):
    """
    Perform a sparse config update. Only one of the kwargs may be specified.
    """
    wlock = repo.wlock()
    try:
        oldsparsematch = repo.sparsematch()

        if repo.vfs.exists('sparse'):
            raw = repo.vfs.read('sparse')
            oldinclude, oldexclude, oldprofiles = map(
                set, repo.readsparseconfig(raw))
        else:
            oldinclude = set()
            oldexclude = set()
            oldprofiles = set()

        try:
            if reset:
                newinclude = set()
                newexclude = set()
                newprofiles = set()
            else:
                newinclude = set(oldinclude)
                newexclude = set(oldexclude)
                newprofiles = set(oldprofiles)

            if any(os.path.isabs(pat) for pat in pats):
                err = _('paths cannot be absolute')
                raise error.Abort(err)

            adjustpats = ((include or exclude or delete) and
                    not ui.configbool('sparse', 'includereporootpaths', False))
            adjustpats |= ((enableprofile or disableprofile) and
                    not ui.configbool('sparse', 'enablereporootpaths', True))
            if adjustpats:
                # supplied file patterns should be treated as relative
                # to current working dir, so we need to convert them first
                root, cwd = repo.root, repo.getcwd()
                abspats = []
                for kindpat in pats:
                    kind, pat = matchmod._patsplit(kindpat, None)
                    if kind in cwdrealtivepatkinds or kind is None:
                        kindpat = ((kind + ':' if kind else '') +
                                pathutil.canonpath(root, cwd, pat))
                    abspats.append(kindpat)
                pats = abspats

            oldstatus = repo.status()
            if include:
                newinclude.update(pats)
            elif exclude:
                newexclude.update(pats)
            elif enableprofile:
                newprofiles.update(pats)
            elif disableprofile:
                newprofiles.difference_update(pats)
            elif delete:
                newinclude.difference_update(pats)
                newexclude.difference_update(pats)

            repo.writesparseconfig(newinclude, newexclude, newprofiles)
            fcounts = map(
                len, _refresh(ui, repo, oldstatus, oldsparsematch, force))

            profilecount = (len(newprofiles - oldprofiles) -
                            len(oldprofiles - newprofiles))
            includecount = (len(newinclude - oldinclude) -
                            len(oldinclude - newinclude))
            excludecount = (len(newexclude - oldexclude) -
                            len(oldexclude - newexclude))
            _verbose_output(
                ui, opts, profilecount, includecount, excludecount, *fcounts)
        except Exception:
            repo.writesparseconfig(oldinclude, oldexclude, oldprofiles)
            raise
    finally:
        wlock.release()
Ejemplo n.º 15
0
def fullpaths(ui, repo, paths):
    cwd = os.getcwd()
    return [pathutil.canonpath(repo.root, cwd, path) for path in paths]
Ejemplo n.º 16
0
def cleanpath(repo, path):
    path = path.lstrip('/')
    return pathutil.canonpath(repo.root, '', path)
Ejemplo n.º 17
0
 def makestandin(relpath):
     path = pathutil.canonpath(repo.root, repo.getcwd(), relpath)
     return os.path.join(repo.wjoin(lfutil.standin(path)))
Ejemplo n.º 18
0
 def makestandin(relpath):
     path = pathutil.canonpath(repo.root, repo.getcwd(), relpath)
     return os.path.join(repo.wjoin(lfutil.standin(path)))