mercurial/scmposix.py
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
Mon, 10 Apr 2017 16:55:16 +0200
changeset 31972 ba7e4a4a7f32
parent 31348 7c09b071318a
child 32078 bf5e13e38390
permissions -rw-r--r--
obsolescence: add test case D-4 for obsolescence markers exchange About 3 years ago, in August 2014, the logic to select what markers to select on push was ported from the evolve extension to Mercurial core. However, for some unclear reasons, the tests for that logic were not ported alongside. I realised it a couple of weeks ago while working on another push related issue. I've made a clean up pass on the tests and they are now ready to integrate the core test suite. This series of changesets do not change any logic. I just adds test for logic that has been around for about 10 versions of Mercurial. They are a patch for each test case. It makes it easier to review and postpone one with documentation issues without rejecting the wholes series. This patch introduce case D-4: unknown changeset in between known on Each test case comes it in own test file. It help parallelism and does not introduce a significant overhead from having a single unified giant test file. Here are timing to support this claim. # Multiple test files version: # run-tests.py --local -j 1 test-exchange-*.t 53.40s user 6.82s system 85% cpu 1:10.76 total 52.79s user 6.97s system 85% cpu 1:09.97 total 52.94s user 6.82s system 85% cpu 1:09.69 total # Single test file version: # run-tests.py --local -j 1 test-exchange-obsmarkers.t 52.97s user 6.85s system 85% cpu 1:10.10 total 52.64s user 6.79s system 85% cpu 1:09.63 total 53.70s user 7.00s system 85% cpu 1:11.17 total
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27483
39087ee88835 scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22583
diff changeset
     1
from __future__ import absolute_import
39087ee88835 scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22583
diff changeset
     2
30324
80708959161a scmutil: narrow ImportError handling in termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30323
diff changeset
     3
import array
30322
4b1af1c867fa scmutil: move util.termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30290
diff changeset
     4
import errno
4b1af1c867fa scmutil: move util.termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30290
diff changeset
     5
import fcntl
27483
39087ee88835 scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22583
diff changeset
     6
import os
39087ee88835 scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22583
diff changeset
     7
import sys
39087ee88835 scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22583
diff changeset
     8
39087ee88835 scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22583
diff changeset
     9
from . import (
30290
c90a05124fae py3: make scmposix.userrcpath() return bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27483
diff changeset
    10
    encoding,
27483
39087ee88835 scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22583
diff changeset
    11
    osutil,
30476
5b0baa9f3362 py3: use pycompat.sysargv in scmposix.systemrcpath()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30327
diff changeset
    12
    pycompat,
27483
39087ee88835 scmposix: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22583
diff changeset
    13
)
18690
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    14
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    15
def _rcfiles(path):
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    16
    rcs = [os.path.join(path, 'hgrc')]
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    17
    rcdir = os.path.join(path, 'hgrc.d')
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    18
    try:
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    19
        rcs.extend([os.path.join(rcdir, f)
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    20
                    for f, kind in osutil.listdir(rcdir)
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    21
                    if f.endswith(".rc")])
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    22
    except OSError:
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    23
        pass
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    24
    return rcs
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    25
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    26
def systemrcpath():
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    27
    path = []
30646
16b5df5792a8 py3: replace sys.platform with pycompat.sysplatform (part 1 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30476
diff changeset
    28
    if pycompat.sysplatform == 'plan9':
18690
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    29
        root = 'lib/mercurial'
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    30
    else:
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    31
        root = 'etc/mercurial'
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    32
    # old mod_python does not set sys.argv
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    33
    if len(getattr(sys, 'argv', [])) > 0:
30476
5b0baa9f3362 py3: use pycompat.sysargv in scmposix.systemrcpath()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30327
diff changeset
    34
        p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
22583
23c995ed466b config: don't read the same config file twice
Mads Kiilerich <madski@unity3d.com>
parents: 18690
diff changeset
    35
        if p != '/':
23c995ed466b config: don't read the same config file twice
Mads Kiilerich <madski@unity3d.com>
parents: 18690
diff changeset
    36
            path.extend(_rcfiles(os.path.join(p, root)))
18690
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    37
    path.extend(_rcfiles('/' + root))
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    38
    return path
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    39
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    40
def userrcpath():
30646
16b5df5792a8 py3: replace sys.platform with pycompat.sysplatform (part 1 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30476
diff changeset
    41
    if pycompat.sysplatform == 'plan9':
30290
c90a05124fae py3: make scmposix.userrcpath() return bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27483
diff changeset
    42
        return [encoding.environ['home'] + '/lib/hgrc']
30961
354020079723 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc
David Demelier <demelier.david@gmail.com>
parents: 30646
diff changeset
    43
    elif pycompat.sysplatform == 'darwin':
354020079723 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc
David Demelier <demelier.david@gmail.com>
parents: 30646
diff changeset
    44
        return [os.path.expanduser('~/.hgrc')]
18690
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
diff changeset
    45
    else:
30961
354020079723 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc
David Demelier <demelier.david@gmail.com>
parents: 30646
diff changeset
    46
        confighome = encoding.environ.get('XDG_CONFIG_HOME')
354020079723 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc
David Demelier <demelier.david@gmail.com>
parents: 30646
diff changeset
    47
        if confighome is None or not os.path.isabs(confighome):
354020079723 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc
David Demelier <demelier.david@gmail.com>
parents: 30646
diff changeset
    48
            confighome = os.path.expanduser('~/.config')
354020079723 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc
David Demelier <demelier.david@gmail.com>
parents: 30646
diff changeset
    49
354020079723 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc
David Demelier <demelier.david@gmail.com>
parents: 30646
diff changeset
    50
        return [os.path.expanduser('~/.hgrc'),
354020079723 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc
David Demelier <demelier.david@gmail.com>
parents: 30646
diff changeset
    51
                os.path.join(confighome, 'hg', 'hgrc')]
30322
4b1af1c867fa scmutil: move util.termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30290
diff changeset
    52
30327
365812902904 scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents: 30325
diff changeset
    53
def termsize(ui):
30322
4b1af1c867fa scmutil: move util.termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30290
diff changeset
    54
    try:
4b1af1c867fa scmutil: move util.termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30290
diff changeset
    55
        import termios
30324
80708959161a scmutil: narrow ImportError handling in termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30323
diff changeset
    56
        TIOCGWINSZ = termios.TIOCGWINSZ  # unavailable on IRIX (issue3449)
80708959161a scmutil: narrow ImportError handling in termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30323
diff changeset
    57
    except (AttributeError, ImportError):
30327
365812902904 scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents: 30325
diff changeset
    58
        return 80, 24
30325
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    59
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    60
    for dev in (ui.ferr, ui.fout, ui.fin):
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    61
        try:
30322
4b1af1c867fa scmutil: move util.termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30290
diff changeset
    62
            try:
30325
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    63
                fd = dev.fileno()
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    64
            except AttributeError:
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    65
                continue
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    66
            if not os.isatty(fd):
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    67
                continue
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    68
            arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
31348
7c09b071318a smcposix: pass unicode as first argument to array.array
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30961
diff changeset
    69
            height, width = array.array(r'h', arri)[:2]
30327
365812902904 scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents: 30325
diff changeset
    70
            if width > 0 and height > 0:
365812902904 scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents: 30325
diff changeset
    71
                return width, height
30325
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    72
        except ValueError:
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    73
            pass
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    74
        except IOError as e:
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    75
            if e[0] == errno.EINVAL:
30322
4b1af1c867fa scmutil: move util.termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30290
diff changeset
    76
                pass
30325
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    77
            else:
1ad1c5017043 scmutil: remove superfluous indent from termwidth()
Yuya Nishihara <yuya@tcha.org>
parents: 30324
diff changeset
    78
                raise
30327
365812902904 scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents: 30325
diff changeset
    79
    return 80, 24