File: fork.in

package info (click to toggle)
quilt 0.63-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,868 kB
  • ctags: 153
  • sloc: sh: 5,792; perl: 1,236; lisp: 492; makefile: 431
file content (111 lines) | stat: -rw-r--r-- 2,529 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#! @BASH@

#  This script is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2 as
#  published by the Free Software Foundation.
#
#  See the COPYING and AUTHORS files for more details.

# Read in library functions
if [ "$(type -t patch_file_name)" != function ]
then
	if ! [ -r $QUILT_DIR/scripts/patchfns ]
	then
		echo "Cannot read library $QUILT_DIR/scripts/patchfns" >&2
		exit 1
	fi
	. $QUILT_DIR/scripts/patchfns
fi

usage()
{
	printf $"Usage: quilt fork [new_name]\n"
	if [ x$1 = x-h ]
	then
		printf $"
Fork the topmost patch.  Forking a patch means creating a verbatim copy
of it under a new name, and use that new name instead of the original
one in the current series.  This is useful when a patch has to be
modified, but the original version of it should be preserved, e.g.
because it is used in another series, or for the history.  A typical
sequence of commands would be: fork, edit, refresh.

If new_name is missing, the name of the forked patch will be the current
patch name, followed by \`-2'.  If the patch name already ends in a
dash-and-number, the number is further incremented (e.g., patch.diff,
patch-2.diff, patch-3.diff).
"
		exit 0
	else
		exit 1
	fi
}

options=`getopt -o h -- "$@"`

if [ $? -ne 0 ]
then
	usage
fi

eval set -- "$options"

while true
do
	case "$1" in
	-h)
		usage -h ;;
	--)
		shift
		break ;;
	esac
done

if [ $# -gt 1 ]
then
	usage
fi

top_patch=$(find_top_patch) || exit 1

if [ $# -eq 1 ]
then
	new_patch="$1"
else
	new_patch="$(next_filename "$top_patch")"
fi

new_patch=${new_patch#$QUILT_PATCHES/}

check_potential_patchname "$new_patch"

if patch_in_series $new_patch || \
   [ -d "$QUILT_PC/$new_patch" ] || \
   [ -e "$(patch_file_name $new_patch)" ]
then
	printf $"Patch %s exists already, please choose a new name\n" \
	       "$(print_patch $new_patch)" >&2
	exit 1
fi

if ! rename_in_db "$top_patch" "$new_patch" || \
   ! rename_in_series "$top_patch" "$new_patch" || \
   ! mv "$QUILT_PC/$top_patch" "$QUILT_PC/$new_patch" || \
   ( [ -e "$(patch_file_name $top_patch)" ] && \
     ! cp -p "$(patch_file_name $top_patch)" \
	     "$(patch_file_name $new_patch)" )
then
	printf $"Fork of patch %s to patch %s failed\n" \
	       "$(print_patch $top_patch)" \
	       "$(print_patch $new_patch)" >&2
	exit 1
fi

printf $"Fork of patch %s created as %s\n" \
       "$(print_patch $top_patch)" \
       "$(print_patch $new_patch)"

### Local Variables:
### mode: shell-script
### End:
# vim:filetype=sh