mq: untangle git patch detection
authorPatrick Mezard <pmezard@gmail.com>
Tue, 29 Dec 2009 16:00:29 +0100
changeset 10150 926c436964b4
parent 10149 fa7170d6529f
child 10151 c7355a0e1f39
mq: untangle git patch detection
hgext/mq.py
--- a/hgext/mq.py	Tue Dec 29 16:00:24 2009 +0100
+++ b/hgext/mq.py	Tue Dec 29 16:00:29 2009 +0100
@@ -1159,15 +1159,6 @@
             cparents = repo.changelog.parents(top)
             patchparent = self.qparents(repo, top)
             ph = patchheader(self.join(patchfn))
-
-            patchf = self.opener(patchfn, 'r')
-
-            # if the patch was a git patch, refresh it as a git patch
-            for line in patchf:
-                if line.startswith('diff --git'):
-                    self.diffopts().git = True
-                    break
-
             if msg:
                 ph.setmessage(msg)
             if newuser:
@@ -1175,12 +1166,17 @@
             if newdate:
                 ph.setdate(newdate)
 
+            # if the patch was a git patch, refresh it as a git patch
+            patchf = self.opener(patchfn, 'r')
+            for line in patchf:
+                if line.startswith('diff --git'):
+                    self.diffopts().git = True
+                    break
+            patchf.close()
+
             # only commit new patch when write is complete
             patchf = self.opener(patchfn, 'w', atomictemp=True)
 
-            patchf.seek(0)
-            patchf.truncate()
-
             comments = str(ph)
             if comments:
                 patchf.write(comments)