quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] Re: [PATCH 2/4] Protect pending header edits


From: Don Mullis
Subject: [Quilt-dev] Re: [PATCH 2/4] Protect pending header edits
Date: Sun, 11 Apr 2010 20:39:27 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Protect pending `quilt header -e' edits from commands that can remove
the patch being edited from the patch stack, or otherwise cause the
edited header to land in an unexpected place.  Abort such commands,
with the exceptions of `quilt delete -f` and `quilt pop -f`.

Those commands are:
     delete (without -f) 
         treat pending header edit like refreshed body change
     fork
         pending edits are typically intended for the latest patch
         revision, on the stack.
     pop (without -f)
         treat pending header edit like refreshed body change
     rename
         avoids creation of corrupt patches containing only the edited header.

---
 quilt/delete.in           |   18 ++++++++++++
 quilt/fork.in             |    5 +++
 quilt/header.in           |   33 +++++++++++++++++++++++
 quilt/pop.in              |   13 +++++++++
 quilt/rename.in           |    5 +++
 quilt/scripts/patchfns.in |   14 ++++++++++
 test/header.test          |   64 ++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 150 insertions(+), 2 deletions(-)

Index: quilt/quilt/header.in
===================================================================
--- quilt.orig/quilt/header.in  2010-02-21 22:12:47.000000000 -0800
+++ quilt/quilt/header.in       2010-02-21 22:21:38.000000000 -0800
@@ -132,6 +132,11 @@ then
        | maybe_strip_diffstat \
        | maybe_strip_trailing_whitespace
 else
+       if editor_was_opened $patch
+       then
+               exit 1
+       fi
+
        patch_file_or_null=/dev/null
        [ -e "$patch_file" ] && patch_file_or_null=$patch_file
 
@@ -151,7 +156,33 @@ else
 
        if [ -n "$opt_edit" ]
        then
-               LANG=$ORIGINAL_LANG $EDITOR "$tmp" || exit 1
+               # If this script is killed before its editor child exits,
+               # the ~editor_opened file will be left dangling.
+               # Trust the user to notice that a 'quilt pop -f' recovers
+               # from this state.
+
+               touch $QUILT_PC/$patch~editor_opened
+               LANG=$ORIGINAL_LANG $EDITOR "$tmp"
+               editor_status=$?
+
+               # If, OTOH, the user does a 'quilt pop -f', then
+               # closes the editor normally, this script won't
+               # find ~editor_opened and doesn't know where to put
+               # the new header.
+               if ! [ -e $QUILT_PC/$patch~editor_opened ]
+               then
+                       printf "Patch %s has disappeared out from under 'quilt 
header -e' session.
+Edited header may be found in %s\n" "$patch" "$tmp"
+                       exit 1
+               fi
+               rm $QUILT_PC/$patch~editor_opened
+
+               if ! [ $editor_status = 0 ]
+               then
+                       printf "Editing session for header of patch %s seems to 
have crashed.
+Abandoning changes in %s\n" "$patch" "$tmp"
+                       exit 1
+               fi
        fi
 
        maybe_strip_diffstat < $tmp \
Index: quilt/quilt/pop.in
===================================================================
--- quilt.orig/quilt/pop.in     2010-02-21 22:12:47.000000000 -0800
+++ quilt/quilt/pop.in  2010-02-21 22:30:04.000000000 -0800
@@ -151,6 +151,19 @@ remove_patch()
                check_for_pending_changes $patch || status=1
        fi
 
+       if editor_was_opened $patch
+       then
+               if [ -n "$opt_force" ]
+               then
+                       printf $"Popping patch %s anyway due to -f\n" \
+                       "$(print_patch $patch)" >&2
+                       rm -f $QUILT_PC/$patch~editor_opened
+               else
+                       rm -rf $workdir
+                       status=1
+               fi
+       fi
+
        if [ $status -eq 0 ]
        then
                rm -f "$QUILT_PC/$patch/.timestamp"
Index: quilt/test/header.test
===================================================================
--- quilt.orig/test/header.test 2010-02-21 22:12:47.000000000 -0800
+++ quilt/test/header.test      2010-02-21 22:30:52.000000000 -0800
@@ -42,3 +42,67 @@
        > @@ -1 +1 @@
        > -foo
        > +bar
+
+       $ touch .pc/patch~editor_opened
+
+       $ quilt pop
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+
+       $ quilt delete
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+
+       $ quilt rename new_name
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+
+       $ quilt fork
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+
+       $ quilt header -e
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+
+       $ quilt header -a
+       < text to be appended
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+
+       $ quilt pop -f
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+       > Popping patch %{P}patch anyway due to -f
+       > Removing patch %{P}patch
+       > Restoring foo
+       >
+       > No patches applied
+
+       # Test editing the header of a patch beyond the TOS
+       # ---
+       $ touch .pc/patch~editor_opened
+
+       $ quilt rename -P patch new_name
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+
+       $ quilt delete patch
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+
+       $ quilt delete -f patch
+       > A `quilt header -e` session for this patch may still be running --
+       > implied by existence of file
+       >     .pc/patch~editor_opened
+       > Deleting patch %{P}patch anyway due to -f
+       > Removed patch %{P}patch
Index: quilt/quilt/fork.in
===================================================================
--- quilt.orig/quilt/fork.in    2010-02-21 22:12:47.000000000 -0800
+++ quilt/quilt/fork.in 2010-02-21 22:21:38.000000000 -0800
@@ -86,6 +86,11 @@ then
        exit 1
 fi
 
+if editor_was_opened $top_patch
+then
+       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" || \
Index: quilt/quilt/rename.in
===================================================================
--- quilt.orig/quilt/rename.in  2010-02-21 22:12:47.000000000 -0800
+++ quilt/quilt/rename.in       2010-02-21 22:21:38.000000000 -0800
@@ -86,6 +86,11 @@ then
        exit 1
 fi
 
+if editor_was_opened $patch
+then
+       exit 1
+fi
+
 if ( is_applied $patch && \
      ( ! rename_in_db "$patch" "$new_patch" || \
        ! move_file "$QUILT_PC/$patch" \
Index: quilt/quilt/delete.in
===================================================================
--- quilt.orig/quilt/delete.in  2010-02-21 22:12:47.000000000 -0800
+++ quilt/quilt/delete.in       2010-02-21 22:21:38.000000000 -0800
@@ -72,7 +72,11 @@ do
        --backup)
                QUILT_BACKUP=1
                shift ;;
-       -f | -R)
+       -f)
+               opt_force=1
+               opt_pop="${opt_pop+$opt_pop }$1"
+               shift ;;
+       -R)
                opt_pop="${opt_pop+$opt_pop }$1"
                shift ;;
        --)
@@ -118,6 +122,18 @@ if is_applied "$patch"; then
        fi
 fi
 
+if editor_was_opened $patch
+then
+       if [ -n "$opt_force" ]
+       then
+               printf $"Deleting patch %s anyway due to -f\n" \
+               "$(print_patch $patch)" >&2
+               rm -f $QUILT_PC/$patch~editor_opened
+       else
+               exit 1
+       fi
+fi
+
 if remove_from_series "$patch"
 then
        printf $"Removed patch %s\n" "$(print_patch "$patch")"
Index: quilt/quilt/scripts/patchfns.in
===================================================================
--- quilt.orig/quilt/scripts/patchfns.in        2010-02-21 22:12:47.000000000 
-0800
+++ quilt/quilt/scripts/patchfns.in     2010-02-21 22:30:04.000000000 -0800
@@ -943,6 +943,20 @@ apply_patch_temporarily()
        fi
 }
 
+editor_was_opened()
+{
+       local patch=$1
+
+       if [ -e $QUILT_PC/$patch~editor_opened ]
+       then
+               printf $"A \`quilt header -e\` session for this patch may still 
be running --\n" >&2
+               printf $"implied by existence of file\n    %s\n" \
+                              "$QUILT_PC/$patch~editor_opened" >&2
+               return 0
+       fi
+       return 1
+}
+
 next_filename()
 {
        local patch=$1 base num




reply via email to

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