quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [PATCH v2] push: Check for duplicate patch in series


From: Jean Delvare
Subject: [Quilt-dev] [PATCH v2] push: Check for duplicate patch in series
Date: Thu, 27 Feb 2014 17:27:08 +0100

In the case of a generated or manually tweaked series file, it can
happen that the same patch shows up twice in the series file. Check
for this before pushing any patch, otherwise we would corrupt quilt's
internal database.

This fixes bug #20628:
https://savannah.nongnu.org/bugs/?20628
---
Changes since v1:
* Different implementation, checking for all duplicates before applying
  the first patch. This solves the performance regression.

 quilt/push.in                       |   24 +++++++++++++++++++++++
 test/duplicate-patch-in-series.test |   37 ++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

--- a/quilt/push.in
+++ b/quilt/push.in
@@ -275,6 +275,24 @@ list_patches()
        fi
 }
 
+check_duplicate_patches()
+{
+       local IFS=$'\n'
+       local -a duplicates
+       local patch
+
+       duplicates=($((applied_patches ; printf $'%s\n' "address@hidden") \
+                     | awk '{ if (lines[$0]++ == 1) print }'))
+       [ address@hidden -ge 1 ] || return 0
+
+       for patch in "address@hidden"
+       do
+               printf $"Patch %s is already applied; check your series file\n" 
\
+                      "$(print_patch "$patch")"
+       done
+       return 1
+}
+
 options=`getopt -o fqvam::h --long fuzz:,merge::,leave-rejects,color:: -- "$@"`
 
 if [ $? -ne 0 ]
@@ -380,6 +398,12 @@ then
 fi
 
 patches=$(list_patches)
+
+# In theory, these patches can't be already applied. However in the case
+# of a generated or manually tweaked series file, this could happen and
+# cause havoc, so play it safe and check.
+check_duplicate_patches || exit 1
+
 create_db
 for patch in $patches
 do
--- /dev/null
+++ b/test/duplicate-patch-in-series.test
@@ -0,0 +1,37 @@
+# Check that duplicate patches in generated series files won't cause havoc
+# See bug #20628 at https://savannah.nongnu.org/bugs/?20628
+
+$ mkdir patches
+$ echo "old line" > file.txt
+
+$ cat > patches/first.patch
+< --- file.txt
+< +++ file.txt
+< @@ -1 +1 @@
+< -old line
+< +new line
+
+$ cat > patches/series
+< first.patch -p0
+< first.patch -p0
+
+$ quilt push
+> Applying patch %{P}first.patch
+> patching file file.txt
+>
+> Now at patch %{P}first.patch
+
+$ quilt push
+> Patch %{P}first.patch is already applied; check your series file
+
+$ quilt pop
+> Removing patch %{P}first.patch
+> Restoring file.txt
+>
+> No patches applied
+
+$ quilt push -qa
+> Patch %{P}first.patch is already applied; check your series file
+
+$ quilt pop -q
+> No patch removed


-- 
Jean Delvare
Suse L3 Support




reply via email to

[Prev in Thread] Current Thread [Next in Thread]