Esempio n. 1
0
def add(ui, repo, match, dryrun, listsubrepos, prefix):
    join = lambda f: os.path.join(prefix, f)
    bad = []
    oldbad = match.bad
    match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
    names = []
    wctx = repo[None]
    for f in repo.walk(match):
        exact = match.exact(f)
        if exact or f not in repo.dirstate:
            names.append(f)
            if ui.verbose or not exact:
                ui.status(_('adding %s\n') % match.rel(join(f)))

    if listsubrepos:
        for subpath in wctx.substate:
            sub = wctx.sub(subpath)
            try:
                submatch = matchmod.narrowmatcher(subpath, match)
                bad.extend(sub.add(ui, submatch, dryrun, prefix))
            except error.LookupError:
                ui.status(_("skipping missing subrepository: %s\n")
                               % join(subpath))

    if not dryrun:
        rejected = wctx.add(names, prefix)
        bad.extend(f for f in rejected if f in match.files())
    return bad
Esempio n. 2
0
def add(ui, repo, match, dryrun, listsubrepos, prefix):
    join = lambda f: os.path.join(prefix, f)
    bad = []
    oldbad = match.bad
    match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
    names = []
    wctx = repo[None]
    cca = None
    abort, warn = scmutil.checkportabilityalert(ui)
    if abort or warn:
        cca = scmutil.casecollisionauditor(ui, abort, wctx)
    for f in repo.walk(match):
        exact = match.exact(f)
        if exact or f not in repo.dirstate:
            if cca:
                cca(f)
            names.append(f)
            if ui.verbose or not exact:
                ui.status(_('adding %s\n') % match.rel(join(f)))

    if listsubrepos:
        for subpath in wctx.substate:
            sub = wctx.sub(subpath)
            try:
                submatch = matchmod.narrowmatcher(subpath, match)
                bad.extend(sub.add(ui, submatch, dryrun, prefix))
            except error.LookupError:
                ui.status(
                    _("skipping missing subrepository: %s\n") % join(subpath))

    if not dryrun:
        rejected = wctx.add(names, prefix)
        bad.extend(f for f in rejected if f in match.files())
    return bad
Esempio n. 3
0
def diffordiffstat(ui, repo, diffopts, node1, node2, match,
                   changes=None, stat=False, fp=None, prefix='',
                   listsubrepos=False):
    '''show diff or diffstat.'''
    if fp is None:
        write = ui.write
    else:
        def write(s, **kw):
            fp.write(s)

    if stat:
        diffopts = diffopts.copy(context=0)
        width = 80
        if not ui.plain():
            width = ui.termwidth()
        chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
                            prefix=prefix)
        for chunk, label in patch.diffstatui(util.iterlines(chunks),
                                             width=width,
                                             git=diffopts.git):
            write(chunk, label=label)
    else:
        for chunk, label in patch.diffui(repo, node1, node2, match,
                                         changes, diffopts, prefix=prefix):
            write(chunk, label=label)

    if listsubrepos:
        ctx1 = repo[node1]
        ctx2 = repo[node2]
        for subpath, sub in subrepo.itersubrepos(ctx1, ctx2):
            if node2 is not None:
                node2 = ctx2.substate[subpath][1]
            submatch = matchmod.narrowmatcher(subpath, match)
            sub.diff(diffopts, node2, submatch, changes=changes,
                     stat=stat, fp=fp, prefix=prefix)
Esempio n. 4
0
def diffordiffstat(ui,
                   repo,
                   diffopts,
                   node1,
                   node2,
                   match,
                   changes=None,
                   stat=False,
                   fp=None,
                   prefix='',
                   listsubrepos=False):
    '''show diff or diffstat.'''
    if fp is None:
        write = ui.write
    else:

        def write(s, **kw):
            fp.write(s)

    if stat:
        diffopts = diffopts.copy(context=0)
        width = 80
        if not ui.plain():
            width = ui.termwidth()
        chunks = patch.diff(repo,
                            node1,
                            node2,
                            match,
                            changes,
                            diffopts,
                            prefix=prefix)
        for chunk, label in patch.diffstatui(util.iterlines(chunks),
                                             width=width,
                                             git=diffopts.git):
            write(chunk, label=label)
    else:
        for chunk, label in patch.diffui(repo,
                                         node1,
                                         node2,
                                         match,
                                         changes,
                                         diffopts,
                                         prefix=prefix):
            write(chunk, label=label)

    if listsubrepos:
        ctx1 = repo[node1]
        ctx2 = repo[node2]
        for subpath, sub in subrepo.itersubrepos(ctx1, ctx2):
            if node2 is not None:
                node2 = ctx2.substate[subpath][1]
            submatch = matchmod.narrowmatcher(subpath, match)
            sub.diff(diffopts,
                     node2,
                     submatch,
                     changes=changes,
                     stat=stat,
                     fp=fp,
                     prefix=prefix)
def diffordiffstat(ui, repo, diffopts, node1, node2, match,
                   changes=None, stat=False, fp=None, prefix='',
                   listsubrepos=False):
    '''show diff or diffstat.'''
    if fp is None:
        write = ui.write
    else:
        def write(s, **kw):
            fp.write(s)

    if stat:
        diffopts = diffopts.copy(context=0)
        width = 80
        if not ui.plain():
            width = ui.termwidth()
        chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
                            prefix=prefix)
        for chunk, label in patch.diffstatui(util.iterlines(chunks),
                                             width=width,
                                             git=diffopts.git):
            write(chunk, label=label)
    else:
        for chunk, label in patch.diffui(repo, node1, node2, match,
                                         changes, diffopts, prefix=prefix):
            write(chunk, label=label)

    if listsubrepos:
        ctx1 = repo[node1]
        ctx2 = repo[node2]
        for subpath, sub in subrepo.itersubrepos(ctx1, ctx2):
            tempnode2 = node2
            try:
                if node2 is not None:
                    tempnode2 = ctx2.substate[subpath][1]
            except KeyError:
                # A subrepo that existed in node1 was deleted between node1 and
                # node2 (inclusive). Thus, ctx2's substate won't contain that
                # subpath. The best we can do is to ignore it.
                tempnode2 = None
            submatch = matchmod.narrowmatcher(subpath, match)
            sub.diff(diffopts, tempnode2, submatch, changes=changes,
                     stat=stat, fp=fp, prefix=prefix)
def forget(ui, repo, match, prefix, explicitonly):
    join = lambda f: os.path.join(prefix, f)
    bad = []
    oldbad = match.bad
    match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
    wctx = repo[None]
    forgot = []
    s = repo.status(match=match, clean=True)
    forget = sorted(s[0] + s[1] + s[3] + s[6])
    if explicitonly:
        forget = [f for f in forget if match.exact(f)]

    for subpath in wctx.substate:
        sub = wctx.sub(subpath)
        try:
            submatch = matchmod.narrowmatcher(subpath, match)
            subbad, subforgot = sub.forget(ui, submatch, prefix)
            bad.extend([subpath + '/' + f for f in subbad])
            forgot.extend([subpath + '/' + f for f in subforgot])
        except error.LookupError:
            ui.status(_("skipping missing subrepository: %s\n")
                           % join(subpath))

    if not explicitonly:
        for f in match.files():
            if f not in repo.dirstate and not os.path.isdir(match.rel(join(f))):
                if f not in forgot:
                    if os.path.exists(match.rel(join(f))):
                        ui.warn(_('not removing %s: '
                                  'file is already untracked\n')
                                % match.rel(join(f)))
                    bad.append(f)

    for f in forget:
        if ui.verbose or not match.exact(f):
            ui.status(_('removing %s\n') % match.rel(join(f)))

    rejected = wctx.forget(forget, prefix)
    bad.extend(f for f in rejected if f in match.files())
    forgot.extend(forget)
    return bad, forgot
Esempio n. 7
0
def add(ui, repo, match, dryrun, listsubrepos, prefix, explicitonly):
    join = lambda f: os.path.join(prefix, f)
    bad = []
    oldbad = match.bad
    match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
    names = []
    wctx = repo[None]
    cca = None
    abort, warn = scmutil.checkportabilityalert(ui)
    if abort or warn:
        cca = scmutil.casecollisionauditor(ui, abort, wctx)
    for f in repo.walk(match):
        exact = match.exact(f)
        if exact or not explicitonly and f not in repo.dirstate:
            if cca:
                cca(f)
            names.append(f)
            if ui.verbose or not exact:
                ui.status(_('adding %s\n') % match.rel(join(f)))

    for subpath in wctx.substate:
        sub = wctx.sub(subpath)
        try:
            submatch = matchmod.narrowmatcher(subpath, match)
            if listsubrepos:
                bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
                                   False))
            else:
                bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
                                   True))
        except error.LookupError:
            ui.status(_("skipping missing subrepository: %s\n")
                           % join(subpath))

    if not dryrun:
        rejected = wctx.add(names, prefix)
        bad.extend(f for f in rejected if f in match.files())
    return bad
Esempio n. 8
0
def archive(repo, dest, node, kind, decode=True, matchfn=None,
            prefix='', mtime=None, subrepos=False):
    '''create archive of repo as it was at node.

    dest can be name of directory, name of archive file, or file
    object to write archive to.

    kind is type of archive to create.

    decode tells whether to put files through decode filters from
    hgrc.

    matchfn is function to filter names of files to write to archive.

    prefix is name of path to put before every archive member.'''

    if kind == 'files':
        if prefix:
            raise util.Abort(_('cannot give prefix when archiving to files'))
    else:
        prefix = tidyprefix(dest, kind, prefix)

    def write(name, mode, islink, getdata):
        data = getdata()
        if decode:
            data = repo.wwritedata(name, data)
        archiver.addfile(prefix + name, mode, islink, data)

    if kind not in archivers:
        raise util.Abort(_("unknown archive type '%s'") % kind)

    ctx = repo[node]
    archiver = archivers[kind](dest, mtime or ctx.date()[0])

    if repo.ui.configbool("ui", "archivemeta", True):
        name = '.hg_archival.txt'
        if not matchfn or matchfn(name):
            write(name, 0644, False, lambda: buildmetadata(ctx))

    if matchfn:
        files = [f for f in ctx.manifest().keys() if matchfn(f)]
    else:
        files = ctx.manifest().keys()
    total = len(files)
    if total:
        files.sort()
        repo.ui.progress(_('archiving'), 0, unit=_('files'), total=total)
        for i, f in enumerate(files):
            ff = ctx.flags(f)
            write(f, 'x' in ff and 0755 or 0644, 'l' in ff, ctx[f].data)
            repo.ui.progress(_('archiving'), i + 1, item=f,
                             unit=_('files'), total=total)
        repo.ui.progress(_('archiving'), None)

    if subrepos:
        for subpath in sorted(ctx.substate):
            sub = ctx.sub(subpath)
            submatch = matchmod.narrowmatcher(subpath, matchfn)
            total += sub.archive(archiver, prefix, submatch)

    if total == 0:
        raise error.Abort(_('no files match the archive pattern'))

    archiver.done()
    return total
Esempio n. 9
0
def archive(repo,
            dest,
            node,
            kind,
            decode=True,
            matchfn=None,
            prefix='',
            mtime=None,
            subrepos=False):
    '''create archive of repo as it was at node.

    dest can be name of directory, name of archive file, or file
    object to write archive to.

    kind is type of archive to create.

    decode tells whether to put files through decode filters from
    hgrc.

    matchfn is function to filter names of files to write to archive.

    prefix is name of path to put before every archive member.'''

    if kind == 'files':
        if prefix:
            raise util.Abort(_('cannot give prefix when archiving to files'))
    else:
        prefix = tidyprefix(dest, kind, prefix)

    def write(name, mode, islink, getdata):
        data = getdata()
        if decode:
            data = repo.wwritedata(name, data)
        archiver.addfile(prefix + name, mode, islink, data)

    if kind not in archivers:
        raise util.Abort(_("unknown archive type '%s'") % kind)

    ctx = repo[node]
    archiver = archivers[kind](dest, mtime or ctx.date()[0])

    if repo.ui.configbool("ui", "archivemeta", True):
        name = '.hg_archival.txt'
        if not matchfn or matchfn(name):
            write(name, 0o644, False, lambda: buildmetadata(ctx))

    if matchfn:
        files = [f for f in ctx.manifest().keys() if matchfn(f)]
    else:
        files = ctx.manifest().keys()
    total = len(files)
    if total:
        files.sort()
        repo.ui.progress(_('archiving'), 0, unit=_('files'), total=total)
        for i, f in enumerate(files):
            ff = ctx.flags(f)
            write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, ctx[f].data)
            repo.ui.progress(_('archiving'),
                             i + 1,
                             item=f,
                             unit=_('files'),
                             total=total)
        repo.ui.progress(_('archiving'), None)

    if subrepos:
        for subpath in sorted(ctx.substate):
            sub = ctx.workingsub(subpath)
            submatch = matchmod.narrowmatcher(subpath, matchfn)
            total += sub.archive(archiver, prefix, submatch)

    if total == 0:
        raise error.Abort(_('no files match the archive pattern'))

    archiver.done()
    return total
Esempio n. 10
0
def addremove(repo, matcher, prefix, opts={}, dry_run=None, similarity=None):
    m = matcher
    if dry_run is None:
        dry_run = opts.get('dry_run')
    if similarity is None:
        similarity = float(opts.get('similarity') or 0)

    ret = 0
    join = lambda f: os.path.join(prefix, f)

    def matchessubrepo(matcher, subpath):
        if matcher.exact(subpath):
            return True
        for f in matcher.files():
            if f.startswith(subpath):
                return True
        return False

    wctx = repo[None]
    for subpath in sorted(wctx.substate):
        if opts.get('subrepos') or matchessubrepo(m, subpath):
            sub = wctx.sub(subpath)
            try:
                submatch = matchmod.narrowmatcher(subpath, m)
                if sub.addremove(submatch, prefix, opts, dry_run, similarity):
                    ret = 1
            except error.LookupError:
                repo.ui.status(_("skipping missing subrepository: %s\n")
                                 % join(subpath))

    rejected = []
    def badfn(f, msg):
        if f in m.files():
            m.bad(f, msg)
        rejected.append(f)

    badmatch = matchmod.badmatch(m, badfn)
    added, unknown, deleted, removed, forgotten = _interestingfiles(repo,
                                                                    badmatch)

    unknownset = set(unknown + forgotten)
    toprint = unknownset.copy()
    toprint.update(deleted)
    for abs in sorted(toprint):
        if repo.ui.verbose or not m.exact(abs):
            if abs in unknownset:
                status = _('adding %s\n') % m.uipath(abs)
            else:
                status = _('removing %s\n') % m.uipath(abs)
            repo.ui.status(status)

    renames = _findrenames(repo, m, added + unknown, removed + deleted,
                           similarity)

    if not dry_run:
        _markchanges(repo, unknown + forgotten, deleted, renames)

    for f in rejected:
        if f in m.files():
            return 1
    return ret
Esempio n. 11
0
def addremove(repo, matcher, prefix, opts={}, dry_run=None, similarity=None):
    m = matcher
    if dry_run is None:
        dry_run = opts.get('dry_run')
    if similarity is None:
        similarity = float(opts.get('similarity') or 0)

    ret = 0
    join = lambda f: os.path.join(prefix, f)

    def matchessubrepo(matcher, subpath):
        if matcher.exact(subpath):
            return True
        for f in matcher.files():
            if f.startswith(subpath):
                return True
        return False

    wctx = repo[None]
    for subpath in sorted(wctx.substate):
        if opts.get('subrepos') or matchessubrepo(m, subpath):
            sub = wctx.sub(subpath)
            try:
                submatch = matchmod.narrowmatcher(subpath, m)
                if sub.addremove(submatch, prefix, opts, dry_run, similarity):
                    ret = 1
            except error.LookupError:
                repo.ui.status(
                    _("skipping missing subrepository: %s\n") % join(subpath))

    rejected = []
    origbad = m.bad

    def badfn(f, msg):
        if f in m.files():
            origbad(f, msg)
        rejected.append(f)

    m.bad = badfn
    added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m)
    m.bad = origbad

    unknownset = set(unknown + forgotten)
    toprint = unknownset.copy()
    toprint.update(deleted)
    for abs in sorted(toprint):
        if repo.ui.verbose or not m.exact(abs):
            if abs in unknownset:
                status = _('adding %s\n') % m.uipath(abs)
            else:
                status = _('removing %s\n') % m.uipath(abs)
            repo.ui.status(status)

    renames = _findrenames(repo, m, added + unknown, removed + deleted,
                           similarity)

    if not dry_run:
        _markchanges(repo, unknown + forgotten, deleted, renames)

    for f in rejected:
        if f in m.files():
            return 1
    return ret
Esempio n. 12
0
def archive(repo,
            dest,
            node,
            kind,
            decode=True,
            matchfn=None,
            prefix=None,
            mtime=None,
            subrepos=False):
    '''create archive of repo as it was at node.

    dest can be name of directory, name of archive file, or file
    object to write archive to.

    kind is type of archive to create.

    decode tells whether to put files through decode filters from
    hgrc.

    matchfn is function to filter names of files to write to archive.

    prefix is name of path to put before every archive member.'''

    if kind == 'files':
        if prefix:
            raise util.Abort(_('cannot give prefix when archiving to files'))
    else:
        prefix = tidyprefix(dest, kind, prefix)

    def write(name, mode, islink, getdata):
        data = getdata()
        if decode:
            data = repo.wwritedata(name, data)
        archiver.addfile(prefix + name, mode, islink, data)

    if kind not in archivers:
        raise util.Abort(_("unknown archive type '%s'") % kind)

    ctx = repo[node]
    archiver = archivers[kind](dest, mtime or ctx.date()[0])

    if repo.ui.configbool("ui", "archivemeta", True):

        def metadata():
            base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
                repo[0].hex(), hex(node), encoding.fromlocal(ctx.branch()))

            tags = ''.join('tag: %s\n' % t for t in ctx.tags()
                           if repo.tagtype(t) == 'global')
            if not tags:
                repo.ui.pushbuffer()
                opts = {
                    'template': '{latesttag}\n{latesttagdistance}',
                    'style': '',
                    'patch': None,
                    'git': None
                }
                cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
                ltags, dist = repo.ui.popbuffer().split('\n')
                tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':'))
                tags += 'latesttagdistance: %s\n' % dist

            return base + tags

        name = '.hg_archival.txt'
        if not matchfn or matchfn(name):
            write(name, 0644, False, metadata)

    if matchfn:
        files = [f for f in ctx.manifest().keys() if matchfn(f)]
    else:
        files = ctx.manifest().keys()
    total = len(files)
    if total:
        files.sort()
        repo.ui.progress(_('archiving'), 0, unit=_('files'), total=total)
        for i, f in enumerate(files):
            ff = ctx.flags(f)
            write(f, 'x' in ff and 0755 or 0644, 'l' in ff, ctx[f].data)
            repo.ui.progress(_('archiving'),
                             i + 1,
                             item=f,
                             unit=_('files'),
                             total=total)
        repo.ui.progress(_('archiving'), None)

    if subrepos:
        for subpath in sorted(ctx.substate):
            sub = ctx.sub(subpath)
            submatch = matchmod.narrowmatcher(subpath, matchfn)
            total += sub.archive(repo.ui, archiver, prefix, submatch)

    if total == 0:
        raise error.Abort(_('no files match the archive pattern'))

    archiver.done()
    return total
Esempio n. 13
0
def archive(repo, dest, node, kind, decode=True, matchfn=None,
            prefix=None, mtime=None, subrepos=False):
    '''create archive of repo as it was at node.

    dest can be name of directory, name of archive file, or file
    object to write archive to.

    kind is type of archive to create.

    decode tells whether to put files through decode filters from
    hgrc.

    matchfn is function to filter names of files to write to archive.

    prefix is name of path to put before every archive member.'''

    if kind == 'files':
        if prefix:
            raise util.Abort(_('cannot give prefix when archiving to files'))
    else:
        prefix = tidyprefix(dest, kind, prefix)

    def write(name, mode, islink, getdata):
        data = getdata()
        if decode:
            data = repo.wwritedata(name, data)
        archiver.addfile(prefix + name, mode, islink, data)

    if kind not in archivers:
        raise util.Abort(_("unknown archive type '%s'") % kind)

    ctx = repo[node]
    archiver = archivers[kind](dest, mtime or ctx.date()[0])

    if repo.ui.configbool("ui", "archivemeta", True):
        def metadata():
            base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
                repo[0].hex(), hex(node), encoding.fromlocal(ctx.branch()))

            tags = ''.join('tag: %s\n' % t for t in ctx.tags()
                           if repo.tagtype(t) == 'global')
            if not tags:
                repo.ui.pushbuffer()
                opts = {'template': '{latesttag}\n{latesttagdistance}',
                        'style': '', 'patch': None, 'git': None}
                cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
                ltags, dist = repo.ui.popbuffer().split('\n')
                ltags = ltags.split(':')
                changessince = len(repo.revs('only(.,%s)', ltags[0]))
                tags = ''.join('latesttag: %s\n' % t for t in ltags)
                tags += 'latesttagdistance: %s\n' % dist
                tags += 'changessincelatesttag: %s\n' % changessince

            return base + tags

        name = '.hg_archival.txt'
        if not matchfn or matchfn(name):
            write(name, 0644, False, metadata)

    if matchfn:
        files = [f for f in ctx.manifest().keys() if matchfn(f)]
    else:
        files = ctx.manifest().keys()
    total = len(files)
    if total:
        files.sort()
        repo.ui.progress(_('archiving'), 0, unit=_('files'), total=total)
        for i, f in enumerate(files):
            ff = ctx.flags(f)
            write(f, 'x' in ff and 0755 or 0644, 'l' in ff, ctx[f].data)
            repo.ui.progress(_('archiving'), i + 1, item=f,
                             unit=_('files'), total=total)
        repo.ui.progress(_('archiving'), None)

    if subrepos:
        for subpath in sorted(ctx.substate):
            sub = ctx.sub(subpath)
            submatch = matchmod.narrowmatcher(subpath, matchfn)
            total += sub.archive(archiver, prefix, submatch)

    if total == 0:
        raise error.Abort(_('no files match the archive pattern'))

    archiver.done()
    return total