Commit | Line | Data |
---|---|---|
ed239fbd YD |
1 | #!/bin/sh |
2 | set -e | |
3 | ||
4 | # stg-fold-files-from - picks changes to one file from another patch. | |
5 | # Only supports picking from one file, 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 | ||
10 | # usage: stg-fold-files-from <patch> [-#<n>[-<n>][,<n>]...] <file> | |
11 | ||
12 | # Copyright (c) 2006-2007 Yann Dirson <ydirson@altern.org> | |
13 | # Subject to the GNU GPL, version 2. | |
14 | ||
15 | PATCH="$1" | |
16 | shift | |
17 | ||
18 | filtercmd=cat | |
19 | hunks= | |
20 | foldflags= | |
21 | while [ "$#" -gt 0 ]; do | |
22 | case "$1" in | |
23 | -\#*) hunks="$1"; shift ;; | |
24 | -t) foldflags="-t"; shift ;; | |
25 | -*) { echo >&2 "unknown flag '$1'"; exit 1; } ;; | |
26 | *) break ;; | |
27 | esac | |
28 | done | |
29 | [ "$#" = 1 ] || { echo >&2 "supports one file only"; exit 1; } | |
30 | ||
31 | stg show "$PATCH" | filterdiff -p1 $hunks -i "$1" | stg fold $foldflags |