Commits

martin.v.loewis  committed 6cfbfac

Support branch on hgrepos.

  • Participants
  • Parent commits 03f8ec1

Comments (0)

Files changed (3)

File extensions/create_patch.py

 class NotChanged(ValueError):
     pass
 
-def download_patch(source, lastrev):
+def download_patch(source, lastrev, patchbranch):
     from mercurial import hg, ui, localrepo, commands, bundlerepo
     UI = ui.ui()
     bundle = tempfile.mktemp(dir="/var/tmp")
         repo0.ui.quiet=True
         repo0.ui.pushbuffer()
         commands.pull(repo0.ui, repo0, quiet=True)
-        commands.update(repo0.ui, repo0)
         repo0.ui.popbuffer() # discard all pull output
+        # find out what the head revision of the given branch is
         repo0.ui.pushbuffer()
-        if commands.incoming(repo0.ui, repo0, source=source, branch=['default'], bundle=bundle, force=False) != 0:
+        head = repo0.ui.popbuffer().strip()
+        repo0.ui.pushbuffer()
+        if commands.incoming(repo0.ui, repo0, source=source, branch=[patchbranch], bundle=bundle, force=False) != 0:
             raise ValueError, "Repository contains no changes"
         rhead = repo0.ui.popbuffer()
         if rhead:
             raise NotChanged
         repo=bundlerepo.bundlerepository(UI, ".", bundle)
         repo.ui.pushbuffer()
-        commands.diff(repo.ui, repo, rev=['ancestor(.,default)', 'default'])
+        old = 'max(p1(min(outgoing() and branch(%s))) or p2(max(merge() and outgoing() and branch(%s))))' % (patchbranch, patchbranch)
+        commands.diff(repo.ui, repo, rev=[old, patchbranch])
         result = repo.ui.popbuffer()
     finally:
         os.chdir(cwd)
             self.client.error_message.append('unknown hgrepo url')
             return
         lastrev = db.hgrepo.get(repo, 'lastrev')
+        branch = db.hgrepo.get(repo, 'patchbranch')
+        if not branch:
+            branch = 'default'
         try:
-            diff, head = download_patch(url, lastrev)
+            diff, head = download_patch(url, lastrev, branch)
         except NotChanged:
             self.client.error_message.append('%s.diff is already available' % lastrev)
             return

File html/issue.item.html

 </table>
 
 <table class="files" tal:condition="context/hgrepos">
- <tr><th class="Header" colspan="2">Repositories containing patches</th></tr>
+ <tr><th class="Header" colspan="4">Repositories containing patches</th></tr>
  <tr tal:repeat="hgrepo python:context.hgrepos.sorted('creation')">
   <td>
    <a tal:attributes="href hgrepo/url"
-      tal:content="hgrepo/url">link</a>
+      tal:content="hgrepo/url">link</a><tal:block 
+        tal:condition="hgrepo/patchbranch">:<a 
+        tal:attributes="href string:${hgrepo/url}/shortlog/${hgrepo/patchbranch}"
+        tal:content="hgrepo/patchbranch"/>
+   </tal:block>
+  </td>
+  <td><tal:block tal:condition="hgrepo/is_edit_ok"><a
+          tal:attributes="href string:hgrepo${hgrepo/id}">edit</a> (change branch)
+      </tal:block>
+  </td>
+  <td>
+   <form style="padding:0" method="post" tal:condition="hgrepo/is_edit_ok"
+         tal:attributes="action string:issue${context/id}">
+    <input type="hidden" name="@remove@files" tal:attributes="value hgrepo/id">
+    <input type="hidden" name="@action" value="edit">
+    <input type="submit" value="Remove">
+   </form>
   </td>
   <td>
    <form style="padding:0" method="post" tal:condition="context/is_edit_ok"
                  patchset=String(),)
 
 hgrepo = Class(db, "hgrepo",
-                   url=String(),
-                   lastrev=String())
+               url=String(),
+               lastrev=String(),
+               patchbranch=String(),
+               )
 
 # IssueClass automatically gets these properties in addition to the Class ones:
 #   title = String()
     db.security.addPermissionToRole('User', 'View', cl)
     db.security.addPermissionToRole('Anonymous', 'View', cl)
 
+def may_edit_hgrepo(db, userid, itemid):
+    return userid == db.hgrepo.get(itemid, "creator")
 db.security.addPermissionToRole('User', 'Create', 'hgrepo')
-p = db.security.addPermission(name='Edit', klass='hgrepo',
-                              properties=['url'])
+p = db.security.addPermission(name='Edit', klass='hgrepo', check=may_edit_hgrepo,
+                              properties=['url', 'patchbranch'])
 db.security.addPermissionToRole('User', p)
 
 class may_view_spam:
 # Coordinator permissions
 ##########################
 for cl in ('issue_type', 'severity', 'component',
-           'version', 'priority', 'stage', 'status', 'resolution', 'issue', 'file', 'msg'):
+           'version', 'priority', 'stage', 'status', 'resolution', 'issue', 
+           'file', 'msg', 'hgrepo'):
     db.security.addPermissionToRole('Coordinator', 'View', cl)
     db.security.addPermissionToRole('Coordinator', 'Edit', cl)
     db.security.addPermissionToRole('Coordinator', 'Create', cl)