[QBZR/Merge] Add unidiff format to diff dialog

Alexander Belchenko bialix at ukr.net
Thu Oct 18 13:50:03 BST 2007


Alexander Belchenko пишет:
> Goffredo Baroncelli пишет:
>> I worked a bit on my patch:
>> - now the _() function should translate correctly
>> - the unidiff diff should be english only (for the moment)
>>
>> I didn't touched the po/po.* files, because I don't know how gettext 
>> work.
>>
>> Please Alexander give me a feedback. 
> 
> IMO, we don't need special dictionary to transform english status
> words to translated ones. Instead we need to use function i18n.N_()
> that provide non-translated string, and use i18n._() when we need
> translations.
> 
> Attached the diff against your last patch and complete patch against
> Lukas' main branch.
> I'm also added blank line between files in unidiff output.

I just realized that blank line between files in unidiff use last 
background color of last line. I think it better to have it always
with default color (i.e. white), so I slightly change code again.
Also, using += for strings is slow, so I changed your code to
use list.append method.

=== modified file 'diff.py'
--- diff.py	2007-10-18 08:27:28 +0000
+++ diff.py	2007-10-18 12:39:52 +0000
@@ -220,18 +220,19 @@
              '=':   'background-color:#c5e3f7; color:black',
          }
          defaultstyle = 'background-color:#ffffff; color=black',
-        res ='<span style="font-size:12px">'
+        res = ['<span style="font-size:12px">']
          keys = style.keys( )
          keys.sort(reverse=True) # so '---' is before '-'
          for l in self.unidiff_list(lineterm=''):
              for k in keys:
                  if l.startswith(k):
-                    res += markup_line(l, style[k])
+                    res.append(markup_line(l, style[k]))
                      break
              else:
-                res += markup_line(l, defaultstyle)
-        res += '</span>'
-        return res
+                res.append(markup_line(l, defaultstyle))
+        res.append('</span>')
+        res.append(markup_line('', defaultstyle))   # blank line 
between files
+        return ''.join(res)

      def html_side_by_side(self):
          """Make HTML for side-by-side diff view."""
@@ -371,7 +372,6 @@
          res = []
          for diff in self:
              res.append(diff.html_unidiff())
-            res.append('<br/>')             # blank line between files
          return ''.join(res)

      def html_side_by_side(self):



Latest version of the code available at launchpad:
https://code.launchpad.net/~bialix/qbzr/qbzr.bialix

Lukas, what you think about this version?
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: diff.use.N_.v2.patch
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20071018/573d6eed/attachment-0001.diff 


More information about the bazaar mailing list