convert/gnuarch: fix cat-log parsing
authorEdouard Gomez <ed.gomez@free.fr>
Sun, 04 Jan 2009 02:36:48 +0100
changeset 7578 7971650bdc73
parent 7577 bd96fcb696d8
child 7579 a8db971dc258
convert/gnuarch: fix cat-log parsing cat-log parsing was very wrong. It assumed the Summary header was comming last, which is wrong. Plus the code was buggy because it was concatenating all headers in the summary. As parsing GNU Arch isn't trivial, and python email code does it so well... just use that ;-)
hgext/convert/gnuarch.py
--- a/hgext/convert/gnuarch.py	Sun Jan 04 02:36:48 2009 +0100
+++ b/hgext/convert/gnuarch.py	Sun Jan 04 02:36:48 2009 +0100
@@ -4,6 +4,7 @@
 from mercurial.i18n import _
 from mercurial import util
 import os, shutil, tempfile, stat
+from email.Parser import Parser
 
 class gnuarch_source(converter_source, commandline):
 
@@ -46,6 +47,7 @@
         self.parents = {}
         self.tags = {}
         self.modecache = {}
+        self.catlogparser = Parser()
 
     def before(self):
         if self.execmd == 'tla':
@@ -70,7 +72,7 @@
             self.changes[rev] = self.gnuarch_rev(rev)
 
             # Read author, date and summary
-            catlog = self.runlines0('cat-log', '-d', self.path, rev)
+            catlog = self.run0('cat-log', '-d', self.path, rev)
             self._parsecatlog(catlog, rev)
 
             self.parents[rev] = child
@@ -229,20 +231,15 @@
         return path
 
     def _parsecatlog(self, data, rev):
-        summary = []
-        for l in data:
-            l = l.strip()
-            if summary:
-                summary.append(l)
-            elif l.startswith('Summary:'):
-                summary.append(l[len('Summary: '):])
-            elif l.startswith('Standard-date:'):
-                date = l[len('Standard-date: '):]
-                strdate = util.strdate(date, '%Y-%m-%d %H:%M:%S')
-                self.changes[rev].date = util.datestr(strdate)
-            elif l.startswith('Creator:'):
-                self.changes[rev].author = l[len('Creator: '):]
-        self.changes[rev].summary = '\n'.join(summary)
+        try:
+            catlog = self.catlogparser.parsestr(data)
+            self.changes[rev].date = util.datestr(
+                util.strdate(catlog['Standard-date'],
+                             '%Y-%m-%d %H:%M:%S'))
+            self.changes[rev].author = catlog['Creator']
+            self.changes[rev].summary = catlog['Summary']
+	except Exception, err:
+            raise util.Abort(_('could not parse cat-log of %s') % rev)
 
     def _parsechangeset(self, data, rev):
         for l in data: