[PATCH] mq:fix qrefresh problem for hg exported patch

Xiaofeng Ling xiaofeng.ling at intel.com
Tue Sep 13 03:24:32 CDT 2005


Chris
      This patch fix mq qrefresh problme with hg patch information.	
mq qrefresh does not deal with the hg patch information
like mq qpush, so after mq qrefresh, the comments will become
"# HG changeset patch"

diff -r 6809b2e04cdb contrib/mq
--- a/contrib/mq	Tue Sep 13 06:02:28 2005
+++ b/contrib/mq	Tue Sep 13 14:09:02 2005
@@ -420,21 +420,35 @@
              sys.exit(1)
          parents = repo.changelog.parents(top)
          comments = []
+        text = []
+        format = None
          try:
              patchf = self.opener(os.path.join(self.path, patch))
              while(True):
                  l = patchf.readline()
                  if not l or l.startswith('Index:') or 
re.match('=====.*vs.*=====', l) or l.startswith('---'):
                      break
-                comments.append(l)
+                self.ui.write("line:%s" % l)
+                if l.startswith('# HG changeset patch'):
+                    format = "hgpatch"
+                if format == "hgpatch":
+                    if l.startswith("# User "):
+                        user = l[7:]
+                    elif not l.startswith("# ") and l:
+                        comments.append(l)
+                        format = None
+                else:
+                    comments.append(l)
+                text.append(l)
              if comments and re.match('diff', comments[-1]):
                  del comments[-1]
+            if text and re.match('diff', text[-1]):
+                del text[-1]
          except IOError: pass

          patchf = self.opener(os.path.join(self.path, patch), "w")
-        text = None
-        if comments:
-            text = "".join(comments)
+        if text:
+            text = "".join(text)
              patchf.write(text)

          tip = repo.changelog.tip()
@@ -498,9 +512,12 @@
              repo.dirstate.update(c, 'n')
              repo.dirstate.forget(forget)

-            if not text: text = "patch queue: %s\n" % patch
+            if not comments:
+                comments = "patch queue: %s\n" % patch
+            else:
+                comments = "".join(comments)
              self.strip(repo, top, update=False, cache=cache)
-            n = repo.commit(filelist, text, changes[1], force=1)
+            n = repo.commit(filelist, comments, changes[1], force=1)
              self.applied[-1] = revlog.hex(n) + ':' + patch
              self.applied_dirty = 1
          else:


More information about the Mercurial mailing list