pgtoolkit/pgdiff.py
changeset 94 a10f553e6f6a
parent 87 3ef717ee9253
--- a/pgtoolkit/pgdiff.py	Tue Dec 10 11:39:57 2013 +0100
+++ b/pgtoolkit/pgdiff.py	Tue Feb 04 16:10:04 2014 +0100
@@ -137,13 +137,15 @@
 
 
 class DiffFunction(DiffBase):
-    def __init__(self, change, schema, function, show_body_diff=False):
+    def __init__(self, change, schema, function, definition, show_body_diff=False):
         DiffBase.__init__(self)
         self.level = 1
         self.type = 'function'
         self.change = change
         self.schema = schema
         self.function = function
+        #: New function definition
+        self.definition = definition
         self.name = function
         self.show_body_diff = show_body_diff
 
@@ -168,6 +170,9 @@
                     highlight(1,15), b, highlight(0), '.']))
         return ' '.join(res)
 
+    def format_patch(self):
+        return [self.definition]
+
 
 class DiffColumn(DiffBase):
     ALTER_COMMANDS = {
@@ -484,7 +489,13 @@
         for nd in self._diff_names(src_functions, dst_functions):
             if not self._test_function(nd[1]):
                 continue
-            fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1], show_body_diff=self.function_body_diff)
+            if nd[1] in dst_functions:
+                dst_definition = dst_functions[nd[1]].definition
+            else:
+                dst_definition = None
+            fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1],
+                               definition=dst_definition,
+                               show_body_diff=self.function_body_diff)
             if nd[0] == '*':
                 # compare function body and result
                 a = src_functions[nd[1]]