git-cinnabar

Форк
0
/
filter.py 
60 строк · 1.8 Кб
1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
import sys
6

7

8
class DataCommand:
9
    def __init__(self, data):
10
        self.data = data
11

12
    def write_to(self, out):
13
        out.write(b"data %d\n" % len(self.data))
14
        out.write(self.data)
15

16

17
def iter_commands(input=sys.stdin.buffer):
18
    for line in input:
19
        if line.startswith(b"data "):
20
            _, length = line.split()
21
            length = int(length)
22
            data = input.read(length)
23
            assert len(data) == length
24
            yield DataCommand(data)
25
        else:
26
            yield line
27

28

29
def write_command(command, out=sys.stdout.buffer):
30
    if isinstance(command, DataCommand):
31
        command.write_to(out)
32
    else:
33
        out.write(command)
34

35

36
if __name__ == "__main__":
37
    args = sys.argv[1:]
38
    for arg in args:
39
        if arg not in ["--commits", "--roots"]:
40
            print(f"Unsupported options: {args}")
41
            sys.exit(1)
42

43
    commands = iter_commands()
44
    for command in commands:
45
        if isinstance(command, DataCommand):
46
            if "--commits" in args:
47
                command.data += b"\n"
48
            if "--roots" in args:
49
                write_command(command)
50
                while True:
51
                    command = next(commands)
52
                    # No "from" command, so this is a root, remove all the
53
                    # files from it.
54
                    if not command.startswith((b"deleteall", b"M ")):
55
                        break
56

57
        elif command.startswith((b"author  <", b"committer  <")):
58
            cmd, email = command.split(b"<", 1)
59
            command = cmd[:-1] + email.split(b"@", 1)[0] + b" <" + email
60
        write_command(command)
61

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.