示例#1
0
def clean(repo, node, show_stats=True):
    """forcibly switch the working directory to node, clobbering changes"""
    stats = updaterepo(repo, node, True)
    util.unlinkpath(repo.join('graftstate'), ignoremissing=True)
    if show_stats:
        _showstats(repo, stats)
    return stats[3] > 0
示例#2
0
def clean(repo, node, show_stats=True):
    """forcibly switch the working directory to node, clobbering changes"""
    stats = updaterepo(repo, node, True)
    util.unlinkpath(repo.join('graftstate'), ignoremissing=True)
    if show_stats:
        _showstats(repo, stats)
    return stats[3] > 0
示例#3
0
 def remove(self, list, unlink=False):
     if unlink:
         for f in list:
             try:
                 util.unlinkpath(self._repo.wjoin(f))
             except OSError, inst:
                 if inst.errno != errno.ENOENT:
                     raise
示例#4
0
 def remove(self, list, unlink=False):
     if unlink:
         for f in list:
             try:
                 util.unlinkpath(self._repo.wjoin(f))
             except OSError, inst:
                 if inst.errno != errno.ENOENT:
                     raise
示例#5
0
def applyupdates(repo, actions, wctx, mctx, overwrite, labels=None):
    """apply the merge action list to the working directory

    wctx is the working copy context
    mctx is the context to be merged into the working copy

    Return a tuple of counts (updated, merged, removed, unresolved) that
    describes how many files were affected by the update.
    """

    updated, merged, removed, unresolved = 0, 0, 0, 0
    ms = mergestate(repo)
    ms.reset(wctx.p1().node(), mctx.node())
    moves = []
    for m, l in actions.items():
        l.sort()

    # prescan for merges
    for f, args, msg in actions['m']:
        f1, f2, fa, move, anc = args
        if f == '.hgsubstate':  # merged internally
            continue
        repo.ui.debug(" preserving %s for resolve of %s\n" % (f1, f))
        fcl = wctx[f1]
        fco = mctx[f2]
        actx = repo[anc]
        if fa in actx:
            fca = actx[fa]
        else:
            fca = repo.filectx(f1, fileid=nullrev)
        ms.add(fcl, fco, fca, f)
        if f1 != f and move:
            moves.append(f1)

    audit = repo.wopener.audit
    _updating = _('updating')
    _files = _('files')
    progress = repo.ui.progress

    # remove renamed files after safely stored
    for f in moves:
        if os.path.lexists(repo.wjoin(f)):
            repo.ui.debug("removing %s\n" % f)
            audit(f)
            util.unlinkpath(repo.wjoin(f))

    numupdates = sum(len(l) for m, l in actions.items() if m != 'k')

    if [a for a in actions['r'] if a[0] == '.hgsubstate']:
        subrepo.submerge(repo, wctx, mctx, wctx, overwrite)

    # remove in parallel (must come first)
    z = 0
    prog = worker.worker(repo.ui, 0.001, batchremove, (repo, ), actions['r'])
    for i, item in prog:
        z += i
        progress(_updating, z, item=item, total=numupdates, unit=_files)
    removed = len(actions['r'])

    # get in parallel
    prog = worker.worker(repo.ui, 0.001, batchget, (repo, mctx), actions['g'])
    for i, item in prog:
        z += i
        progress(_updating, z, item=item, total=numupdates, unit=_files)
    updated = len(actions['g'])

    if [a for a in actions['g'] if a[0] == '.hgsubstate']:
        subrepo.submerge(repo, wctx, mctx, wctx, overwrite)

    # forget (manifest only, just log it) (must come first)
    for f, args, msg in actions['f']:
        repo.ui.debug(" %s: %s -> f\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)

    # re-add (manifest only, just log it)
    for f, args, msg in actions['a']:
        repo.ui.debug(" %s: %s -> a\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)

    # keep (noop, just log it)
    for f, args, msg in actions['k']:
        repo.ui.debug(" %s: %s -> k\n" % (f, msg))
        # no progress

    # merge
    for f, args, msg in actions['m']:
        repo.ui.debug(" %s: %s -> m\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        f1, f2, fa, move, anc = args
        if f == '.hgsubstate':  # subrepo states need updating
            subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), overwrite)
            continue
        audit(f)
        r = ms.resolve(f, wctx, labels=labels)
        if r is not None and r > 0:
            unresolved += 1
        else:
            if r is None:
                updated += 1
            else:
                merged += 1

    # directory rename, move local
    for f, args, msg in actions['dm']:
        repo.ui.debug(" %s: %s -> dm\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        f0, flags = args
        repo.ui.note(_("moving %s to %s\n") % (f0, f))
        audit(f)
        repo.wwrite(f, wctx.filectx(f0).data(), flags)
        util.unlinkpath(repo.wjoin(f0))
        updated += 1

    # local directory rename, get
    for f, args, msg in actions['dg']:
        repo.ui.debug(" %s: %s -> dg\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        f0, flags = args
        repo.ui.note(_("getting %s to %s\n") % (f0, f))
        repo.wwrite(f, mctx.filectx(f0).data(), flags)
        updated += 1

    # divergent renames
    for f, args, msg in actions['dr']:
        repo.ui.debug(" %s: %s -> dr\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        fl, = args
        repo.ui.warn(
            _("note: possible conflict - %s was renamed "
              "multiple times to:\n") % f)
        for nf in fl:
            repo.ui.warn(" %s\n" % nf)

    # rename and delete
    for f, args, msg in actions['rd']:
        repo.ui.debug(" %s: %s -> rd\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        fl, = args
        repo.ui.warn(
            _("note: possible conflict - %s was deleted "
              "and renamed to:\n") % f)
        for nf in fl:
            repo.ui.warn(" %s\n" % nf)

    # exec
    for f, args, msg in actions['e']:
        repo.ui.debug(" %s: %s -> e\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        flags, = args
        audit(f)
        util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags)
        updated += 1

    ms.commit()
    progress(_updating, None, total=numupdates, unit=_files)

    return updated, merged, removed, unresolved
示例#6
0
 def unlinkpath(self, path=None, ignoremissing=False):
     return util.unlinkpath(self.join(path), ignoremissing)
示例#7
0
def applyupdates(repo, action, wctx, mctx, actx, overwrite):
    """apply the merge action list to the working directory

    wctx is the working copy context
    mctx is the context to be merged into the working copy
    actx is the context of the common ancestor

    Return a tuple of counts (updated, merged, removed, unresolved) that
    describes how many files were affected by the update.
    """

    updated, merged, removed, unresolved = 0, 0, 0, 0
    ms = mergestate(repo)
    ms.reset(wctx.p1().node())
    moves = []
    action.sort(key=actionkey)

    # prescan for merges
    for a in action:
        f, m = a[:2]
        if m == 'm':  # merge
            f2, fd, flags, move = a[2:]
            if f == '.hgsubstate':  # merged internally
                continue
            repo.ui.debug("preserving %s for resolve of %s\n" % (f, fd))
            fcl = wctx[f]
            fco = mctx[f2]
            if mctx == actx:  # backwards, use working dir parent as ancestor
                if fcl.parents():
                    fca = fcl.p1()
                else:
                    fca = repo.filectx(f, fileid=nullrev)
            else:
                fca = fcl.ancestor(fco, actx)
            if not fca:
                fca = repo.filectx(f, fileid=nullrev)
            ms.add(fcl, fco, fca, fd, flags)
            if f != fd and move:
                moves.append(f)

    audit = scmutil.pathauditor(repo.root)

    # remove renamed files after safely stored
    for f in moves:
        if os.path.lexists(repo.wjoin(f)):
            repo.ui.debug("removing %s\n" % f)
            audit(f)
            os.unlink(repo.wjoin(f))

    numupdates = len(action)
    for i, a in enumerate(action):
        f, m = a[:2]
        repo.ui.progress(_('updating'),
                         i + 1,
                         item=f,
                         total=numupdates,
                         unit=_('files'))
        if f and f[0] == "/":
            continue
        if m == "r":  # remove
            repo.ui.note(_("removing %s\n") % f)
            audit(f)
            if f == '.hgsubstate':  # subrepo states need updating
                subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
            try:
                util.unlinkpath(repo.wjoin(f))
            except OSError, inst:
                if inst.errno != errno.ENOENT:
                    repo.ui.warn(
                        _("update failed to remove %s: %s!\n") %
                        (f, inst.strerror))
            removed += 1
        elif m == "m":  # merge
            if f == '.hgsubstate':  # subrepo states need updating
                subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
                                 overwrite)
                continue
            f2, fd, flags, move = a[2:]
            repo.wopener.audit(fd)
            r = ms.resolve(fd, wctx, mctx)
            if r is not None and r > 0:
                unresolved += 1
            else:
                if r is None:
                    updated += 1
                else:
                    merged += 1
            if (move and repo.dirstate.normalize(fd) != f
                    and os.path.lexists(repo.wjoin(f))):
                repo.ui.debug("removing %s\n" % f)
                audit(f)
                os.unlink(repo.wjoin(f))
示例#8
0
     flags = a[2]
     repo.ui.note(_("getting %s\n") % f)
     t = mctx.filectx(f).data()
     repo.wwrite(f, t, flags)
     t = None
     updated += 1
     if f == '.hgsubstate':  # subrepo states need updating
         subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
 elif m == "d":  # directory rename
     f2, fd, flags = a[2:]
     if f:
         repo.ui.note(_("moving %s to %s\n") % (f, fd))
         audit(f)
         t = wctx.filectx(f).data()
         repo.wwrite(fd, t, flags)
         util.unlinkpath(repo.wjoin(f))
     if f2:
         repo.ui.note(_("getting %s to %s\n") % (f2, fd))
         t = mctx.filectx(f2).data()
         repo.wwrite(fd, t, flags)
     updated += 1
 elif m == "dr":  # divergent renames
     fl = a[2]
     repo.ui.warn(
         _("note: possible conflict - %s was renamed "
           "multiple times to:\n") % f)
     for nf in fl:
         repo.ui.warn(" %s\n" % nf)
 elif m == "e":  # exec
     flags = a[2]
     repo.wopener.audit(f)
示例#9
0
def applyupdates(repo, actions, wctx, mctx, actx, overwrite):
    """apply the merge action list to the working directory

    wctx is the working copy context
    mctx is the context to be merged into the working copy
    actx is the context of the common ancestor

    Return a tuple of counts (updated, merged, removed, unresolved) that
    describes how many files were affected by the update.
    """

    updated, merged, removed, unresolved = 0, 0, 0, 0
    ms = mergestate(repo)
    ms.reset(wctx.p1().node())
    moves = []
    actions.sort(key=actionkey)

    # prescan for merges
    for a in actions:
        f, m, args, msg = a
        repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
        if m == "m": # merge
            f2, fd, move = args
            if fd == '.hgsubstate': # merged internally
                continue
            repo.ui.debug("  preserving %s for resolve of %s\n" % (f, fd))
            fcl = wctx[f]
            fco = mctx[f2]
            if mctx == actx: # backwards, use working dir parent as ancestor
                if fcl.parents():
                    fca = fcl.p1()
                else:
                    fca = repo.filectx(f, fileid=nullrev)
            else:
                fca = fcl.ancestor(fco, actx)
            if not fca:
                fca = repo.filectx(f, fileid=nullrev)
            ms.add(fcl, fco, fca, fd)
            if f != fd and move:
                moves.append(f)

    audit = repo.wopener.audit

    # remove renamed files after safely stored
    for f in moves:
        if os.path.lexists(repo.wjoin(f)):
            repo.ui.debug("removing %s\n" % f)
            audit(f)
            util.unlinkpath(repo.wjoin(f))

    numupdates = len(actions)
    workeractions = [a for a in actions if a[1] in 'gr']
    updateactions = [a for a in workeractions if a[1] == 'g']
    updated = len(updateactions)
    removeactions = [a for a in workeractions if a[1] == 'r']
    removed = len(removeactions)
    actions = [a for a in actions if a[1] not in 'gr']

    hgsub = [a[1] for a in workeractions if a[0] == '.hgsubstate']
    if hgsub and hgsub[0] == 'r':
        subrepo.submerge(repo, wctx, mctx, wctx, overwrite)

    z = 0
    prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite),
                         removeactions)
    for i, item in prog:
        z += i
        repo.ui.progress(_('updating'), z, item=item, total=numupdates,
                         unit=_('files'))
    prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite),
                         updateactions)
    for i, item in prog:
        z += i
        repo.ui.progress(_('updating'), z, item=item, total=numupdates,
                         unit=_('files'))

    if hgsub and hgsub[0] == 'g':
        subrepo.submerge(repo, wctx, mctx, wctx, overwrite)

    _updating = _('updating')
    _files = _('files')
    progress = repo.ui.progress

    for i, a in enumerate(actions):
        f, m, args, msg = a
        progress(_updating, z + i + 1, item=f, total=numupdates, unit=_files)
        if m == "m": # merge
            f2, fd, move = args
            if fd == '.hgsubstate': # subrepo states need updating
                subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
                                 overwrite)
                continue
            audit(fd)
            r = ms.resolve(fd, wctx, mctx)
            if r is not None and r > 0:
                unresolved += 1
            else:
                if r is None:
                    updated += 1
                else:
                    merged += 1
        elif m == "d": # directory rename
            f2, fd, flags = args
            if f:
                repo.ui.note(_("moving %s to %s\n") % (f, fd))
                audit(f)
                repo.wwrite(fd, wctx.filectx(f).data(), flags)
                util.unlinkpath(repo.wjoin(f))
            if f2:
                repo.ui.note(_("getting %s to %s\n") % (f2, fd))
                repo.wwrite(fd, mctx.filectx(f2).data(), flags)
            updated += 1
        elif m == "dr": # divergent renames
            fl, = args
            repo.ui.warn(_("note: possible conflict - %s was renamed "
                           "multiple times to:\n") % f)
            for nf in fl:
                repo.ui.warn(" %s\n" % nf)
        elif m == "rd": # rename and delete
            fl, = args
            repo.ui.warn(_("note: possible conflict - %s was deleted "
                           "and renamed to:\n") % f)
            for nf in fl:
                repo.ui.warn(" %s\n" % nf)
        elif m == "e": # exec
            flags, = args
            audit(f)
            util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags)
            updated += 1
    ms.commit()
    progress(_updating, None, total=numupdates, unit=_files)

    return updated, merged, removed, unresolved
示例#10
0
def copy(ui, repo, pats, opts, rename=False):
    # called with the repo lock held
    #
    # hgsep => pathname that uses "/" to separate directories
    # ossep => pathname that uses os.sep to separate directories
    cwd = repo.getcwd()
    targets = {}
    after = opts.get("after")
    dryrun = opts.get("dry_run")
    wctx = repo[None]

    def walkpat(pat):
        srcs = []
        badstates = after and '?' or '?r'
        m = scmutil.match(repo[None], [pat], opts, globbed=True)
        for abs in repo.walk(m):
            state = repo.dirstate[abs]
            rel = m.rel(abs)
            exact = m.exact(abs)
            if state in badstates:
                if exact and state == '?':
                    ui.warn(_('%s: not copying - file is not managed\n') % rel)
                if exact and state == 'r':
                    ui.warn(
                        _('%s: not copying - file has been marked for'
                          ' remove\n') % rel)
                continue
            # abs: hgsep
            # rel: ossep
            srcs.append((abs, rel, exact))
        return srcs

    # abssrc: hgsep
    # relsrc: ossep
    # otarget: ossep
    def copyfile(abssrc, relsrc, otarget, exact):
        abstarget = scmutil.canonpath(repo.root, cwd, otarget)
        reltarget = repo.pathto(abstarget, cwd)
        target = repo.wjoin(abstarget)
        src = repo.wjoin(abssrc)
        state = repo.dirstate[abstarget]

        scmutil.checkportable(ui, abstarget)

        # check for collisions
        prevsrc = targets.get(abstarget)
        if prevsrc is not None:
            ui.warn(
                _('%s: not overwriting - %s collides with %s\n') %
                (reltarget, repo.pathto(abssrc, cwd), repo.pathto(
                    prevsrc, cwd)))
            return

        # check for overwrites
        exists = os.path.lexists(target)
        if not after and exists or after and state in 'mn':
            if not opts['force']:
                ui.warn(_('%s: not overwriting - file exists\n') % reltarget)
                return

        if after:
            if not exists:
                if rename:
                    ui.warn(
                        _('%s: not recording move - %s does not exist\n') %
                        (relsrc, reltarget))
                else:
                    ui.warn(
                        _('%s: not recording copy - %s does not exist\n') %
                        (relsrc, reltarget))
                return
        elif not dryrun:
            try:
                if exists:
                    os.unlink(target)
                targetdir = os.path.dirname(target) or '.'
                if not os.path.isdir(targetdir):
                    os.makedirs(targetdir)
                util.copyfile(src, target)
                srcexists = True
            except IOError, inst:
                if inst.errno == errno.ENOENT:
                    ui.warn(_('%s: deleted in working copy\n') % relsrc)
                    srcexists = False
                else:
                    ui.warn(
                        _('%s: cannot copy - %s\n') % (relsrc, inst.strerror))
                    return True  # report a failure

        if ui.verbose or not exact:
            if rename:
                ui.status(_('moving %s to %s\n') % (relsrc, reltarget))
            else:
                ui.status(_('copying %s to %s\n') % (relsrc, reltarget))

        targets[abstarget] = abssrc

        # fix up dirstate
        scmutil.dirstatecopy(ui,
                             repo,
                             wctx,
                             abssrc,
                             abstarget,
                             dryrun=dryrun,
                             cwd=cwd)
        if rename and not dryrun:
            if not after and srcexists:
                util.unlinkpath(repo.wjoin(abssrc))
            wctx.forget([abssrc])
 def unlinkpath(self, path=None, ignoremissing=False):
     return util.unlinkpath(self.join(path), ignoremissing)
示例#12
0
文件: merge.py 项目: RayFerr000/PLTL
def applyupdates(repo, actions, wctx, mctx, overwrite, labels=None):
    """apply the merge action list to the working directory

    wctx is the working copy context
    mctx is the context to be merged into the working copy

    Return a tuple of counts (updated, merged, removed, unresolved) that
    describes how many files were affected by the update.
    """

    updated, merged, removed, unresolved = 0, 0, 0, 0
    ms = mergestate(repo)
    ms.reset(wctx.p1().node(), mctx.node())
    moves = []
    for m, l in actions.items():
        l.sort()

    # prescan for merges
    for f, args, msg in actions['m']:
        f1, f2, fa, move, anc = args
        if f == '.hgsubstate': # merged internally
            continue
        repo.ui.debug(" preserving %s for resolve of %s\n" % (f1, f))
        fcl = wctx[f1]
        fco = mctx[f2]
        actx = repo[anc]
        if fa in actx:
            fca = actx[fa]
        else:
            fca = repo.filectx(f1, fileid=nullrev)
        ms.add(fcl, fco, fca, f)
        if f1 != f and move:
            moves.append(f1)

    audit = repo.wvfs.audit
    _updating = _('updating')
    _files = _('files')
    progress = repo.ui.progress

    # remove renamed files after safely stored
    for f in moves:
        if os.path.lexists(repo.wjoin(f)):
            repo.ui.debug("removing %s\n" % f)
            audit(f)
            util.unlinkpath(repo.wjoin(f))

    numupdates = sum(len(l) for m, l in actions.items() if m != 'k')

    def dirtysubstate():
        # mark '.hgsubstate' as possibly dirty forcibly, because
        # modified '.hgsubstate' is misunderstood as clean,
        # when both st_size/st_mtime of '.hgsubstate' aren't changed,
        # even if "submerge" fails and '.hgsubstate' is inconsistent
        repo.dirstate.normallookup('.hgsubstate')

    if [a for a in actions['r'] if a[0] == '.hgsubstate']:
        dirtysubstate()
        subrepo.submerge(repo, wctx, mctx, wctx, overwrite)

    # remove in parallel (must come first)
    z = 0
    prog = worker.worker(repo.ui, 0.001, batchremove, (repo,), actions['r'])
    for i, item in prog:
        z += i
        progress(_updating, z, item=item, total=numupdates, unit=_files)
    removed = len(actions['r'])

    # get in parallel
    prog = worker.worker(repo.ui, 0.001, batchget, (repo, mctx), actions['g'])
    for i, item in prog:
        z += i
        progress(_updating, z, item=item, total=numupdates, unit=_files)
    updated = len(actions['g'])

    if [a for a in actions['g'] if a[0] == '.hgsubstate']:
        dirtysubstate()
        subrepo.submerge(repo, wctx, mctx, wctx, overwrite)

    # forget (manifest only, just log it) (must come first)
    for f, args, msg in actions['f']:
        repo.ui.debug(" %s: %s -> f\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)

    # re-add (manifest only, just log it)
    for f, args, msg in actions['a']:
        repo.ui.debug(" %s: %s -> a\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)

    # keep (noop, just log it)
    for f, args, msg in actions['k']:
        repo.ui.debug(" %s: %s -> k\n" % (f, msg))
        # no progress

    # merge
    for f, args, msg in actions['m']:
        repo.ui.debug(" %s: %s -> m\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        if f == '.hgsubstate': # subrepo states need updating
            dirtysubstate()
            subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
                             overwrite)
            continue
        audit(f)
        r = ms.resolve(f, wctx, labels=labels)
        if r is not None and r > 0:
            unresolved += 1
        else:
            if r is None:
                updated += 1
            else:
                merged += 1

    # directory rename, move local
    for f, args, msg in actions['dm']:
        repo.ui.debug(" %s: %s -> dm\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        f0, flags = args
        repo.ui.note(_("moving %s to %s\n") % (f0, f))
        audit(f)
        repo.wwrite(f, wctx.filectx(f0).data(), flags)
        util.unlinkpath(repo.wjoin(f0))
        updated += 1

    # local directory rename, get
    for f, args, msg in actions['dg']:
        repo.ui.debug(" %s: %s -> dg\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        f0, flags = args
        repo.ui.note(_("getting %s to %s\n") % (f0, f))
        repo.wwrite(f, mctx.filectx(f0).data(), flags)
        updated += 1

    # exec
    for f, args, msg in actions['e']:
        repo.ui.debug(" %s: %s -> e\n" % (f, msg))
        z += 1
        progress(_updating, z, item=f, total=numupdates, unit=_files)
        flags, = args
        audit(f)
        util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags)
        updated += 1

    ms.commit()
    progress(_updating, None, total=numupdates, unit=_files)

    return updated, merged, removed, unresolved
示例#13
0
def applyupdates(repo, action, wctx, mctx, actx, overwrite):
    """apply the merge action list to the working directory

    wctx is the working copy context
    mctx is the context to be merged into the working copy
    actx is the context of the common ancestor

    Return a tuple of counts (updated, merged, removed, unresolved) that
    describes how many files were affected by the update.
    """

    updated, merged, removed, unresolved = 0, 0, 0, 0
    ms = mergestate(repo)
    ms.reset(wctx.p1().node())
    moves = []
    action.sort(key=actionkey)

    # prescan for merges
    for a in action:
        f, m = a[:2]
        if m == "m":  # merge
            f2, fd, flags, move = a[2:]
            if f == ".hgsubstate":  # merged internally
                continue
            repo.ui.debug("preserving %s for resolve of %s\n" % (f, fd))
            fcl = wctx[f]
            fco = mctx[f2]
            if mctx == actx:  # backwards, use working dir parent as ancestor
                if fcl.parents():
                    fca = fcl.p1()
                else:
                    fca = repo.filectx(f, fileid=nullrev)
            else:
                fca = fcl.ancestor(fco, actx)
            if not fca:
                fca = repo.filectx(f, fileid=nullrev)
            ms.add(fcl, fco, fca, fd, flags)
            if f != fd and move:
                moves.append(f)

    audit = scmutil.pathauditor(repo.root)

    # remove renamed files after safely stored
    for f in moves:
        if os.path.lexists(repo.wjoin(f)):
            repo.ui.debug("removing %s\n" % f)
            audit(f)
            os.unlink(repo.wjoin(f))

    numupdates = len(action)
    for i, a in enumerate(action):
        f, m = a[:2]
        repo.ui.progress(_("updating"), i + 1, item=f, total=numupdates, unit=_("files"))
        if f and f[0] == "/":
            continue
        if m == "r":  # remove
            repo.ui.note(_("removing %s\n") % f)
            audit(f)
            if f == ".hgsubstate":  # subrepo states need updating
                subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
            try:
                util.unlinkpath(repo.wjoin(f))
            except OSError, inst:
                if inst.errno != errno.ENOENT:
                    repo.ui.warn(_("update failed to remove %s: %s!\n") % (f, inst.strerror))
            removed += 1
        elif m == "m":  # merge
            if f == ".hgsubstate":  # subrepo states need updating
                subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), overwrite)
                continue
            f2, fd, flags, move = a[2:]
            repo.wopener.audit(fd)
            r = ms.resolve(fd, wctx, mctx)
            if r is not None and r > 0:
                unresolved += 1
            else:
                if r is None:
                    updated += 1
                else:
                    merged += 1
            if move and repo.dirstate.normalize(fd) != f and os.path.lexists(repo.wjoin(f)):
                repo.ui.debug("removing %s\n" % f)
                audit(f)
                os.unlink(repo.wjoin(f))
示例#14
0
         flags = a[2]
         repo.ui.note(_("getting %s\n") % f)
         t = mctx.filectx(f).data()
         repo.wwrite(f, t, flags)
         t = None
         updated += 1
         if f == ".hgsubstate":  # subrepo states need updating
             subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
     elif m == "d":  # directory rename
         f2, fd, flags = a[2:]
         if f:
             repo.ui.note(_("moving %s to %s\n") % (f, fd))
             audit(f)
             t = wctx.filectx(f).data()
             repo.wwrite(fd, t, flags)
             util.unlinkpath(repo.wjoin(f))
         if f2:
             repo.ui.note(_("getting %s to %s\n") % (f2, fd))
             t = mctx.filectx(f2).data()
             repo.wwrite(fd, t, flags)
         updated += 1
     elif m == "dr":  # divergent renames
         fl = a[2]
         repo.ui.warn(_("note: possible conflict - %s was renamed " "multiple times to:\n") % f)
         for nf in fl:
             repo.ui.warn(" %s\n" % nf)
     elif m == "e":  # exec
         flags = a[2]
         repo.wopener.audit(f)
         util.setflags(repo.wjoin(f), "l" in flags, "x" in flags)
 ms.commit()
示例#15
0
def applyupdates(repo, actions, wctx, mctx, actx, overwrite):
    """apply the merge action list to the working directory

    wctx is the working copy context
    mctx is the context to be merged into the working copy
    actx is the context of the common ancestor

    Return a tuple of counts (updated, merged, removed, unresolved) that
    describes how many files were affected by the update.
    """

    updated, merged, removed, unresolved = 0, 0, 0, 0
    ms = mergestate(repo)
    ms.reset(wctx.p1().node())
    moves = []
    actions.sort(key=actionkey)

    # prescan for merges
    for a in actions:
        f, m, args, msg = a
        repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
        if m == "m":  # merge
            f2, fd, move = args
            if fd == '.hgsubstate':  # merged internally
                continue
            repo.ui.debug("  preserving %s for resolve of %s\n" % (f, fd))
            fcl = wctx[f]
            fco = mctx[f2]
            if mctx == actx:  # backwards, use working dir parent as ancestor
                if fcl.parents():
                    fca = fcl.p1()
                else:
                    fca = repo.filectx(f, fileid=nullrev)
            else:
                fca = fcl.ancestor(fco, actx)
            if not fca:
                fca = repo.filectx(f, fileid=nullrev)
            ms.add(fcl, fco, fca, fd)
            if f != fd and move:
                moves.append(f)

    audit = repo.wopener.audit

    # remove renamed files after safely stored
    for f in moves:
        if os.path.lexists(repo.wjoin(f)):
            repo.ui.debug("removing %s\n" % f)
            audit(f)
            util.unlinkpath(repo.wjoin(f))

    numupdates = len(actions)
    workeractions = [a for a in actions if a[1] in 'gr']
    updateactions = [a for a in workeractions if a[1] == 'g']
    updated = len(updateactions)
    removeactions = [a for a in workeractions if a[1] == 'r']
    removed = len(removeactions)
    actions = [a for a in actions if a[1] not in 'gr']

    hgsub = [a[1] for a in workeractions if a[0] == '.hgsubstate']
    if hgsub and hgsub[0] == 'r':
        subrepo.submerge(repo, wctx, mctx, wctx, overwrite)

    z = 0
    prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite),
                         removeactions)
    for i, item in prog:
        z += i
        repo.ui.progress(_('updating'),
                         z,
                         item=item,
                         total=numupdates,
                         unit=_('files'))
    prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite),
                         updateactions)
    for i, item in prog:
        z += i
        repo.ui.progress(_('updating'),
                         z,
                         item=item,
                         total=numupdates,
                         unit=_('files'))

    if hgsub and hgsub[0] == 'g':
        subrepo.submerge(repo, wctx, mctx, wctx, overwrite)

    _updating = _('updating')
    _files = _('files')
    progress = repo.ui.progress

    for i, a in enumerate(actions):
        f, m, args, msg = a
        progress(_updating, z + i + 1, item=f, total=numupdates, unit=_files)
        if m == "m":  # merge
            f2, fd, move = args
            if fd == '.hgsubstate':  # subrepo states need updating
                subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
                                 overwrite)
                continue
            audit(fd)
            r = ms.resolve(fd, wctx, mctx)
            if r is not None and r > 0:
                unresolved += 1
            else:
                if r is None:
                    updated += 1
                else:
                    merged += 1
        elif m == "d":  # directory rename
            f2, fd, flags = args
            if f:
                repo.ui.note(_("moving %s to %s\n") % (f, fd))
                audit(f)
                repo.wwrite(fd, wctx.filectx(f).data(), flags)
                util.unlinkpath(repo.wjoin(f))
            if f2:
                repo.ui.note(_("getting %s to %s\n") % (f2, fd))
                repo.wwrite(fd, mctx.filectx(f2).data(), flags)
            updated += 1
        elif m == "dr":  # divergent renames
            fl, = args
            repo.ui.warn(
                _("note: possible conflict - %s was renamed "
                  "multiple times to:\n") % f)
            for nf in fl:
                repo.ui.warn(" %s\n" % nf)
        elif m == "rd":  # rename and delete
            fl, = args
            repo.ui.warn(
                _("note: possible conflict - %s was deleted "
                  "and renamed to:\n") % f)
            for nf in fl:
                repo.ui.warn(" %s\n" % nf)
        elif m == "e":  # exec
            flags, = args
            audit(f)
            util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags)
            updated += 1
    ms.commit()
    progress(_updating, None, total=numupdates, unit=_files)

    return updated, merged, removed, unresolved
示例#16
0
文件: cmdutil.py 项目: mortonfox/cr48
def copy(ui, repo, pats, opts, rename=False):
    # called with the repo lock held
    #
    # hgsep => pathname that uses "/" to separate directories
    # ossep => pathname that uses os.sep to separate directories
    cwd = repo.getcwd()
    targets = {}
    after = opts.get("after")
    dryrun = opts.get("dry_run")
    wctx = repo[None]

    def walkpat(pat):
        srcs = []
        badstates = after and '?' or '?r'
        m = scmutil.match(repo[None], [pat], opts, globbed=True)
        for abs in repo.walk(m):
            state = repo.dirstate[abs]
            rel = m.rel(abs)
            exact = m.exact(abs)
            if state in badstates:
                if exact and state == '?':
                    ui.warn(_('%s: not copying - file is not managed\n') % rel)
                if exact and state == 'r':
                    ui.warn(_('%s: not copying - file has been marked for'
                              ' remove\n') % rel)
                continue
            # abs: hgsep
            # rel: ossep
            srcs.append((abs, rel, exact))
        return srcs

    # abssrc: hgsep
    # relsrc: ossep
    # otarget: ossep
    def copyfile(abssrc, relsrc, otarget, exact):
        abstarget = scmutil.canonpath(repo.root, cwd, otarget)
        reltarget = repo.pathto(abstarget, cwd)
        target = repo.wjoin(abstarget)
        src = repo.wjoin(abssrc)
        state = repo.dirstate[abstarget]

        scmutil.checkportable(ui, abstarget)

        # check for collisions
        prevsrc = targets.get(abstarget)
        if prevsrc is not None:
            ui.warn(_('%s: not overwriting - %s collides with %s\n') %
                    (reltarget, repo.pathto(abssrc, cwd),
                     repo.pathto(prevsrc, cwd)))
            return

        # check for overwrites
        exists = os.path.lexists(target)
        if not after and exists or after and state in 'mn':
            if not opts['force']:
                ui.warn(_('%s: not overwriting - file exists\n') %
                        reltarget)
                return

        if after:
            if not exists:
                if rename:
                    ui.warn(_('%s: not recording move - %s does not exist\n') %
                            (relsrc, reltarget))
                else:
                    ui.warn(_('%s: not recording copy - %s does not exist\n') %
                            (relsrc, reltarget))
                return
        elif not dryrun:
            try:
                if exists:
                    os.unlink(target)
                targetdir = os.path.dirname(target) or '.'
                if not os.path.isdir(targetdir):
                    os.makedirs(targetdir)
                util.copyfile(src, target)
                srcexists = True
            except IOError, inst:
                if inst.errno == errno.ENOENT:
                    ui.warn(_('%s: deleted in working copy\n') % relsrc)
                    srcexists = False
                else:
                    ui.warn(_('%s: cannot copy - %s\n') %
                            (relsrc, inst.strerror))
                    return True # report a failure

        if ui.verbose or not exact:
            if rename:
                ui.status(_('moving %s to %s\n') % (relsrc, reltarget))
            else:
                ui.status(_('copying %s to %s\n') % (relsrc, reltarget))

        targets[abstarget] = abssrc

        # fix up dirstate
        scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
                             dryrun=dryrun, cwd=cwd)
        if rename and not dryrun:
            if not after and srcexists:
                util.unlinkpath(repo.wjoin(abssrc))
            wctx.forget([abssrc])