Commits

Dan Villiom Podlaski Christiansen  committed a14bfd6

Filename support.

  • Participants
  • Parent commits 6c70c33

Comments (0)

Files changed (2)

File hgopenurl/__init__.py

 
 demandimport.ignore.append('ic')
 
-def getpath(ui, repo, path, rev):
+def getpath(ui, repo, filename, path, rev):
     if path is None:
         path = 'default'
 
     if gcode:
         ui.debug('this is a Google Code repository\n')
         repoid = gcode.group(1)
-        if rev:
+        if filename:
+            url = 'https://code.google.com/p/%s/source/browse/%s' % (
+                repoid, filename,
+            )
+            if rev:
+                url += '?rev=%s' % rev
+        elif rev:
             url = 'https://code.google.com/p/%s/source/detail?r=%s' % (
                 repoid, rev,
             )
     elif bb:
         ui.debug('this is a BitBucket repository\n')
         repoid = '%s/%s' % bb.groups()[3:5]
-        if rev:
+        if filename:
+            url = 'https://bitbucket.org/%s/src/%s/%s' % (
+                repoid, rev or 'default', filename,
+            )
+            if rev:
+                url += '?rev=%s' % rev
+        elif rev:
             url = 'https://bitbucket.org/%s/changeset/%s' % (repoid, rev)
         else:
             url = 'https://bitbucket.org/%s/changesets' % repoid
     elif fallbackhttp:
         ui.note('assuming standard hgweb repository')
         url = path.rstrip('/')
-        if rev:
+        if filename:
+            url = '/file/%s/%s' % (
+                rev or 'default', filename,
+            )
+        elif rev:
             url += '/rev/%s' % rev
     elif fallbackssh:
         raise util.Abort("don't know how to convert regular SSH repositories "
                          "into an web address")
     else:
-        raise util.Abort("unsupported URL schema")
-        
+        raise util.Abort("unsupported URL schema for path %r" % path)
 
     return url
     
-def showurl(ui, repo, path=None, rev=None):
+def showurl(ui, repo, filename=None, path=None, rev=None):
     '''print the web URL of the repository.
 
     If the -r/--rev argument is given, show the address of the changelog for
     that revision. Otherwise, the address of the repository changelog is shown.
     '''
-    ui.write('%s\n' % getpath(ui, repo, path, rev))
+    ui.write('%s\n' % getpath(ui, repo, filename, path, rev))
 
-def openurl(ui, repo, path=None, rev=None):
+def openurl(ui, repo, filename=None, path=None, rev=None):
     '''open the URL of the repository in a web browser.
 
     If the -r/--rev argument is given, open the address of the changelog for
     that revision. Otherwise, the address of the repository changelog is opened.
     '''
 
-    url = getpath(ui, repo, path, rev)
+    url = getpath(ui, repo, filename, path, rev)
 
     ui.note('opening %r\n' % url)
     webbrowser.open(url)
          [
           ('r', 'rev', '', 'revision to link to', 'REV'),
          ],
-         'hg showurl [-r REV] [PATH]',
+         'hg showurl [-r REV] [FILE [DEST]]',
          ),
     "openurl|ou":
         (openurl,
          [
           ('r', 'rev', '', 'revision to link to', 'REV'),
          ],
-         'hg openurl [-r REV] [PATH]',
+         'hg openurl [-r REV] [FILE [DEST]]',
          ),
 }

File tests/test-showurl.t

   > hgopenurl = $TESTDIR/../hgopenurl
   > EOF
 
+  $ setdefault() {
+  >   echo "[paths]\ndefault = $1\n" > .hg/hgrc
+  > }
+  $ testurl() {
+  >   setdefault $1
+  >   hg showurl
+  > }
+  $ testrev() {
+  >   setdefault $1
+  >   hg showurl -r deadbeef
+  > }
+
   $ hg init testrepo
   $ cd testrepo
-  $ cat > .hg/hgrc <<EOF
-  > [paths]
-  > default = http://bitbucket.org/xxx/yyy
-  > EOF
-
-Test URL expansion
-
-  $ hg showurl
-  https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl default
-  https://bitbucket.org/xxx/yyy/changesets
+  $ setdefault http://bitbucket.org/xxx/yyy
 
 BitBucket URLs
 
-  $ hg showurl http://bitbucket.org/xxx/yyy/
+  $ testurl http://bitbucket.org/xxx/yyy/
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl https://bitbucket.org/xxx/yyy
+  $ testurl https://bitbucket.org/xxx/yyy
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl https://bitbucket.org/xxx/yyy/
+  $ testurl https://bitbucket.org/xxx/yyy/
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl ssh://bitbucket.org/xxx/yyy
+  $ testurl ssh://bitbucket.org/xxx/yyy
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl ssh://bitbucket.org/xxx/yyy/
+  $ testurl ssh://bitbucket.org/xxx/yyy/
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl ssh://hg@bitbucket.org/xxx/yyy
+  $ testurl ssh://hg@bitbucket.org/xxx/yyy
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl ssh://hg@bitbucket.org/xxx/yyy/
+  $ testurl ssh://hg@bitbucket.org/xxx/yyy/
   https://bitbucket.org/xxx/yyy/changesets
 
 Ditto, with revision
 
-  $ hg showurl -r deadbeef ssh://hg@bitbucket.org/xxx/yyy/
+  $ testrev ssh://hg@bitbucket.org/xxx/yyy/
   https://bitbucket.org/xxx/yyy/changeset/deadbeef
-  $ hg showurl -r deadbeef http://bitbucket.org/xxx/yyy/
+  $ testrev http://bitbucket.org/xxx/yyy/
   https://bitbucket.org/xxx/yyy/changeset/deadbeef
 
+Ditto, with filename
+
+  $ hg showurl kaflaflibob ssh://hg@bitbucket.org/xxx/yyy/
+  https://bitbucket.org/xxx/yyy/src/default/kaflaflibob
+  $ hg showurl kaflaflibob http://bitbucket.org/xxx/yyy/
+  https://bitbucket.org/xxx/yyy/src/default/kaflaflibob
+
+Ditto, with filename & revision
+
+  $ hg showurl -r 42 kaflaflibob ssh://hg@bitbucket.org/xxx/yyy/
+  https://bitbucket.org/xxx/yyy/src/42/kaflaflibob?rev=42
+  $ hg showurl -r 42 kaflaflibob http://bitbucket.org/xxx/yyy/
+  https://bitbucket.org/xxx/yyy/src/42/kaflaflibob?rev=42
+
 BitBucket MQ URLs
 
-  $ hg showurl http://bitbucket.org/xxx/yyy/.hg/patches/
+  $ testurl http://bitbucket.org/xxx/yyy/.hg/patches/
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl https://bitbucket.org/xxx/yyy/.hg/patches
+  $ testurl https://bitbucket.org/xxx/yyy/.hg/patches
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl https://bitbucket.org/xxx/yyy/.hg/patches/
+  $ testurl https://bitbucket.org/xxx/yyy/.hg/patches/
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl ssh://bitbucket.org/xxx/yyy/.hg/patches
+  $ testurl ssh://bitbucket.org/xxx/yyy/.hg/patches
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl ssh://bitbucket.org/xxx/yyy/.hg/patches/
+  $ testurl ssh://bitbucket.org/xxx/yyy/.hg/patches/
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl ssh://hg@bitbucket.org/xxx/yyy/.hg/patches
+  $ testurl ssh://hg@bitbucket.org/xxx/yyy/.hg/patches
   https://bitbucket.org/xxx/yyy/changesets
-  $ hg showurl ssh://hg@bitbucket.org/xxx/yyy/.hg/patches/
+  $ testurl ssh://hg@bitbucket.org/xxx/yyy/.hg/patches/
   https://bitbucket.org/xxx/yyy/changesets
 
 Google Code URLs
 
-  $ hg showurl http://xxx.googlecode.com/hg
+  $ testurl http://xxx.googlecode.com/hg
   https://code.google.com/p/xxx/source/list
-  $ hg showurl http://xxx.googlecode.com/hg/
+  $ testurl http://xxx.googlecode.com/hg/
   https://code.google.com/p/xxx/source/list
-  $ hg showurl https://xxx.googlecode.com/hg
+  $ testurl https://xxx.googlecode.com/hg
   https://code.google.com/p/xxx/source/list
-  $ hg showurl https://xxx.googlecode.com/hg/
+  $ testurl https://xxx.googlecode.com/hg/
   https://code.google.com/p/xxx/source/list
 
 Ditto, with revision
 
-  $ hg showurl -r deadbeef http://xxx.googlecode.com/hg
+  $ testrev http://xxx.googlecode.com/hg
   https://code.google.com/p/xxx/source/detail?r=deadbeef
 
+Ditto, with filename
+
+  $ hg showurl kaflaflibob http://xxx.googlecode.com/hg
+  https://code.google.com/p/xxx/source/browse/kaflaflibob
+
+Ditto, with filename & revision
+
+  $ hg showurl -r 42 kaflaflibob http://xxx.googlecode.com/hg
+  https://code.google.com/p/xxx/source/browse/kaflaflibob?rev=42
+
 Pseudo-hgweb URLs
 
-  $ hg showurl http://xxx
+  $ testurl http://xxx
   http://xxx
-  $ hg showurl http://xxx/
+  $ testurl http://xxx/
   http://xxx
-  $ hg showurl https://xxx
+  $ testurl https://xxx
   https://xxx
-  $ hg showurl https://xxx/
+  $ testurl https://xxx/
   https://xxx
 
 Ditto, with revision
 
-  $ hg showurl -r deadbeef http://xxx
+  $ testrev http://xxx
   http://xxx/rev/deadbeef
-  $ hg showurl -r deadbeef https://xxx/
+  $ testrev https://xxx/
   https://xxx/rev/deadbeef
 
+Ditto, with revision
+
+  $ hg openurl -r 42 http://xxx
+  $ hg openurl -r 42  https://xxx/
+
 We can't do these
 
-  $ hg showurl ssh://xxx/
+  $ testurl ssh://xxx/
   abort: don't know how to convert regular SSH repositories into an web address
   [255]
-  $ hg showurl ssh://xxx/
+  $ testurl ssh://xxx/
   abort: don't know how to convert regular SSH repositories into an web address
   [255]
-  $ hg showurl file:///xxx/
-  abort: unsupported URL schema
+  $ testurl file:///xxx/
+  abort: unsupported URL schema for path 'file:///xxx/'
   [255]
-  $ hg showurl /xxx
-  abort: unsupported URL schema
+  $ testurl /xxx
+  abort: unsupported URL schema for path '/xxx'
   [255]