Ejemplo n.º 1
0
def mergefiles(ui, repo, wctx, shelvectx):
    """updates to wctx and merges the changes from shelvectx into the
    dirstate."""
    with ui.configoverride({("ui", "quiet"): True}):
        hg.update(repo, wctx.node())
        files = []
        files.extend(shelvectx.files())
        files.extend(shelvectx.p1().files())

        # revert will overwrite unknown files, so move them out of the way
        for file in repo.status(unknown=True).unknown:
            if file in files:
                util.rename(file, scmutil.origpath(ui, repo, file))
        ui.pushbuffer(True)
        cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(),
                       *pathtofiles(repo, files), **{"no_backup": True})
        ui.popbuffer()
Ejemplo n.º 2
0
def _summarize(repo, workingfilectx, otherctx, basectx):
    origfile = (
        None
        if workingfilectx.isabsent()
        else scmutil.origpath(repo.ui, repo, repo.wjoin(workingfilectx.path()))
    )

    def flags(context):
        if isinstance(context, absentfilectx):
            return {
                "contents": None,
                "exists": False,
                "isexec": None,
                "issymlink": None,
            }
        return {
            "contents": pycompat.decodeutf8(context.data()),
            "exists": True,
            "isexec": context.isexec(),
            "issymlink": context.islink(),
        }

    output = flags(workingfilectx)

    filestat = util.filestat.frompath(origfile) if origfile is not None else None
    if origfile and filestat.stat:
        # Since you can start a merge with a dirty working copy (either via
        # `up` or `merge -f`), "local" must reflect that, not the underlying
        # changeset. Those contents are available in the .orig version, so we
        # look there and mock up the schema to look like the other contexts.
        #
        # Test cases affected in test-merge-conflict-cornercases.t: #0
        local = {
            "contents": pycompat.decodeutf8(util.readfile(origfile)),
            "exists": True,
            "isexec": util.isexec(origfile),
            "issymlink": util.statislink(filestat.stat),
        }
    else:
        # No backup file. This happens whenever the merge was esoteric enough
        # that we didn't launch a merge tool*, and instead prompted the user to
        # "use (c)hanged version, (d)elete, or leave (u)nresolved".
        #
        # The only way to exit that prompt with a conflict is to choose "u",
        # which leaves the local version in the working copy (with all its
        # pre-merge properties including any local changes), so we can reuse
        # that.
        #
        # Affected test cases: #0b, #1, #6, #11, and #12.
        #
        # Another alternative might be to use repo['.'][path] but that wouldn't
        # have any dirty pre-merge changes.
        #
        # *If we had, we'd've we would've overwritten the working copy, made a
        # backup and hit the above case.
        #
        # Copy, so the addition of the `path` key below does not affect both
        # versions.
        local = copy.copy(output)

    output["path"] = repo.wjoin(workingfilectx.path())

    return {
        "base": flags(basectx),
        "local": local,
        "other": flags(otherctx),
        "output": output,
        "path": workingfilectx.path(),
    }