|
| 1 | +#!/usr/bin/python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# |
| 4 | +# Copyright (C) 2015-2019 Sérgio Basto <[email protected]> |
| 5 | +# |
| 6 | +# This program is free software; you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation; either version 2 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program; if not, write to the Free Software |
| 18 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | +# |
| 20 | + |
| 21 | +import os |
| 22 | +import sys |
| 23 | +import argparse |
| 24 | +from subprocess import Popen, PIPE |
| 25 | + |
| 26 | +enviro = os.environ |
| 27 | +workdir = '.' |
| 28 | + |
| 29 | +parser = argparse.ArgumentParser() |
| 30 | +parser.add_argument('-v', '--debug', |
| 31 | + help='writes the commands that will be executed', |
| 32 | + action='store_true') |
| 33 | +parser.add_argument('git_args', nargs='*', default=[]) |
| 34 | +parser.add_argument('patchview_args', nargs=argparse.REMAINDER) |
| 35 | +args, unknown = parser.parse_known_args() |
| 36 | +largs = vars(args).get("git_args") |
| 37 | +rargs = vars(args).get("patchview_args") |
| 38 | + |
| 39 | +if args.debug: |
| 40 | + print("%s | %s" % (" ".join(['git', 'diff'] + largs), |
| 41 | + " ".join(['patchview'] + rargs + unknown))) |
| 42 | + |
| 43 | +p1 = Popen(['git', 'diff'] + largs, stdout=PIPE, env=enviro, cwd=workdir) |
| 44 | +p2 = Popen(['patchview'] + rargs + unknown, stdin=p1.stdout, stdout=PIPE, |
| 45 | + env=enviro, cwd=workdir) |
| 46 | +p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. |
| 47 | +sys.stdout.buffer.write(p2.communicate()[0]) |
0 commit comments