From b9dadc55760642ac4e8ac9766cf832cc38015923 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sun, 21 Aug 2022 15:26:24 +0200 Subject: diffpkg: allow to choose between unified context and two columns --- contrib/completion/zsh/_devtools.in | 2 ++ doc/man/diffpkg.1.asciidoc | 9 +++++++++ src/diffpkg.in | 32 +++++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index eee9776..84ecf27 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -47,6 +47,8 @@ _diffpkg_args=( '(-p --pkginfo)'{-p,--pkginfo}'[.PKGINFO diff mode]' '(-b --buildinfo)'{-b,--buildinfo}'[.BUILDINFO diff mode]' '(-m --makepkg-config)'{-m,--makepkg-config}'[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' + '(-u -U --unified)'{-u,-U,--unified}'[Output 3 lines of unified context]' + '(-y --side-by-side)'{-y,--side-by-side}'[Output in two columns]' '(-v --verbose)'{-v,--verbose}'[Provide more detailed/unfiltered output]' '(-h --help)'{-h,--help}'[Display usage]' '*:packages:_devtools_completions_all_packages' diff --git a/doc/man/diffpkg.1.asciidoc b/doc/man/diffpkg.1.asciidoc index 48722a9..622771a 100644 --- a/doc/man/diffpkg.1.asciidoc +++ b/doc/man/diffpkg.1.asciidoc @@ -36,6 +36,15 @@ Options *-h, --help*:: Show a help text +Output Options +-------------- + +*-u, -U, --unified*:: + Output 3 lines of unified context + +*-y, --side-by-side*:: + Output in two columns + Modes ----- diff --git a/src/diffpkg.in b/src/diffpkg.in index 17df6e5..243e127 100644 --- a/src/diffpkg.in +++ b/src/diffpkg.in @@ -27,6 +27,10 @@ usage() { -v, --verbose Provide more detailed/unfiltered output -h, --help Show this help text + OUTPUT OPTIONS + -u, -U, --unified Output 3 lines of unified context + -y, --side-by-side Output in two columns + MODES -l, --list Activate content list diff mode (default) -d, --diffoscope Activate diffoscope diff mode @@ -42,6 +46,9 @@ DIFFOSCOPE=0 PKGINFO=0 BUILDINFO=0 +DIFFMODE=--side-by-side +DIFFOPTIONS=(--expand-tabs) + # option checking while (( $# )); do case $1 in @@ -73,6 +80,14 @@ while (( $# )); do VERBOSE=1 shift ;; + -u|-U|--unified) + DIFFMODE=--unified + shift + ;; + -y|--side-by-side) + DIFFMODE=--side-by-side + shift + ;; --) shift break @@ -86,6 +101,15 @@ while (( $# )); do esac done +if (( VERBOSE )); then + if [[ $DIFFMODE == --unified ]]; then + DIFFMODE="--unified=99999" + fi +else + DIFFOPTIONS+=(--suppress-common-lines) +fi +DIFFOPTIONS+=("${DIFFMODE}") + if ! (( DIFFOSCOPE || TARLIST || PKGINFO || BUILDINFO )); then TARLIST=1 fi @@ -128,25 +152,27 @@ diff_pkgs() { [[ -f $oldpkg ]] || die "No such file: %s" "${oldpkg}" [[ -f $newpkg ]] || die "No such file: %s" "${newpkg}" + DIFFOPTIONS+=(--label "${oldpkg}" --label "${newpkg}") + if (( TARLIST )); then tar_list "$oldpkg" > "$TMPDIR/filelist-old" tar_list "$newpkg" > "$TMPDIR/filelist" - sdiff -s "$TMPDIR/filelist-old" "$TMPDIR/filelist" + diff "${DIFFOPTIONS[@]}" "$TMPDIR/filelist-old" "$TMPDIR/filelist" fi if (( PKGINFO )); then bsdtar xOqf "$oldpkg" .PKGINFO > "$TMPDIR/pkginfo-old" bsdtar xOqf "$newpkg" .PKGINFO > "$TMPDIR/pkginfo" - sdiff -s "$TMPDIR/pkginfo-old" "$TMPDIR/pkginfo" + diff "${DIFFOPTIONS[@]}" "$TMPDIR/pkginfo-old" "$TMPDIR/pkginfo" fi if (( BUILDINFO )); then bsdtar xOqf "$oldpkg" .BUILDINFO > "$TMPDIR/buildinfo-old" bsdtar xOqf "$newpkg" .BUILDINFO > "$TMPDIR/buildinfo" - sdiff -s "$TMPDIR/buildinfo-old" "$TMPDIR/buildinfo" + diff "${DIFFOPTIONS[@]}" "$TMPDIR/buildinfo-old" "$TMPDIR/buildinfo" fi if (( DIFFOSCOPE )); then -- cgit v1.2.3-54-g00ecf