[PATCH] transplant: fix crash if filter script munges log file

Luke Plant L.Plant.98 at cantab.net
Mon Mar 28 15:46:29 CDT 2011


# HG changeset patch
# User Luke Plant <L.Plant.98 at cantab.net>
# Date 1301343452 -3600
# Node ID 7e5031180c0fbe737c18a6cabda66ffcd6959688
# Parent  307c72686eb0c336db0e20143a76edb211e9bba8
transplant: fix crash if filter script munges log file

This fixes an UnboundLocalError crash if the filter script removes the
'User' or 'Date' lines from the log file.

diff -r 307c72686eb0 -r 7e5031180c0f hgext/transplant.py
--- a/hgext/transplant.py	Mon Mar 28 11:18:56 2011 -0500
+++ b/hgext/transplant.py	Mon Mar 28 21:17:32 2011 +0100
@@ -346,6 +346,8 @@
         message = []
         node = revlog.nullid
         inmsg = False
+        user = None
+        date = None
         for line in fp.read().splitlines():
             if inmsg:
                 message.append(line)
@@ -360,6 +362,8 @@
             elif not line.startswith('# '):
                 inmsg = True
                 message.append(line)
+        if None in (user, date):
+            raise util.Abort(_("filter produced garbled log file"))
         return (node, user, date, '\n'.join(message), parents)
 
     def log(self, user, date, message, p1, p2, merge=False):
diff -r 307c72686eb0 -r 7e5031180c0f tests/test-transplant.t
--- a/tests/test-transplant.t	Mon Mar 28 11:18:56 2011 -0500
+++ b/tests/test-transplant.t	Mon Mar 28 21:17:32 2011 +0100
@@ -363,6 +363,19 @@
   Transplant from rev 17ab29e464c6ca53e329470efe2a9918ac617a6f
   $ cd ..
 
+test transplant with filter handles invalid changelog
+
+  $ hg init filter-invalid-log
+  $ cd filter-invalid-log
+  $ cat <<'EOF' >test-filter-invalid-log
+  > #!/bin/sh
+  > echo "" > $1
+  > EOF
+  $ chmod +x test-filter-invalid-log
+  $ hg transplant -s ../t --filter ./test-filter-invalid-log 0
+  filtering * (glob)
+  abort: filter failed
+  [255]
 
 test with a win32ext like setup (differing EOLs)
 


More information about the Mercurial-devel mailing list