Example #1
0
def snapshotcheckout(ui, repo, *args, **opts):
    """checks out the working copy to the snapshot state, given its revision id
    """
    cctx = getsnapshotctx(ui, repo, args)
    clean = opts.get("clean")
    # This is a temporary safety check that WC is clean.
    if sum(map(len, repo.status(unknown=True))) != 0 and not clean:
        raise error.Abort(
            _("You must have a clean working copy to checkout on a snapshot. "
              "Use --clean to bypass that.\n"))
    ui.status(_("will checkout on %s\n") % cctx.hex())
    with repo.wlock():
        parents = [p.node() for p in cctx.parents()]
        # First we check out on the 1st parent of the snapshot state
        hg.update(repo.unfiltered(), parents[0], quietempty=True)
        # Then we update snapshot files in the working copy
        # Here the dirstate is not updated because of the matcher
        matcher = scmutil.matchfiles(repo, cctx.files(), opts)
        mergemod.update(repo.unfiltered(),
                        cctx.hex(),
                        False,
                        False,
                        matcher=matcher)
        # Finally, we mark the modified files in the dirstate
        scmutil.addremove(repo, matcher, "", opts)
        # Tie the state to the 2nd parent if needed
        if len(parents) == 2:
            with repo.dirstate.parentchange():
                repo.setparents(*parents)
    snapshotmetadataid = cctx.extra().get("snapshotmetadataid")
    if snapshotmetadataid:
        snapmetadata = snapshotmetadata.getfromlocalstorage(
            repo, snapshotmetadataid)
        checkouttosnapshotmetadata(ui, repo, snapmetadata, clean)
    ui.status(_("checkout complete\n"))
Example #2
0
def _amend(orig, ui, repo, old, extra, pats, opts):
    # Only wrap if not disabled and repo is instance of
    # localrepo.localrepository
    if _disabled[0] or not isinstance(repo, localrepo.localrepository):
        return orig(ui, repo, old, extra, pats, opts)

    with repo.wlock(), repo.lock(), repo.transaction("dirsyncamend"):
        wctx = repo[None]
        matcher = scmutil.match(wctx, pats, opts)
        if opts.get("addremove") and scmutil.addremove(repo, matcher, "",
                                                       opts):
            raise error.Abort(
                _("failed to mark all new/missing files as added/removed"))

        mirroredfiles = _updateworkingcopy(repo, matcher)
        if mirroredfiles and not matcher.always():
            # Ensure that all the files to be amended (original + synced) are
            # under consideration during the amend operation. We do so by
            # setting the value against 'include' key in opts as the only source
            # of truth.
            pats = ()
            opts["include"] = [f for f in wctx.files() if matcher(f)
                               ] + list(mirroredfiles)

        return orig(ui, repo, old, extra, pats, opts)
Example #3
0
File: perf.py Project: leszfb/eden
def perfaddremove(ui, repo, **opts):
    timer, fm = gettimer(ui, opts)
    try:
        oldquiet = repo.ui.quiet
        repo.ui.quiet = True
        matcher = scmutil.match(repo[None])
        timer(lambda: scmutil.addremove(repo, matcher, "", dry_run=True))
    finally:
        repo.ui.quiet = oldquiet
        fm.end()