File: config.py

package info (click to toggle)
hg-git 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,372 kB
  • sloc: python: 8,708; sh: 185; makefile: 23
file content (95 lines) | stat: -rw-r--r-- 2,501 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import bisect
import collections

from mercurial import exthelper
from mercurial import help
from mercurial.i18n import _
from mercurial.utils import stringutil, urlutil

from . import util

eh = exthelper.exthelper()

CONFIG_DEFAULTS = {
    b'experimental': {
        b'hg-git-bundle': False,
        b'hg-git-serve': False,
    },
    b'git': {
        b'authors': None,
        b'branch_bookmark_suffix': None,
        b'findcopiesharder': False,
        b'intree': None,
        b'mindate': None,
        b'public': list,
        b'renamelimit': 400,
        b'similarity': 0,
        b'pull-prune-remote-branches': True,
        b'pull-prune-bookmarks': True,
        b'blame.ignoreRevsFile': None,
    },
    b'hggit': {
        b'fetchbuffer': 100,
        b'mapsavefrequency': 1000,
        b'usephases': None,
        b'retries': 3,
        b'invalidpaths': b'skip',
        b'threads': -1,
    },
}

for section, items in CONFIG_DEFAULTS.items():
    for item, default in items.items():
        eh.configitem(section, item, default=default)


publishoption = collections.namedtuple(
    'publishoption', ['use_phases', 'publish_defaults', 'refs_to_publish']
)


def get_publishing_option(ui, remote_names):
    refs = set(ui.configlist(b'git', b'public'))

    use_phases = ui.configbool(b'hggit', b'usephases', None)

    if use_phases is None:
        use_phases = any(
            not p.url.islocal() for n in remote_names for p in ui.paths.get(n)
        )

    publish_defaults = not refs

    return publishoption(use_phases, publish_defaults, refs)


@eh.extsetup
def extsetup(ui):
    @urlutil.pathsuboption(b'hg-git.publish', 'hggit_publish')
    def pathsuboption(ui, path, value):
        b = stringutil.parsebool(value)
        if b is True:
            return publishoption(True, True, frozenset())
        elif b is False:
            return publishoption(False, False, frozenset())
        else:
            return publishoption(
                True, False, frozenset(stringutil.parselist(value))
            )

    def insertconfigurationhelp(ui, topic, doc):
        doc += (
            b'\n\n' + util.get_package_resource("helptext/config.rst").strip()
        )

        return doc

    help.addtopichook(b'config', insertconfigurationhelp)

    entry = (
        [b'hggit-config'],
        _(b"Configuring hg-git"),
        lambda ui: util.get_package_resource("helptext/config.rst"),
        help.TOPIC_CATEGORY_CONFIG,
    )
    bisect.insort(help.helptable, entry)