File: ext-break-git-import.py

package info (click to toggle)
hg-git 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,244 kB
  • sloc: python: 8,702; sh: 185; makefile: 23
file content (41 lines) | stat: -rw-r--r-- 935 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
"""This is a small custom extension that allows stopping a hg-git
conversion after a specific number of commits.

Configure it using the following environment variables:

- ABORT_AFTER
- EXIT_AFTER

"""

import os
from mercurial import error, extensions

counter = 0

hggit = extensions.find(b"hggit")


def wrap(orig, *args, **kwargs):
    global counter

    counter += 1

    try:
        return orig(*args, **kwargs)
    finally:
        abort_after = int(os.getenv("ABORT_AFTER", "0"))
        exit_after = int(os.getenv("EXIT_AFTER", "0"))

        if abort_after and counter > abort_after:
            raise error.Abort(b"aborted after %d commits!" % abort_after)
        elif exit_after and counter > exit_after:
            raise KeyboardInterrupt


extensions.wrapfunction(hggit.git_handler.GitHandler, "export_hg_commit", wrap)
extensions.wrapfunction(
    hggit.git_handler.GitHandler,
    "import_git_commit",
    wrap,
)