changeset 10150:926c436964b4

mq: untangle git patch detection
author Patrick Mezard <pmezard@gmail.com>
date Tue, 29 Dec 2009 16:00:29 +0100
parents fa7170d6529f
children c7355a0e1f39
files hgext/mq.py
diffstat 1 files changed, 8 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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)