X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/ed239fbd9baf26fe26349fd115523156bac58a37..9938103fc5b4082d84f21eca0668b3b58913c895:/contrib/stg-fold-files-from diff --git a/contrib/stg-fold-files-from b/contrib/stg-fold-files-from index bfb4a1f..c52abfc 100755 --- a/contrib/stg-fold-files-from +++ b/contrib/stg-fold-files-from @@ -1,13 +1,14 @@ -#!/bin/sh +#!/bin/bash set -e # stg-fold-files-from - picks changes to one file from another patch. -# Only supports picking from one file, but allows to select any range +# Only supports picking from one file pattern, but allows to select any range # of hunks from the file, using the -# flag to filterdiff. # Use together with "filterdiff --annotate" in your diff pager, to # identify hunk numbers easily. +# Use "-O -U" to get finer hunk granularity for -#. -# usage: stg-fold-files-from [-#[-][,]...] +# usage: stg-fold-files-from [-n] [-O ] [-#[-][,]...] # Copyright (c) 2006-2007 Yann Dirson # Subject to the GNU GPL, version 2. @@ -18,14 +19,28 @@ shift filtercmd=cat hunks= foldflags= +showflags=() +noact=0 while [ "$#" -gt 0 ]; do case "$1" in - -\#*) hunks="$1"; shift ;; - -t) foldflags="-t"; shift ;; + -\#*) hunks="$1" ;; + -t) foldflags="-t" ;; + -n) noact=1 ;; + -O) showflags+=(-O "$2"); shift ;; -*) { echo >&2 "unknown flag '$1'"; exit 1; } ;; *) break ;; esac + shift done [ "$#" = 1 ] || { echo >&2 "supports one file only"; exit 1; } -stg show "$PATCH" | filterdiff -p1 $hunks -i "$1" | stg fold $foldflags +getpatch() +{ + stg show "${showflags[@]}" "$PATCH" | filterdiff -p1 $hunks -i "$1" +} + +if [ $noact = 1 ]; then + getpatch "$1" +else + getpatch "$1" | stg fold $foldflags +fi