contrib/simplemerge
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 13 Nov 2017 21:54:46 -0800
changeset 35119 764e3ad1cf54
parent 34051 d2fc88426d21
child 37120 a8a902d7176e
permissions -rwxr-xr-x
bundle2: inline struct operations Before, we were calling struct.unpack() (via an alias) on every loop iteration. I'm not sure what Python does under the hood, but it would have to look at the struct format and determine what to do. This commit establishes a struct.Struct instance and reuses it for struct reading. We can see the impact from running `hg perfbundleread` on a Firefox bundle: ! read(8k) ! wall 0.679730 comb 0.680000 user 0.140000 sys 0.540000 (best of 15) ! read(16k) ! wall 0.577228 comb 0.570000 user 0.080000 sys 0.490000 (best of 17) ! read(32k) ! wall 0.516060 comb 0.520000 user 0.040000 sys 0.480000 (best of 20) ! read(128k) ! wall 0.496378 comb 0.490000 user 0.010000 sys 0.480000 (best of 20) ! bundle2 iterparts() ! wall 3.056811 comb 3.050000 user 2.340000 sys 0.710000 (best of 4) ! wall 2.992605 comb 2.990000 user 2.260000 sys 0.730000 (best of 4) ! bundle2 iterparts() seekable ! wall 4.007676 comb 4.000000 user 3.170000 sys 0.830000 (best of 3) ! wall 3.863810 comb 3.860000 user 3.000000 sys 0.860000 (best of 3) ! bundle2 part seek() ! wall 6.267110 comb 6.250000 user 3.480000 sys 2.770000 (best of 3) ! wall 6.213387 comb 6.200000 user 3.350000 sys 2.850000 (best of 3) ! bundle2 part read(8k) ! wall 3.404164 comb 3.400000 user 2.650000 sys 0.750000 (best of 3) ! wall 3.241099 comb 3.250000 user 2.560000 sys 0.690000 (best of 3) ! bundle2 part read(16k) ! wall 3.197972 comb 3.200000 user 2.490000 sys 0.710000 (best of 4) ! wall 3.003930 comb 3.000000 user 2.270000 sys 0.730000 (best of 4) ! bundle2 part read(32k) ! wall 3.060557 comb 3.060000 user 2.340000 sys 0.720000 (best of 4) ! wall 2.904695 comb 2.900000 user 2.160000 sys 0.740000 (best of 4) ! bundle2 part read(128k) ! wall 2.952209 comb 2.950000 user 2.230000 sys 0.720000 (best of 4) ! wall 2.776140 comb 2.780000 user 2.070000 sys 0.710000 (best of 4) Profiling now says most remaining time is spent in util.chunkbuffer. I already heavily optimized that data structure several releases ago. So we'll likely get little more performance out of bundle2 reading while still retaining util.chunkbuffer(). Differential Revision: https://phab.mercurial-scm.org/D1393
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4363
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
     1
#!/usr/bin/env python
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     2
from __future__ import absolute_import
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     3
30576
541949a10a68 fancyopts: switch from fancyopts.getopt.* to getopt.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30559
diff changeset
     4
import getopt
19378
9de689d20230 cleanup: drop unused variables and an unused import
Simon Heimberg <simohe@besonet.ch>
parents: 19022
diff changeset
     5
import sys
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     6
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     7
import hgdemandimport
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     8
hgdemandimport.enable()
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     9
4363
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
    10
from mercurial.i18n import _
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    11
from mercurial import (
34051
d2fc88426d21 context: add arbitraryfilectx, which can represent files outside the workdir
Phil Cohen <phillco@fb.com>
parents: 34050
diff changeset
    12
    context,
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    13
    error,
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    14
    fancyopts,
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    15
    simplemerge,
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    16
    ui as uimod,
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    17
    util,
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    18
)
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    19
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    20
options = [('L', 'label', [], _('labels to use on conflict markers')),
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    21
           ('a', 'text', None, _('treat all files as text')),
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    22
           ('p', 'print', None,
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    23
            _('print results instead of overwriting LOCAL')),
22023
f18830651811 simplemerge: burn "minimal" feature to the ground
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 19378
diff changeset
    24
           ('', 'no-minimal', None, _('no effect (DEPRECATED)')),
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    25
           ('h', 'help', None, _('display help and exit')),
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    26
           ('q', 'quiet', None, _('suppress output'))]
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    27
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    28
usage = _('''simplemerge [OPTS] LOCAL BASE OTHER
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    29
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    30
    Simple three-way file merge utility with a minimal feature set.
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
    31
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    32
    Apply to LOCAL the changes necessary to go from BASE to OTHER.
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
    33
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    34
    By default, LOCAL is overwritten with the results of this operation.
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    35
''')
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    36
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    37
class ParseError(Exception):
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    38
    """Exception raised on errors in parsing the command line."""
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    39
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    40
def showhelp():
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    41
    sys.stdout.write(usage)
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    42
    sys.stdout.write('\noptions:\n')
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    43
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    44
    out_opts = []
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    45
    for shortopt, longopt, default, desc in options:
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    46
        out_opts.append(('%2s%s' % (shortopt and '-%s' % shortopt,
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    47
                                    longopt and ' --%s' % longopt),
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    48
                         '%s' % desc))
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    49
    opts_len = max([len(opt[0]) for opt in out_opts])
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    50
    for first, second in out_opts:
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    51
        sys.stdout.write(' %-*s  %s\n' % (opts_len, first, second))
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    52
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    53
try:
7080
a6477aa893b8 tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents: 6002
diff changeset
    54
    for fp in (sys.stdin, sys.stdout, sys.stderr):
14233
659f34b833b9 rename util.set_binary to setbinary
Adrian Buehlmann <adrian@cadifra.com>
parents: 8269
diff changeset
    55
        util.setbinary(fp)
19022
cba222f01056 tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents: 14233
diff changeset
    56
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    57
    opts = {}
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    58
    try:
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    59
        args = fancyopts.fancyopts(sys.argv[1:], options, opts)
30576
541949a10a68 fancyopts: switch from fancyopts.getopt.* to getopt.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30559
diff changeset
    60
    except getopt.GetoptError as e:
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    61
        raise ParseError(e)
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    62
    if opts['help']:
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    63
        showhelp()
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    64
        sys.exit(0)
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    65
    if len(args) != 3:
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    66
            raise ParseError(_('wrong number of arguments'))
33903
ed6f64173121 contrib: make simplemerge script pass context-like objects
Phil Cohen <phillco@fb.com>
parents: 33895
diff changeset
    67
    local, base, other = args
ed6f64173121 contrib: make simplemerge script pass context-like objects
Phil Cohen <phillco@fb.com>
parents: 33895
diff changeset
    68
    sys.exit(simplemerge.simplemerge(uimod.ui.load(),
34051
d2fc88426d21 context: add arbitraryfilectx, which can represent files outside the workdir
Phil Cohen <phillco@fb.com>
parents: 34050
diff changeset
    69
                                     context.arbitraryfilectx(local),
d2fc88426d21 context: add arbitraryfilectx, which can represent files outside the workdir
Phil Cohen <phillco@fb.com>
parents: 34050
diff changeset
    70
                                     context.arbitraryfilectx(base),
d2fc88426d21 context: add arbitraryfilectx, which can represent files outside the workdir
Phil Cohen <phillco@fb.com>
parents: 34050
diff changeset
    71
                                     context.arbitraryfilectx(other),
33903
ed6f64173121 contrib: make simplemerge script pass context-like objects
Phil Cohen <phillco@fb.com>
parents: 33895
diff changeset
    72
                                     **opts))
28047
863075fd4cd0 misc: use modern exception syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
    73
except ParseError as e:
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    74
    sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    75
    showhelp()
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    76
    sys.exit(1)
28047
863075fd4cd0 misc: use modern exception syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
    77
except error.Abort as e:
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    78
    sys.stderr.write("abort: %s\n" % e)
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    79
    sys.exit(255)
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    80
except KeyboardInterrupt:
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    81
    sys.exit(255)