Commits

Anonymous committed 14734fa

Link to a specific line when :NNN is added after a file name. Also update and add more tests.

Comments (0)

Files changed (2)

extensions/local_replace.py

 ]
 '''
 
+def make_file_link(match):
+    baseurl = 'http://hg.python.org/cpython/file/default/'
+    sep = match.group('sep')
+    path = match.group('path')
+    lnum = match.group('lnum') or ''  # the match includes the ':'
+    if not path.endswith('/'):
+        # files without and with line number
+        if not lnum:
+            return '<a href="%s%s">%s%s</a>' % (baseurl, path, sep, path)
+        else:
+            return '<a href="%s%s#l%s">%s%s%s</a>' % (baseurl, path, lnum[1:],
+                                                      sep, path, lnum)
+    else:
+        # dirs
+        return '<a href="%s%s">%s%s</a>%s' % (baseurl, path, sep, path, lnum)
+
+
 substitutions = [
     # r12345, r 12345, rev12345, rev 12345, revision12345, revision 12345
     (re.compile(r'\b(?<![/?&;])(?P<revstr>r(ev(ision)?)?\s*)(?P<revision>\d+)'),
     (re.compile(r'\b(?<![/?&;])(?P<revision>[a-fA-F0-9]{12})\b'),
      r'<a href="http://hg.python.org/lookup/\g<revision>">\g<revision></a>'),
 
-    # Lib/somefile.py, Modules/somemodule.c, Doc/somedocfile.rst, ...
+    # Lib/somefile.py, Lib/somefile.py:123, Modules/somemodule.c:123, ...
     (re.compile(r'(?P<sep>(?<!\w/)|(?<!\w)/)(?P<path>(?:Demo|Doc|Grammar|'
                 r'Include|Lib|Mac|Misc|Modules|Parser|PC|PCbuild|Python|'
-                'RISCOS|Tools|Objects)/[-.a-zA-Z0-9_/]+[a-zA-Z0-9]/?)'),
-     r'<a href="http://hg.python.org/cpython/file/default/\g<path>">\g<sep>\g<path></a>'),
+                r'RISCOS|Tools|Objects)/[-.\w/]+[a-zA-Z0-9]/?)(?P<lnum>:\d{1,5})?'),
+     make_file_link),
 ]
 
 # if the issue number is too big the db will explode -- limit it to 7 digits

extensions/test/test_local_replace.py

 test_strings = [
     ## r12345, r 12345, rev12345, rev 12345, revision12345, revision 12345
     ('r222 ',
-     '<a href="http://svn.python.org/view?rev=222&view=rev">r222</a> '),
+     '<a href="http://hg.python.org/lookup/r222">r222</a> '),
     (' r222 ',
-     ' <a href="http://svn.python.org/view?rev=222&view=rev">r222</a> '),
+     ' <a href="http://hg.python.org/lookup/r222">r222</a> '),
     (' r 222 ',
-     ' <a href="http://svn.python.org/view?rev=222&view=rev">r 222</a> '),
+     ' <a href="http://hg.python.org/lookup/r222">r 222</a> '),
     (' rev222 ',
-     ' <a href="http://svn.python.org/view?rev=222&view=rev">rev222</a> '),
+     ' <a href="http://hg.python.org/lookup/r222">rev222</a> '),
     (' rev  222 ',
-     ' <a href="http://svn.python.org/view?rev=222&view=rev">rev  222</a> '),
+     ' <a href="http://hg.python.org/lookup/r222">rev  222</a> '),
     (' revision222 ',
-     ' <a href="http://svn.python.org/view?rev=222&view=rev">revision222</a> '),
+     ' <a href="http://hg.python.org/lookup/r222">revision222</a> '),
     (' revision 222 ',
-     ' <a href="http://svn.python.org/view?rev=222&view=rev">revision 222</a> '),
+     ' <a href="http://hg.python.org/lookup/r222">revision 222</a> '),
     ('wordthatendswithr 222',
      'wordthatendswithr 222'),
 
 
     ## Lib/somefile.py, Modules/somemodule.c, Doc/somedocfile.rst, ...
     ('Lib/cgi.py',
-     '<a href="http://svn.python.org/view/python/branches/py3k/Lib/cgi.py">Lib/cgi.py</a>'),
+     '<a href="http://hg.python.org/cpython/file/default/Lib/cgi.py">Lib/cgi.py</a>'),
     ('/Lib/cgi.py',
-     '<a href="http://svn.python.org/view/python/branches/py3k/Lib/cgi.py">/Lib/cgi.py</a>'),
+     '<a href="http://hg.python.org/cpython/file/default/Lib/cgi.py">/Lib/cgi.py</a>'),
     ('see Lib/cgi.py.',
-     'see <a href="http://svn.python.org/view/python/branches/py3k/Lib/cgi.py">Lib/cgi.py</a>.'),
+     'see <a href="http://hg.python.org/cpython/file/default/Lib/cgi.py">Lib/cgi.py</a>.'),
     ('see /Lib/cgi.py.',
-     'see <a href="http://svn.python.org/view/python/branches/py3k/Lib/cgi.py">/Lib/cgi.py</a>.'),
+     'see <a href="http://hg.python.org/cpython/file/default/Lib/cgi.py">/Lib/cgi.py</a>.'),
     ('(Lib/cgi.py)',
-     '(<a href="http://svn.python.org/view/python/branches/py3k/Lib/cgi.py">Lib/cgi.py</a>)'),
+     '(<a href="http://hg.python.org/cpython/file/default/Lib/cgi.py">Lib/cgi.py</a>)'),
     ('(/Lib/cgi.py)',
-     '(<a href="http://svn.python.org/view/python/branches/py3k/Lib/cgi.py">/Lib/cgi.py</a>)'),
+     '(<a href="http://hg.python.org/cpython/file/default/Lib/cgi.py">/Lib/cgi.py</a>)'),
+    ('/Lib/http',
+     '<a href="http://hg.python.org/cpython/file/default/Lib/http">/Lib/http</a>'),
+    ('/Lib/http/',
+     '<a href="http://hg.python.org/cpython/file/default/Lib/http/">/Lib/http/</a>'),
+
+    ## Lib/somefile.py:123, Modules/somemodule.c:123, ...
+    ('see Lib/cgi.py:123,',
+     'see <a href="http://hg.python.org/cpython/file/default/Lib/cgi.py#l123">Lib/cgi.py:123</a>,'),
+    ('see Lib/cgi.py: foo',
+     'see <a href="http://hg.python.org/cpython/file/default/Lib/cgi.py">Lib/cgi.py</a>: foo'),
+    ('see Lib/cgi.py: 123',
+     'see <a href="http://hg.python.org/cpython/file/default/Lib/cgi.py">Lib/cgi.py</a>: 123'),
+    ('/Lib/http/:123',
+     '<a href="http://hg.python.org/cpython/file/default/Lib/http/">/Lib/http/</a>:123'),
 
     ## URLs
     ('http://svn.python.org/view/python/tags/r265 ',
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.