diff --git a/Makefile.am b/Makefile.am index 58604f9b..e0117b02 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,6 +16,8 @@ bin_SCRIPTS = \ dist_bin_SCRIPTS = \ patchview/gitdiff \ patchview/gitdiffview \ + patchview/gitshow \ + patchview/gitshowview \ patchview/svndiff \ patchview/svndiffview diff --git a/README.md b/README.md index 007fc0af..83292f64 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ Patchutils is a small collection of programs that operate on patch files. It pro - **gitdiff** / **gitdiffview** - Git-specific diff viewing tools. +- **gitshow** / **gitshowview** - Git-specific show viewing tools. + - **svndiff** / **svndiffview** - Subversion-specific diff viewing tools. ## Installation diff --git a/patchview/README.patchview b/patchview/README.patchview index 144fc4db..3fcc0573 100644 --- a/patchview/README.patchview +++ b/patchview/README.patchview @@ -1,38 +1,34 @@ So what is patchview? It is a wrapper of filterdiff for use with numbered files. $ patchview - (without args) -is equivalent to: lsdiff --number +Without args is equivalent to: lsdiff --number $ patchview -F2- - (or with any other args) + -is equivalent to: filterdiff -F2- (or whatever arguments are supplied) +With one or more args is equivalent to: filterdiff args + +There are 4 scripts for working with git repos (gitdiff, gitdiffview, gitshow and gitshowview) and 2 for svn (svndiff and svndiffview). +Also these scripts have option -v which shows the full command that is which is being executed. -There are two scripts for working with git (gitdiff and gitdiffview) and two for svn (svndiff and svndiffview). $ svndiff - $ gitdiff - (without args) - -will give the list of files modified + $ gitdiff - $ svndiff -F1 - $ gitdiff -F1 - -will show the patch of file #1 +Without args, will give the list of files modified +With args will show the patches according the args, for example, `gitdiff -F1` will show the patch for first file $ svndiffview $ gitdiffview -pipe all patches through filterdiff to `vim - -R` (in read-only mode, easy to quit), showing complete patch with color. +Without args will pipe all patches through filterdiff to `vim - -R` (in read-only mode, easy to quit), showing complete patch with colors. +With args will pipe the patches according the args, for example, `gitsvnview -F2` will pipe the patch for second file to `vim - -R`. - $ svndiffview -F2 - $ gitdiffview -F2 - (or any other args) + $ gitshow + $ gitshowview -will pipe patch of file #2 to `vim - -R` +Is the same of gitdiff but use `git show` instead of `git diff`. Example: We can make the following one-line script with the name difftotrunk.sh, to view the differences of two directories or svn repos (trunk and .) diff --git a/patchview/gitshow b/patchview/gitshow new file mode 100755 index 00000000..0608d261 --- /dev/null +++ b/patchview/gitshow @@ -0,0 +1,47 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015-2020 Sérgio Basto +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +import os +import sys +import argparse +from subprocess import Popen, PIPE + +enviro = os.environ +workdir = '.' + +parser = argparse.ArgumentParser() +parser.add_argument('-v', '--debug', + help='writes the commands that will be executed', + action='store_true') +parser.add_argument('git_args', nargs='*', default=[]) +parser.add_argument('patchview_args', nargs=argparse.REMAINDER) +args, unknown = parser.parse_known_args() +largs = vars(args).get("git_args") +rargs = vars(args).get("patchview_args") + +if args.debug: + print("%s | %s" % (" ".join(['git', 'diff'] + largs), + " ".join(['patchview'] + rargs + unknown))) + +p1 = Popen(['git', 'show'] + largs, stdout=PIPE, env=enviro, cwd=workdir) +p2 = Popen(['patchview'] + rargs + unknown, stdin=p1.stdout, stdout=PIPE, + env=enviro, cwd=workdir) +p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. +sys.stdout.buffer.write(p2.communicate()[0]) diff --git a/patchview/gitshowview b/patchview/gitshowview new file mode 100755 index 00000000..9908b5ec --- /dev/null +++ b/patchview/gitshowview @@ -0,0 +1,20 @@ +#!/bin/sh +# +# Copyright (C) 2014-2020 Sérgio Basto +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +gitshow --filter "$@" | vim -R -