Takumi IINO avatar Takumi IINO committed 8b101d8

Add a bbcompare command to get bitbucket link to compare view

Comments (0)

Files changed (1)

     from mercurial.sshpeer import instance as sshrepo_instance
 from mercurial import hg, url, commands, util, \
-     error, extensions
+     error, extensions, scmutil
 import os
 import base64
+def bb_compare(ui, repo, *revs, **opts):
+    '''display a bitbucket link to compare view'''
+    reponame = get_bbreponame(ui, repo, opts)
+    revs = list(revs)
+    revs.extend(opts['rev'])
+    if not revs:
+        raise util.Abort('no revisions specified')
+    revs = scmutil.revrange(repo, revs)
+    if len(revs) == 1:
+        nodeid = str(repo[None])
+        if nodeid.endswith('+'):
+            # our wc is dirty, just take the node id and be happy
+            nodeid = nodeid[:-1]
+        revs = scmutil.revrange(repo, revs + [nodeid])
+    revs.sort()
+    url = 'http://bitbucket.org/%s/compare/%s:%s..%s'
+    url = url % (reponame, reponame, repo[revs[-1]], repo[revs[0]])
+    ui.write(url + '\n')
 def bb_link(ui, repo, filename=None, **opts):
     '''display a bitbucket link to the repository, or the specific file if given'''
     # XXX: might not work on windows, because it uses \ to separate paths
            'name of the repo at bitbucket (else guessed from repo dir)'),
          'hg bbfollowers [-n reponame]'),
+    'bbcompare':
+        (bb_compare,
+         [('r', 'rev', [], 'revision', 'REV'),
+          ],
+         'hg bbcompare [-r] REVISION...'),
          [('l', 'lineno', -1, 'line number')],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.