chiark / gitweb /
806a1576d7b3806b22b8c5c1eccfa4568082df5e
[stgit] / contrib / stg-fold-files-from
1 #!/bin/bash
2 set -e
3
4 # stg-fold-files-from - picks changes to one file from another patch.
5 # Only supports picking from one file pattern, but allows to select any range
6 # of hunks from the file, using the -# flag to filterdiff.
7 # Use together with "filterdiff --annotate" in your diff pager, to
8 # identify hunk numbers easily.
9 # Use "-O -U<n>" to get finer hunk granularity for -#<n>.
10
11 # usage: stg-fold-files-from <patch> [-O <stg-show-flags>] [-#<n>[-<n>][,<n>]...] <file-pattern>
12
13 # Copyright (c) 2006-2007 Yann Dirson <ydirson@altern.org>
14 # Subject to the GNU GPL, version 2.
15
16 PATCH="$1"
17 shift
18
19 filtercmd=cat
20 hunks=
21 foldflags=
22 showflags=()
23 while [ "$#" -gt 0 ]; do
24     case "$1" in
25         -\#*) hunks="$1" ;;
26         -t) foldflags="-t" ;;
27         -O) showflags+=(-O "$2"); shift ;;
28         -*) { echo >&2 "unknown flag '$1'"; exit 1; } ;;
29         *) break ;;
30     esac
31     shift
32 done
33 [ "$#" = 1 ] || { echo >&2 "supports one file only"; exit 1; }
34
35 stg show "${showflags[@]}" "$PATCH" | filterdiff -p1 $hunks -i "$1" | stg fold $foldflags