Commits

Anonymous committed 1b76481

add support for uploading local diffs

Comments (0)

Files changed (1)

mercurial_reviewboard/__init__.py

                      "(type 'hg out'). Or did you forget to commit ('hg st')?")
         raise util.Abort(msg)
 
-    diff, parentdiff = create_review_data(ui, repo, c, parent, rparent)
+    # read diff and parentdiff from CLI switches if provided;
+    # if they're not provided, generate a diff based on other parameters provided
+    diff = getdiff_from_filename(opts.get('diff'))
+    parentdiff = getdiff_from_filename(opts.get('parentdiff'))
+    if diff is None or parentdiff is None:
+        diff_derived, parentdiff_derived = create_review_data(ui, repo, c, parent, rparent)
+        if diff is None:
+            diff = diff_derived
+        if parentdiff is None:
+            parentdiff = parentdiff_derived
 
     send_review(ui, repo, c, parent, diff, parentdiff, opts)
     
     for chunk in patch.diff(repo, parent.node(), r.node()):
         output += chunk
     return output
+    
+def getdiff_from_filename(filename):
+    '''reads a file and returns it'''
+    if filename is None or len(filename) == 0:
+        return None
+    diff_file = open(filename, 'r')
+    return diff_file.read()
 
 def getreviewboard(ui, opts):
     
             _('comma separated list of groups needed to review the code')),
         ('B', 'bugs_closed', '', 
             _('comma separated list of bug IDs addressed by the change')),
+        ('d', 'diff', '', 
+            _('path to the diff to be posted')),
+        ('D', 'parentdiff', '', 
+            _('path to the parent diff to be posted')),
         ('', 'username', '', _('username for the ReviewBoard site')),
         ('', 'password', '', _('password for the ReviewBoard site')),
         ('', 'apiver', '', _('ReviewBoard API version (e.g. 1.0, 2.0)')),