Commit | Line | Data |
---|---|---|
d6235717 | 1 | #!/bin/bash |
ed239fbd YD |
2 | set -e |
3 | ||
4 | # stg-fold-files-from - picks changes to one file from another patch. | |
36c0e9cc | 5 | # Only supports picking from one file pattern, but allows to select any range |
ed239fbd YD |
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. | |
d6235717 | 9 | # Use "-O -U<n>" to get finer hunk granularity for -#<n>. |
ed239fbd | 10 | |
cbb3c553 | 11 | # usage: stg-fold-files-from <patch> [-n] [-O <stg-show-flags>] [-#<n>[-<n>][,<n>]...] <file-pattern> |
ed239fbd YD |
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= | |
d6235717 | 22 | showflags=() |
cbb3c553 | 23 | noact=0 |
ed239fbd YD |
24 | while [ "$#" -gt 0 ]; do |
25 | case "$1" in | |
d6235717 YD |
26 | -\#*) hunks="$1" ;; |
27 | -t) foldflags="-t" ;; | |
cbb3c553 | 28 | -n) noact=1 ;; |
d6235717 | 29 | -O) showflags+=(-O "$2"); shift ;; |
ed239fbd YD |
30 | -*) { echo >&2 "unknown flag '$1'"; exit 1; } ;; |
31 | *) break ;; | |
32 | esac | |
d6235717 | 33 | shift |
ed239fbd YD |
34 | done |
35 | [ "$#" = 1 ] || { echo >&2 "supports one file only"; exit 1; } | |
36 | ||
cbb3c553 YD |
37 | getpatch() |
38 | { | |
39 | stg show "${showflags[@]}" "$PATCH" | filterdiff -p1 $hunks -i "$1" | |
40 | } | |
41 | ||
42 | if [ $noact = 1 ]; then | |
43 | getpatch "$1" | |
44 | else | |
45 | getpatch "$1" | stg fold $foldflags | |
46 | fi |