Commits

Steve Borho  committed 30ea031

hggtk: string.splitlines() can return empty arrays

Fixes #568

  • Participants
  • Parent commits af92edc
  • Branches stable

Comments (0)

Files changed (5)

File hggtk/backout.py

     def revdesc(self, repo, revid):
         ctx = repo[revid]
         revstr = str(ctx.rev())
-        summary = hglib.toutf(hglib.tounicode(ctx.description()) \
-                .replace(u'\0', '').splitlines()[0][:80])
+        text = hglib.tounicode(ctx.description()).replace(u'\0', '')
+        lines = text.splitlines()
+        summary = hglib.toutf(lines and lines[0][:80] or '')
         escape = gtklib.markup_escape_text
         desc =  '<b>' + hglib.fromutf(_('rev')) + '</b>\t\t: %s\n' % escape(revstr)
         desc += '<b>' + hglib.fromutf(_('summary')) + '</b>\t: %s\n' % escape(summary)

File hggtk/changeset.py

         title_line(_('user/date:'), ctx.user() + '\t' + date, 'changeset')
         for pctx in ctx.parents():
             try:
-                summary = pctx.description().splitlines()[0]
-                summary = toutf(summary)
+                lines = pctx.description().splitlines()
+                summary = toutf(lines and lines[0] or '')
             except:
                 summary = ""
             change = str(pctx.rev()) + ' : ' + str(pctx)
             buf.insert(eob, "\n")
         for cctx in ctx.children():
             try:
-                summary = cctx.description().splitlines()[0]
-                summary = toutf(summary)
+                lines = cctx.description().splitlines()
+                summary = toutf(lines and lines[0] or '')
             except:
                 summary = ""
             change = str(cctx.rev()) + ' : ' + str(cctx)

File hggtk/commit.py

         self.update_recent_messages()
 
     def update_recent_messages(self, msg=None):
-        if msg is not None:
+        if msg:
             self._mru_messages.add(msg)
             self.settings.write()
             if self.popupid is not None: return
         liststore = self.msg_cbbox.get_model()
         liststore.clear()
         for msg in self._mru_messages:
+            if not msg: continue
             sumline = hglib.toutf(hglib.tounicode(msg).splitlines()[0])
             liststore.append([sumline, msg])
 

File hggtk/datamine.py

         ctx = self.repo[rev]
         author = hglib.toutf(util.shortuser(ctx.user()))
         date = hglib.toutf(hglib.displaytime(ctx.date()))
-        summary = gtklib.markup_escape_text(hglib.toutf(hglib.tounicode(
-                ctx.description()).replace(u'\0', '').splitlines()[0]))
+        text = hglib.tounicode(ctx.description()).replace(u'\0', '')
+        lines = text.splitlines()
+        summary = gtklib.markup_escape_text(lines and lines[0] or '')
         desc = '%s@%s %s "%s"' % (author, rev, date, summary)
         self.changedesc[rev] = (desc, author)
         return (desc, author)

File hggtk/merge.py

     def revdesc(self, repo, revid):
         ctx = repo[revid]
         revstr = str(ctx.rev())
-        summary = hglib.toutf(hglib.tounicode(ctx.description()) \
-                .replace(u'\0', '').splitlines()[0][:80])
+        text = hglib.tounicode(ctx.description()).replace(u'\0', '')
+        lines = text.splitlines()
+        summary = hglib.toutf(lines and lines[0][:80] or '')
         escape = gtklib.markup_escape_text
         desc =  '<b>' + hglib.fromutf(_('rev')) + '</b>\t\t: %s\n' % escape(revstr)
         desc += '<b>' + hglib.fromutf(_('summary')) + '</b>\t: %s\n' % escape(summary)