contrib/simplemerge
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 14 Apr 2020 03:16:23 +0200
changeset 44791 b81486b609a3
parent 43659 99e231afc29c
child 45055 4c1b4805db57
permissions -rw-r--r--
nodemap: gate the feature behind a new requirement Now that the feature is working smoothly, a question was still open, should we gate the feature behind a new requirement or just treat it as a cache to be warmed by those who can and ignored by other. The advantage of using the cache approach is a transparent upgrade/downgrade story, making the feature easier to move to. However having out of date cache can come with a significant performance hit for process who expect an up to date cache but found none. In this case the file needs to be stored under `.hg/cache`. The "requirement" approach guarantee that the persistent nodemap is up to date. However, it comes with a less flexible activation story since an explicite upgrade is required. In this case the file can be stored in `.hg/store`. This wiki page is relevant to this questions: https://www.mercurial-scm.org/wiki/ComputedIndexPlan So which one should we take? Another element came into plan, the persistent nodemap use the `add` method of the transaction, it is used to keep track of a file content before a transaction in case we need to rollback it back. It turns out that the `transaction.add` API does not support file stored anywhere than `.hg/store`. Making it support file stored elsewhere is possible, require a change in on disk transaction format. Updating on disk file requires… introducing a new requirements. As a result, we pick the second option "gating the persistent nodemap behind a new requirements". Differential Revision: https://phab.mercurial-scm.org/D8417

#!/usr/bin/env python
from __future__ import absolute_import

import getopt
import sys

import hgdemandimport

hgdemandimport.enable()

from mercurial.i18n import _
from mercurial import (
    context,
    error,
    fancyopts,
    pycompat,
    simplemerge,
    ui as uimod,
)
from mercurial.utils import procutil, stringutil

options = [
    (b'L', b'label', [], _(b'labels to use on conflict markers')),
    (b'a', b'text', None, _(b'treat all files as text')),
    (b'p', b'print', None, _(b'print results instead of overwriting LOCAL')),
    (b'', b'no-minimal', None, _(b'no effect (DEPRECATED)')),
    (b'h', b'help', None, _(b'display help and exit')),
    (b'q', b'quiet', None, _(b'suppress output')),
]

usage = _(
    b'''simplemerge [OPTS] LOCAL BASE OTHER

    Simple three-way file merge utility with a minimal feature set.

    Apply to LOCAL the changes necessary to go from BASE to OTHER.

    By default, LOCAL is overwritten with the results of this operation.
'''
)


class ParseError(Exception):
    """Exception raised on errors in parsing the command line."""


def showhelp():
    pycompat.stdout.write(usage)
    pycompat.stdout.write(b'\noptions:\n')

    out_opts = []
    for shortopt, longopt, default, desc in options:
        out_opts.append(
            (
                b'%2s%s'
                % (
                    shortopt and b'-%s' % shortopt,
                    longopt and b' --%s' % longopt,
                ),
                b'%s' % desc,
            )
        )
    opts_len = max([len(opt[0]) for opt in out_opts])
    for first, second in out_opts:
        pycompat.stdout.write(b' %-*s  %s\n' % (opts_len, first, second))


try:
    for fp in (sys.stdin, pycompat.stdout, sys.stderr):
        procutil.setbinary(fp)

    opts = {}
    try:
        bargv = [a.encode('utf8') for a in sys.argv[1:]]
        args = fancyopts.fancyopts(bargv, options, opts)
    except getopt.GetoptError as e:
        raise ParseError(e)
    if opts[b'help']:
        showhelp()
        sys.exit(0)
    if len(args) != 3:
        raise ParseError(_(b'wrong number of arguments').decode('utf8'))
    local, base, other = args
    sys.exit(
        simplemerge.simplemerge(
            uimod.ui.load(),
            context.arbitraryfilectx(local),
            context.arbitraryfilectx(base),
            context.arbitraryfilectx(other),
            **pycompat.strkwargs(opts)
        )
    )
except ParseError as e:
    e = stringutil.forcebytestr(e)
    pycompat.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e))
    showhelp()
    sys.exit(1)
except error.Abort as e:
    pycompat.stderr.write(b"abort: %s\n" % e)
    sys.exit(255)
except KeyboardInterrupt:
    sys.exit(255)