Commits

mdelagra  committed 3c90101 Merge

merging heads

  • Participants
  • Parent commits c4b32e7, f719d06

Comments (0)

Files changed (6)

File mercurial_reviewboard/__init__.py

     
     check_parent_options(opts)
 
+    c = repo.changectx(rev)
+
+    rparent = find_rparent(ui, repo, c, opts)        
+    parent  = find_parent(ui, repo, c, rparent, opts)
+
+    diff, parentdiff = create_review_data(ui, repo, c, parent, rparent)
+
+    send_review(ui, repo, c, parent, diff, parentdiff, opts)
+    
+def find_rparent(ui, repo, c, opts):
     outgoing = opts.get('outgoing')
     outgoingrepo = opts.get('outgoingrepo')
     master = opts.get('master')
     if master:
         rparent = repo[master]
     elif outgoingrepo:
-        rparent = remoteparent(ui, repo, rev, upstream=outgoingrepo)
+        rparent = remoteparent(ui, repo, c, upstream=outgoingrepo)
     elif outgoing:
-        rparent = remoteparent(ui, repo, rev)
+        rparent = remoteparent(ui, repo, c)
     else:
         rparent = None
+    return rparent
 
-    c = repo.changectx(rev)
-        
+def find_parent(ui, repo, c, rparent, opts):
     parent = opts.get('parent')
     outgoingchanges = opts.get('outgoingchanges')
     branch = opts.get('branch')
     elif branch:
         parent = find_branch_parent(ui, c)
     else:
-        parent = repo[rev].parents()[0]
+        parent = c.parents()[0]
+    return parent
 
-    ui.debug(_('Parent is %s\n' % parent))
-    ui.debug(_('Remote parent is %s\n' % rparent))
-
+def create_review_data(ui, repo, c, parent, rparent):
+    'Returns a tuple of the diff and parent diff for the review.'
     diff = getdiff(ui, repo, c, parent)
     ui.debug('\n=== Diff from parent to rev ===\n')
     ui.debug(diff + '\n')
         ui.debug(parentdiff + '\n')
     else:
         parentdiff = ''
-
-    send_review(ui, repo, c, parent, diff, parentdiff, opts)
+    return diff, parentdiff
+    
     
 def send_review(ui, repo, c, parentc, diff, parentdiff, opts):
     
     
     return fields
 
-def remoteparent(ui, repo, rev, upstream=None):
+def remoteparent(ui, repo, ctx, upstream=None):
     remotepath = expandpath(ui, upstream)
     remoterepo = hg.repository(ui, remotepath)
     out = repo.findoutgoing(remoterepo)
     for o in out:
         orev = repo[o]
-        a, b, c = repo.changelog.nodesbetween([orev.node()], [repo[rev].node()])
+        a, b, c = repo.changelog.nodesbetween([orev.node()], [ctx.node()])
         if a:
             return orev.parents()[0]
 

File mercurial_reviewboard/tests/diffs/two_revs_0

+diff -r 000000000000 -r a8ea53640b24 a
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/a	Sat Nov 07 09:50:35 2009 -0600
+@@ -0,0 +1,1 @@
++a

File mercurial_reviewboard/tests/diffs/two_revs_1

+diff -r a8ea53640b24 -r 669e757d4a24 b
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/b	Sat Nov 07 09:50:35 2009 -0600
+@@ -0,0 +1,1 @@
++b

File mercurial_reviewboard/tests/scripts/create_diffs_two_revs

+pushd ../repos/two_revs
+
+hg diff -r 00000 -r 0 > ../../diffs/two_revs_0
+
+hg diff -r 0     -r 1 > ../../diffs/two_revs_1

File mercurial_reviewboard/tests/test_no_parent_opts.py

+from mock import patch
+from nose.tools import eq_
+
+from mercurial_reviewboard import postreview
+from mercurial_reviewboard.tests import get_initial_opts, get_repo, mock_ui
+
+@patch('mercurial_reviewboard.send_review')
+def test_outgoing(mock_send):
+    ui = mock_ui()
+    repo = get_repo(ui, 'two_revs')
+    opts = get_initial_opts()
+    postreview(ui, repo, **opts)
+    
+    expected = open('mercurial_reviewboard/tests/diffs/two_revs_1', 'r').read()
+    eq_(expected, mock_send.call_args[0][4])

File mercurial_reviewboard/tests/test_remoteparent.py

     
     repo = get_repo(ui, 'two_revs')
     
-    parent = remoteparent(ui, repo, 1, upstream=child_repo_path)
+    parent = remoteparent(ui, repo, repo.changectx(1), upstream=child_repo_path)
     
     eq_('0000000000000000000000000000000000000000', parent.hex())