remove unecessary code in linediff()
[diff2html.git] / diff2html.py
index 5704270..3e52700 100644 (file)
@@ -20,6 +20,7 @@
 #
 # Authors: Olivier MATZ <zer0@droids-corp.org>
 #          Alan De Smet <adesmet@cs.wisc.edu>
+#          Sergey Satskiy <sergey.satskiy@gmail.com>
 #
 # Inspired by diff2html.rb from Dave Burt <dave (at) burt.id.au>
 # (mainly for html theme)
@@ -32,7 +33,7 @@
 #   and display those directly.
 
 
-import sys, re, htmlentitydefs, getopt
+import sys, re, htmlentitydefs, getopt, StringIO
 
 # minimum line size, we add a zero-sized breakable space every
 # LINESIZE characters
@@ -105,7 +106,6 @@ def linediff(s, t):
 
     m, n = len(s), len(t)
     d = [[(0, 0) for i in range(n+1)] for i in range(m+1)]
-    x = [[(0, 0) for i in range(n+1)] for i in range(m+1)]
 
 
     d[0][0] = (0, (0, 0))
@@ -308,10 +308,12 @@ def parse_input(input_file, output_file,
         if m:
             empty_buffer(output_file)
             file1 = m.groups()[0]
-            l = input_file.readline()
-            m = re.match('^\+\+\+ ([^\s]*)', l)
-            if m:
-                file2 = m.groups()[0]
+            while True:
+                l = input_file.readline()
+                m = re.match('^\+\+\+ ([^\s]*)', l)
+                if m:
+                    file2 = m.groups()[0]
+                    break
             add_filename(file1, file2, output_file)
             hunk_off1, hunk_size1, hunk_off2, hunk_size2 = 0, 0, 0, 0
             continue
@@ -395,7 +397,6 @@ def main():
         print str(err) # will print something like "option -a not recognized"
         usage()
         sys.exit(2)
-    output = None
     verbose = False
     for o, a in opts:
         if o in ("-h", "--help"):
@@ -420,6 +421,13 @@ def main():
     parse_input(input_file, output_file,
                 exclude_headers, show_hunk_infos)
 
+def parse_from_memory(txt, exclude_headers, show_hunk_infos):
+    " Parses diff from memory and returns a string with html "
+    input_stream = StringIO.StringIO(txt)
+    output_stream = StringIO.StringIO()
+    parse_input(input_stream, output_stream, exclude_headers, show_hunk_infos)
+    return output_stream.getvalue()
+
 
 if __name__ == "__main__":
     main()