From ab5791e738c32902a9eedff24f812bcb7fb49b0c Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Tue, 6 Aug 2024 01:06:11 +0200 Subject: [PATCH] gitdiffdir: git diff between two dirs. --- G/G | 15 ++++++-- Makefile | 26 +++++++------ README | 2 + ft-udvalg/ft-udvalg | 2 +- gitdiffdir/gitdiffdir | 87 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 17 deletions(-) create mode 100755 gitdiffdir/gitdiffdir diff --git a/G/G b/G/G index 86b70a2..9234925 100755 --- a/G/G +++ b/G/G @@ -99,6 +99,7 @@ B my $i = 0; my @add_X; +# Make groups of grep options: -v foo -v -i bar => [-v foo] [-v -i bar] for(@ARGV) { if($_ eq "-g") { # -g = recursive-and file grep @@ -122,6 +123,7 @@ for(@ARGV) { } if($opt::g and @cmd) { + # -g => search files sub gitdir { # Find .git dir somewhere in parent my $dir = shift; @@ -140,23 +142,28 @@ if($opt::g and @cmd) { `find "$dir" -type f -print0 | xargs -0 cat >/dev/null`; } my $a = shift @cmd; - + # -v => Use -L instead of -l + my $l_or_L = (grep /^-v$/, @$a) ? "L" : "l"; + @$a = (grep { not /^-v$/ } @$a); + my $gitdir = gitdir("."); if($gitdir) { cache_gitdir($gitdir); - $run = 'git grep --threads 30 -l '.shell_quote(@$a); + $run = "git grep --threads 30 -$l_or_L ".shell_quote(@$a); } else { - $run = 'find . -type f | parallel --lb -Xq grep -l '.shell_quote(@$a); + $run = "find . -type f | parallel --lb -Xq grep -$l_or_L ".shell_quote(@$a); } if(@cmd) { $run .= '|' . - join"|", map { 'xargs -d"\n" grep -l '. + join"|", map { 'xargs -d"\n" grep -'.$l_or_L.' '. join(" ", shell_quote(@$_)) } @cmd; } exec $run; } elsif(@cmd) { + # => search stdin exec join"|", map { "grep ".join(" ", shell_quote(@$_)) } @cmd; } else { + # no options => cat exec 'cat'; } diff --git a/Makefile b/Makefile index dfe2388..dbd17e9 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,25 @@ CMD = 2grep 2search audioping blink burncpu bwlimit clipboard drac \ duplicate-packets em emoticons encdir fanspeed field \ find-first-fail find-optimal forever ft-udvalg fxkill G \ - gitnext gitundo goodpasswd histogram Loffice mtrr mirrorpdf \ - neno not off pdfman pidcmd pidtree plotpipe puniq ramusage \ - rand rclean rina rn rrm seekmaniac shython sound-reload \ - splitvideo stdout swapout T teetime timestamp tracefile \ - transpose upsidedown vid w4it-for-port-open whitehash \ - wifi-reload wssh youtube-lbry ytv yyyymmdd + gitdiffdir gitedit gitnext gitundo goodpasswd histogram \ + Loffice mtrr mirrorpdf neno not off pdfman pidcmd pidtree \ + plotpipe puniq ramusage rand rclean rina rn rrm seekmaniac \ + shython sound-reload splitvideo stdout swapout T teetime \ + timestamp tracefile transpose upsidedown vid \ + w4it-for-port-open whitehash wifi-reload wssh youtube-lbry \ + ytv yyyymmdd all: 2search/2grep.1 2search/2search.1 blink/blink.1 \ burncpu/burncpu.1 bwlimit/bwlimit.1 clipboard/clipboard.1 \ drac/drac.1 encdir/encdir.1 fanspeed/fanspeed.1 field/field.1 \ find-first-fail/find-first-fail.1 find-optimal/find-optimal.1 \ - ft-udvalg/ft-udvalg.1 G/G.1 gitnext/gitnext.1 \ - gitundo/gitundo.1 goodpasswd/goodpasswd.1 \ - histogram/histogram.1 mirrorpdf/mirrorpdf.1 neno/neno.1 \ - off/off.1 pdfman/pdfman.1 pidcmd/pidcmd.1 pidtree/pidtree.1 \ - plotpipe/plotpipe.1 puniq/puniq.1 rand/rand.1 rina/rina.1 \ - rn/rn.1 rrm/rrm.1 seekmaniac/seekmaniac.1 shython/shython.1 \ + ft-udvalg/ft-udvalg.1 G/G.1 gitdiffdir/gitdiffdir.1 \ + gitedit/gitedit.1 gitnext/gitnext.1 gitundo/gitundo.1 \ + goodpasswd/goodpasswd.1 histogram/histogram.1 \ + mirrorpdf/mirrorpdf.1 neno/neno.1 off/off.1 pdfman/pdfman.1 \ + pidcmd/pidcmd.1 pidtree/pidtree.1 plotpipe/plotpipe.1 \ + puniq/puniq.1 rand/rand.1 rina/rina.1 rn/rn.1 rrm/rrm.1 \ + seekmaniac/seekmaniac.1 shython/shython.1 \ sound-reload/sound-reload.1 splitvideo/splitvideo.1 \ stdout/stdout.1 teetime/teetime.1 timestamp/timestamp.1 \ tracefile/tracefile.1 transpose/transpose.1 T/T.1 \ diff --git a/README b/README index 216dbe5..0f8cec5 100644 --- a/README +++ b/README @@ -28,6 +28,8 @@ ft-udvalg - Download udvalgsmembers from folketing.dk as ODS. G - shorthand for multi level grep. +gitdiffdir - git diff between two dirs. + gitedit - edit last 10 commits. gitnext - checkout next revision. Opposite of 'checkout HEAD^'. diff --git a/ft-udvalg/ft-udvalg b/ft-udvalg/ft-udvalg index 6d3becf..fc8df86 100755 --- a/ft-udvalg/ft-udvalg +++ b/ft-udvalg/ft-udvalg @@ -174,7 +174,7 @@ for udv, member_list in udv_members.items(): for member in member_list: if member["biopage"] not in members: members[member["biopage"]] = {"biopage": member["biopage"]} - members[member["biopage"]][udv.upper()] = "X" # Mark membership + members[member["biopage"]][udv.upper()] = 1 # Mark membership # Extract additional data for each unique member for member in members.values(): diff --git a/gitdiffdir/gitdiffdir b/gitdiffdir/gitdiffdir new file mode 100755 index 0000000..8d24635 --- /dev/null +++ b/gitdiffdir/gitdiffdir @@ -0,0 +1,87 @@ +#!/bin/bash + +: <<=cut +=pod + +=head1 NAME + +gitdiffdir - git diff, but between two dirs in different repositories + + +=head1 SYNOPSIS + +gitdiffdir dir1 dir2 + + +=head1 DESCRIPTION + +B only looks at tracked files. B +includes all untracked files. + +B tries to simulate B but on two dirs in +different repositories. + + +=head1 EXAMPLES + +Diff dirs with the same name: + + gitdiffdir myproject/mydir1 myoldproject/mydir1 + +Diff dirs with the different names: + + gitdiffdir myproject/mydir1 myoldproject/mydir2 + + +=head1 AUTHOR + +Copyright (C) 2024 Ole Tange, +http://ole.tange.dk and Free Software Foundation, Inc. + + +=head1 LICENSE + +Copyright (C) 2012 Free Software Foundation, Inc. + +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 3 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, see . + + +=head1 DEPENDENCIES + +B uses B, B, B. + + +=head1 SEE ALSO + +B + + +=cut + +dirA="$1" +dirB="$2" + +stdout() { + if [ -t 1 ] ; then + # STDOUT = terminal + # use less + less + else + cat + fi +} + + +parallel -0 'cd {} && git ls-files' ::: "$dirA" "$dirB" | sort -u | + parallel -q diff -Naur "$dirA"/{} "$dirB"/{} | stdout