[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [patch 3/6] select/merge documentation on import
From: |
jayvdb |
Subject: |
[Quilt-dev] [patch 3/6] select/merge documentation on import |
Date: |
Tue, 27 Sep 2005 19:19:25 +1000 |
User-agent: |
quilt/0.42-1 |
Trivialise patch parameter checks
Add quotes around all patch parameters
Report "No patches in series"
annotate reports "No applied patches"
delete hits the series file less
push only checks "stop_at_file" is in the series once
Minor error reporting difference:
When a user is at patch3 " diff --combine patch4 -P patch2 " reports
Patch patch4 is not applied
instead of
Patch patch4 not applied before patch patch2
scripts/patchfns.in | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++-
quilt/add.in | 22 ---------
quilt/annotate.in | 14 +-----
quilt/applied.in | 16 -------
quilt/delete.in | 42 ++++--------------
quilt/diff.in | 31 +-------------
quilt/files.in | 23 +---------
quilt/fold.in | 7 ---
quilt/fork.in | 7 ---
quilt/graph.in | 23 ----------
quilt/header.in | 18 --------
quilt/next.in | 17 -------
quilt/pop.in | 15 ------
quilt/previous.in | 11 ----
quilt/push.in | 42 ++----------------
quilt/refresh.in | 28 ------------
quilt/remove.in | 22 ---------
quilt/rename.in | 16 -------
quilt/top.in | 10 +---
quilt/unapplied.in | 19 +++-----
test/three.test | 29 ++++++++++---
21 files changed, 193 insertions(+), 334 deletions(-)
--- quilt-files.orig/scripts/patchfns.in
+++ quilt-files/scripts/patchfns.in
@@ -197,7 +197,7 @@ patch_in_series()
insert_in_series()
{
local patch=$1 patch_args=$2
- local next=$(patches_after "$(top_patch)" | head -n 1) tmpfile
+ local next=$(patch_after "$(top_patch)") tmpfile
if [ -n "$patch_args" ]
then
@@ -377,6 +377,12 @@ patches_after()
fi
}
+patch_after()
+{
+ local patch="$1"
+ patches_after "$patch" | head -n 1
+}
+
# List all patches that have been applied on top of patch $1
patches_on_top_of()
{
@@ -428,7 +434,8 @@ remove_from_db()
find_patch()
{
- if [ $# -eq 1 -a -n "$1" -a -e "$SERIES" ]
+ local name="$1"
+ if [ -e "$SERIES" ]
then
local patch="${1#$SUBDIR_DOWN$QUILT_PATCHES/}"
local bre=$(quote_bre "$patch")
@@ -452,9 +459,113 @@ find_patch()
done
fi
fi
+ # Finding the first patch will error when the series is empty
+ first=$(find_first_patch)
+ if [ -n "$first" ]
+ then
+ printf $"Patch %s is not in series\n" "$name" >&2
+ fi
return 1
}
+find_first_patch()
+{
+ local patch=$(cat_series | head -n 1)
+ if [ -z "$patch" ]
+ then
+ printf $"No patches in series\n" >&2
+ return 1
+ fi
+
+ echo $patch
+}
+
+find_top_patch ()
+{
+ local patch=$(top_patch)
+ if [ -z "$patch" ]
+ then
+ first=$(find_first_patch) || return 1
+
+ printf $"No patches applied\n" >&2
+ return 1
+ fi
+
+ echo "$patch"
+}
+
+find_series_patch ()
+{
+ local name="$1"
+ local patch
+
+ if [ -n "$name" ]
+ then
+ patch=$(find_patch "$name") || return 1
+ else
+ patch=$(find_top_patch) || return 1
+ fi
+
+ echo "$patch"
+}
+
+find_applied_patch ()
+{
+ local name="$1"
+ local patch
+
+ if [ -n "$name" ]
+ then
+ patch=$(find_patch "$name") || return 1
+
+ if ! is_applied "$patch"
+ then
+ printf $"Patch %s is not applied\n" "$(print_patch
$patch)" >&2
+ return 1
+ fi
+ else
+ patch=$(find_top_patch) || return 1
+ fi
+
+ echo "$patch"
+}
+
+find_pending_patch ()
+{
+ local name="$1"
+ local patch
+
+ if [ -n "$name" ]
+ then
+ patch=$(find_patch "$name") || return 1
+
+ if is_applied "$patch"
+ then
+ printf $"Patch %s is already applied\n" \
+ "$(print_patch $patch)" >&2
+ return 1
+ fi
+ else
+ local start=$(top_patch)
+ if [ -n "$start" ]
+ then
+ patch=$(patch_after "$start")
+ else
+ patch=$(find_first_patch) || return 1
+ fi
+
+
+ if [ -z "$patch" ]
+ then
+ printf $"File series fully applied, ends at patch %s\n"
\
+ "$(print_patch $start)" >&2
+ return 1
+ fi
+ fi
+
+ echo "$patch"
+}
+
file_in_patch()
{
local file=$1 patch=$2
--- quilt-files.orig/quilt/add.in
+++ quilt-files/quilt/add.in
@@ -73,11 +73,7 @@ while true
do
case "$1" in
-p)
- if ! patch=$(find_patch $2)
- then
- printf $"Patch %s is not in series\n" "$2" >&2
- exit 1
- fi
+ opt_patch="$2"
shift 2 ;;
-h)
usage -h ;;
@@ -92,21 +88,7 @@ then
usage
fi
-if [ -n "$patch" ]
-then
- if ! is_applied $patch
- then
- printf $"Patch %s is not applied\n" "$(print_patch $patch)" >&2
- exit 1
- fi
-else
- patch=$(top_patch)
- if [ -z "$patch" ]
- then
- printf $"No patches applied\n" >&2
- exit 1
- fi
-fi
+patch=$(find_applied_patch "$opt_patch") || exit 1
status=0
for file in $*
--- quilt-files.orig/quilt/annotate.in
+++ quilt-files/quilt/annotate.in
@@ -98,11 +98,7 @@ while true
do
case "$1" in
-p)
- if ! opt_patch=$(find_patch "$2")
- then
- printf $"Patch %s is not in series\n" "$2" >&2
- exit 1
- fi
+ opt_patch="$2"
shift 2 ;;
-h)
usage -h ;;
@@ -118,12 +114,8 @@ then
fi
opt_file="$SUBDIR$1"
-if [ -n "$opt_patch" ] && ! is_applied "$opt_patch"
-then
- printf $"Patch %s is not applied\n" \
- "$(print_patch "$opt_patch")" >&2
- exit 1
-fi
+# verify this patch is applied, or that there are applied patches
+opt_patch=$(find_applied_patch "$opt_patch") || exit 1
for patch in $(applied_patches); do
old_file="$(backup_file_name "$patch" "$opt_file")"
--- quilt-files.orig/quilt/applied.in
+++ quilt-files/quilt/applied.in
@@ -55,22 +55,10 @@ done
if [ $# -gt 1 ]
then
usage
-elif [ $# -eq 1 ]
-then
- if ! patch=$(find_patch $1)
- then
- printf $"Patch %s is not in series\n" "$1" >&2
- exit 1
- fi
- if ! is_applied "$patch"
- then
- printf $"Patch is not applied\n" "$(print_patch $patch)" >&2
- exit 1
- fi
-else
- patch=$(top_patch)
fi
+patch=$(find_applied_patch "$1") || exit 1
+
for patch in $(applied_before "$patch") $patch
do
echo "$(print_patch $patch)"
--- quilt-files.orig/quilt/delete.in
+++ quilt-files/quilt/delete.in
@@ -77,42 +77,21 @@ then
usage
fi
-patch="$1"
-if [ -z "$patch" ]
+patch=$(find_series_patch "$1") || exit 1
+
+# This block assumes when opt_next is set, or $1 is blank
+# find_series_patch will always return top_patch.
+if [ -n "$opt_next" ]
then
- patch="$(top_patch)"
- if [ -z "$opt_next" ]
+ patch="$(patch_after "$patch")"
+ if [ -z "$patch" ]
then
- if [ -z "$patch" ]
- then
- printf $"No patches applied\n" >&2
- exit 1
- fi
- else
- if [ -z "$patch" ]
- then
- patch="$(cat_series | head -n 1)"
- else
- patch="$(patches_after "$patch" | head -n 1)"
- fi
- if [ -z "$patch" ]
- then
- printf $"No next patch\n" >&2
- exit 1
- fi
- fi
-else
- save_patch=$patch
- if ! patch=$(find_patch $patch)
- then
- patch=$save_patch
- printf $"Patch %s is not in series\n" "$patch" >&2
+ printf $"No next patch\n" >&2
exit 1
fi
-fi
-if is_applied $patch
+elif [ -z "$1" ] || is_applied $patch
then
- if [ "$patch" != "$(top_patch)" ] || \
+ if [ -n "$1" ] || \
! quilt_command pop -fq
then
printf $"Patch %s is currently applied\n" \
@@ -120,6 +99,7 @@ then
exit 1
fi
fi
+
if remove_from_series "$patch"
then
printf $"Removed patch %s\n" "$(print_patch "$patch")"
--- quilt-files.orig/quilt/diff.in
+++ quilt-files/quilt/diff.in
@@ -155,23 +155,15 @@ do
opt_strip_level=$2
shift 2 ;;
-P)
- if ! last_patch=$(find_patch $2)
- then
- printf $"Patch %s is not in series\n" \
- "$(print_patch $2)" >&2
- exit 1
- fi
+ last_patch="$2"
shift 2 ;;
--combine)
opt_combine=1
if [ "$2" = - ]
then
first_patch=-
- elif ! first_patch=$(find_patch $2)
- then
- printf $"Patch %s is not in series\n" \
- "$(print_patch $2)" >&2
- exit 1
+ else
+ first_patch=$(find_applied_patch "$2") || exit 1
fi
shift 2 ;;
-R)
@@ -233,22 +225,7 @@ then
die 1
fi
-if [ -n "$last_patch" ]
-then
- if ! is_applied "$last_patch"
- then
- printf $"Patch %s is not applied\n" \
- "$(print_patch $last_patch)" >&2
- die 1
- fi
-else
- last_patch=$(top_patch)
- if [ -z "$last_patch" ]
- then
- printf $"No patches applied\n" >&2
- die 1
- fi
-fi
+last_patch=$(find_applied_patch "$last_patch") || exit 1
if [ -z "$opt_strip_level" ]
then
--- quilt-files.orig/quilt/files.in
+++ quilt-files/quilt/files.in
@@ -71,10 +71,8 @@ do
if [ "$2" = - ]
then
:
- elif ! first_patch=$(find_patch $2)
- then
- printf $"Patch %s is not in series file\n" "$2" >&2
- exit 1
+ else
+ first_patch=$(find_series_patch "$2") || exit 1
fi
shift 2 ;;
--)
@@ -87,23 +85,8 @@ if [ $# -gt 1 ]
then
usage
fi
-last_patch=$(find_patch $1)
-if [ -n "$last_patch" ]
-then
- if ! patch=$(find_patch $last_patch)
- then
- printf $"Patch %s is not in series file\n" "$last_patch" >&2
- exit 1
- fi
-else
- last_patch=$(top_patch)
- if [ -z "$last_patch" ]
- then
- printf $"No patches applied\n" >&2
- exit 1
- fi
-fi
+last_patch=$(find_series_patch "$1") || exit 1
if [ -n "$opt_all" -a -z "$first_patch" ]
then
--- quilt-files.orig/quilt/fold.in
+++ quilt-files/quilt/fold.in
@@ -73,12 +73,7 @@ fi
: ${opt_strip_level:=1}
[ -n "$opt_silent" ] && silent=-s
-top=$(top_patch)
-if [ -z "$top" ]
-then
- printf $"No patches applied\n" >&2
- exit 1
-fi
+top=$(find_top_patch) || exit 1
trap "failed=1" SIGINT
--- quilt-files.orig/quilt/fork.in
+++ quilt-files/quilt/fork.in
@@ -66,12 +66,7 @@ then
usage
fi
-top_patch=$(top_patch)
-if [ -z "$top_patch" ]
-then
- printf $"No patches applied\n" >&2
- exit 1
-fi
+top_patch=$(find_top_patch) || exit 1
if [ $# -eq 1 ]
then
--- quilt-files.orig/quilt/graph.in
+++ quilt-files/quilt/graph.in
@@ -109,28 +109,9 @@ then
usage
fi
-if [ $# -eq 1 ]
+if [ -z "$opt_all" ]
then
- if ! patch=$(find_patch $1)
- then
- printf $"Patch %s is not in series\n" "$1" >&2
- exit 1
- fi
- if ! is_applied $patch
- then
- printf $"Patch %s is not applied\n" "$(print_patch $patch)" >&2
- exit 1
- fi
-fi
-
-if [ -z "$opt_all" -a -z "$patch" ]
-then
- patch=$(top_patch)
- if [ -z "$patch" ]
- then
- printf $"No patches applied\n" >&2
- exit 1
- fi
+ patch=$(find_applied_patch "$1") || exit 1
fi
options=
--- quilt-files.orig/quilt/header.in
+++ quilt-files/quilt/header.in
@@ -126,23 +126,7 @@ then
usage
fi
-[ $# -eq 1 ] && opt_patch=$1
-
-if [ -n "$opt_patch" ]
-then
- if ! patch=$(find_patch "$opt_patch")
- then
- printf $"Patch %s is not in series\n" "$opt_patch" >&2
- exit 1
- fi
-else
- patch=$(top_patch)
- if [ -z "$patch" ]
- then
- printf $"No patches applied\n" >&2
- exit 1
- fi
-fi
+patch=$(find_series_patch "$1") || exit 1
patch_file=$(patch_file_name $patch)
--- quilt-files.orig/quilt/next.in
+++ quilt-files/quilt/next.in
@@ -55,23 +55,10 @@ done
if [ $# -gt 1 ]
then
usage
-elif [ $# -eq 1 ]
-then
- if ! patch=$(find_patch $1)
- then
- printf $"Patch %s is not in series\n" "$1" >&2
- exit 1
- fi
-else
- patch=$(top_patch)
fi
-if [ -z "$patch" ]
-then
- next=$(cat_series | head -n 1)
-else
- next=$(patches_after $patch | head -n 1)
-fi
+next=$(find_pending_patch "$1") || exit
+
if [ -n "$next" ]
then
echo "$(print_patch $next)"
--- quilt-files.orig/quilt/pop.in
+++ quilt-files/quilt/pop.in
@@ -228,11 +228,7 @@ then
then
number=$1
else
- if ! stop_at_patch=$(find_patch $1)
- then
- printf $"Patch %s is not in series\n" "$1" >&2
- exit 1
- fi
+ stop_at_patch=$(find_applied_patch "$1") || exit 1
fi
else
[ -n "$opt_all" ] || number=1
@@ -241,15 +237,6 @@ fi
[ -n "$opt_quiet" ] && silent=-s
[ -z "$opt_verbose" ] && silent_unless_verbose=-s
-if [ -n "$stop_at_patch" ]
-then
- if ! is_applied $stop_at_patch
- then
- printf $"Patch %s is not applied\n" "$(print_patch
$stop_at_patch)" >&2
- exit 1
- fi
-fi
-
top=$(top_patch)
if [ -n "$top" -a -e $QUILT_PC/$top~refresh -a -z "$opt_force" ]
then
--- quilt-files.orig/quilt/previous.in
+++ quilt-files/quilt/previous.in
@@ -55,17 +55,10 @@ done
if [ $# -gt 1 ]
then
usage
-elif [ $# -eq 1 ]
-then
- if ! patch=$(find_patch $1)
- then
- printf $"Patch %s is not in series\n" "$1" >&2
- exit 1
- fi
-else
- patch=$(top_patch)
fi
+patch=$(find_series_patch "$1") || exit 1
+
previous=$(applied_before "$patch" | tail -n 1)
if [ -n "$previous" ]
then
--- quilt-files.orig/quilt/push.in
+++ quilt-files/quilt/push.in
@@ -231,17 +231,11 @@ list_patches()
n=$[$n+1]
fi
echo $patch
- if [ $patch = "$stop_at_patch" ]
+ if [ -z "$number" -a "$patch" = "$stop_at_patch" ]
then
break
fi
done
- if [ -n "$stop_at_patch" -a "$patch" != "$stop_at_patch" ]
- then
- printf $"Patch %s not found in file series\n" \
- "$stop_at_patch" >&2
- return 1
- fi
fi
}
@@ -307,31 +301,19 @@ then
then
number=$1
else
- if ! stop_at_patch=$(find_patch $1)
- then
- printf $"Patch %s is not in series\n" "$1" >&2
- exit 1
- fi
+ stop_at_patch="$1"
fi
else
[ -z "$opt_all" ] && number=1
fi
+stop_at_patch=$(find_pending_patch "$stop_at_patch") || exit 1
+
[ -n "$opt_quiet" ] && silent=-s
[ -z "$opt_verbose" ] && silent_unless_verbose=-s
[ -z "$opt_interactive" ] && force_apply=-f
[ -n "$opt_force" ] && opt_leave_rejects=1
-if [ -n "$stop_at_patch" ]
-then
- if is_applied $stop_at_patch
- then
- printf $"Patch %s is already applied\n" \
- "$(print_patch $stop_at_patch)" >&2
- exit 1
- fi
-fi
-
top=$(top_patch)
if [ -n "$top" -a -e $QUILT_PC/$top~refresh ]
then
@@ -340,21 +322,7 @@ then
exit 1
fi
-if ! patches=$(list_patches) 2>&1
-then
- exit 1
-elif [ -z "$patches" ]
-then
- if [ -z "$top" ]
- then
- printf $"No patches applied\n" >&2
- else
- printf $"File series fully applied, ends at patch %s\n" \
- "$(print_patch $top)" >&2
- fi
- exit 2
-fi
-
+patches=$(list_patches)
create_db
for patch in $patches
do
--- quilt-files.orig/quilt/refresh.in
+++ quilt-files/quilt/refresh.in
@@ -131,38 +131,14 @@ do
esac
done
-if [ $# -eq 1 ]
-then
- opt_patch=$1
-elif [ $# -gt 1 ]
+if [ $# -gt 1 ]
then
usage
fi
QUILT_DIFF_OPTS="$QUILT_DIFF_OPTS $opt_format"
-if [ -n "$opt_patch" ]
-then
- if ! patch=$(find_patch $opt_patch)
- then
- printf $"Patch %s is not in series\n" \
- "$(print_patch $opt_patch)" >&2
- exit 1
- fi
- if ! is_applied "$patch"
- then
- printf $"Patch %s is not applied\n" \
- "$(print_patch $patch)" >&2
- exit 1
- fi
-else
- patch=$(top_patch)
- if [ -z "$patch" ]
- then
- printf $"No patches applied\n" >&2
- exit 1
- fi
-fi
+patch=$(find_applied_patch "$1") || exit 1
if [ -z "$opt_strip_level" ]
then
--- quilt-files.orig/quilt/remove.in
+++ quilt-files/quilt/remove.in
@@ -48,11 +48,7 @@ while true
do
case "$1" in
-p)
- if ! patch=$(find_patch $2)
- then
- printf $"Patch %s is not in series\n" "$2" >&2
- exit 1
- fi
+ opt_patch="$2"
shift 2 ;;
-h)
usage -h ;;
@@ -67,21 +63,7 @@ then
usage
fi
-if [ -n "$patch" ]
-then
- if ! is_applied $patch
- then
- printf $"Patch %s is not applied\n" "$(print_patch $patch)" >&2
- exit 1
- fi
-else
- patch=$(top_patch)
- if [ -z "$patch" ]
- then
- printf $"No patches applied\n" >&2
- exit 1
- fi
-fi
+patch=$(find_applied_patch "$opt_patch") || exit 1
status=0
for file in $*
--- quilt-files.orig/quilt/rename.in
+++ quilt-files/quilt/rename.in
@@ -58,11 +58,7 @@ while true
do
case "$1" in
-p)
- if ! patch=$(find_patch $2)
- then
- printf $"Patch %s is not in series\n" "$2" >&2
- exit 1
- fi
+ opt_patch="$2"
shift 2 ;;
-h)
usage -h ;;
@@ -77,15 +73,7 @@ then
usage
fi
-if [ ! -n "$patch" ]
-then
- patch=$(top_patch)
- if [ -z "$patch" ]
- then
- printf $"No patches applied\n" >&2
- exit 1
- fi
-fi
+patch=$(find_series_patch "$opt_patch") || exit 1
new_patch=${1#$QUILT_PATCHES/}
--- quilt-files.orig/quilt/top.in
+++ quilt-files/quilt/top.in
@@ -57,13 +57,9 @@ then
usage
fi
-top=$(top_patch)
-if [ -n "$top" ]
-then
- echo "$(print_patch $top)"
-else
- exit 2
-fi
+top=$(find_top_patch) || exit 2
+echo "$(print_patch $top)"
+
### Local Variables:
### mode: shell-script
### End:
--- quilt-files.orig/quilt/unapplied.in
+++ quilt-files/quilt/unapplied.in
@@ -57,21 +57,18 @@ then
usage
elif [ $# -eq 1 ]
then
- if ! patch=$(find_patch $1)
- then
- printf $"Patch %s is not in series\n" "$1" >&2
- exit 1
- fi
+ start=$(find_series_patch "$1") || exit 1
+ patch=$(patch_after "$start")
+
+ [ -n "$start" -a -z "$patch" ] && exit
else
- patch=$(top_patch)
+ patch=$(find_pending_patch) || exit 1
fi
-if [ -z "$patch" ]
-then
- cat_series
-else
+(
+ echo "$patch"
patches_after $patch
-fi \
+) \
| while read patch
do
echo "$(print_patch $patch)"
--- quilt-files.orig/test/three.test
+++ quilt-files/test/three.test
@@ -5,20 +5,31 @@
$ touch e
$ quilt annotate e
+ > No patches in series
+
$ quilt top
+ > No patches in series
+
$ quilt next
+ > No patches in series
+
$ quilt previous
+ > No patches in series
+
$ quilt unapplied
+ > No patches in series
+
$ quilt applied
+ > No patches in series
$ quilt next patch1
- > Patch patch1 is not in series
+ > No patches in series
$ quilt push patch1
- > Patch patch1 is not in series
+ > No patches in series
$ quilt push
- > No patches applied
+ > No patches in series
$ quilt pop
> No patch removed
@@ -84,20 +95,26 @@
> No patches applied
$ quilt top
+ > No patches applied
+
$ quilt pop
> No patch removed
$ quilt applied
+ > No patches applied
+
$ quilt unapplied
> patches/patch1.diff
> patches/patch2.diff
$ quilt previous
+ > No patches applied
+
$ quilt next
> patches/patch1.diff
$ quilt applied patch1
- > Patch is not applied
+ > Patch patches/patch1.diff is not applied
$ quilt unapplied patch2
$ quilt unapplied patch1
@@ -139,7 +156,7 @@
$ echo patch3.diff >> %{P}/series
$ quilt diff -P patch1 --combine patch3
- > Patch patches/patch3.diff not applied before patch patches/patch1.diff
+ > Patch patches/patch3.diff is not applied
$ quilt pop -qaR
> Removing patch %{P}patch2.diff
@@ -147,7 +164,7 @@
> No patches applied
$ quilt annotate f
- > sed: can't read f: No such file or directory
+ > No patches applied
$ cd ../..
$ rm -rf d
--
John
- [Quilt-dev] [patch 0/6] select/merge documentation on import, jayvdb, 2005/09/26
- [Quilt-dev] [patch 6/6] select/merge documentation on import, jayvdb, 2005/09/26
- [Quilt-dev] [patch 1/6] select/merge documentation on import, jayvdb, 2005/09/26
- [Quilt-dev] [patch 4/6] select/merge documentation on import, jayvdb, 2005/09/26
- [Quilt-dev] [patch 5/6] select/merge documentation on import, jayvdb, 2005/09/26
- [Quilt-dev] [patch 3/6] select/merge documentation on import,
jayvdb <=
- [Quilt-dev] [patch 2/6] select/merge documentation on import, jayvdb, 2005/09/26