508508#
509509# Source URLs.
510510#
511- # Based on code from https://github.com/JuliaLang/julia/blob/master/base/methodshow.jl.
512- #
513511# Customised to handle URLs on travis since the directory is not a Git repo and we must
514512# instead rely on `TRAVIS_REPO_SLUG` to get the remote repo.
515513#
@@ -522,45 +520,26 @@ Get the URL (file and line number) where a method `m` is defined.
522520Note that this is based on the implementation of `Base.url`, but handles URLs correctly
523521on TravisCI as well.
524522"""
525- url (m:: Method ) = url (m. module, string (m. file), m. line)
523+ function url (m:: Method )
524+ if haskey (ENV , " TRAVIS_REPO_SLUG" )
525+ repo = ENV [" TRAVIS_REPO_SLUG" ]
526526
527- function url (mod:: Module , file:: AbstractString , line:: Integer )
528- file = Sys. iswindows () ? replace (file, ' \\ ' => ' /' ) : file
529- if Base. inbase (mod) && ! isabspath (file)
530- local base = " https://github.com/JuliaLang/julia/tree"
531- if isempty (Base. GIT_VERSION_INFO. commit)
532- return " $base /v$VERSION /base/$file #L$line "
533- else
534- local commit = Base. GIT_VERSION_INFO. commit
535- return " $base /$commit /base/$file #L$line "
536- end
537- else
538- if isfile (file)
539- local d = dirname (file)
540- try # might not be in a git repo
541- LibGit2. with (LibGit2. GitRepoExt (d)) do repo
542- LibGit2. with (LibGit2. GitConfig (repo)) do cfg
543- local u = LibGit2. get (cfg, " remote.origin.url" , " " )
544- local m = match (LibGit2. GITHUB_REGEX, u)
545- u = m === nothing ? get (ENV , " TRAVIS_REPO_SLUG" , " " ) : m. captures[1 ]
546- local commit = string (LibGit2. head_oid (repo))
547- local root = LibGit2. path (repo)
548- if startswith (file, root) || startswith (realpath (file), root)
549- local base = " https://github.com/$u /tree"
550- local filename = file[(length (root) + 1 ): end ]
551- return " $base /$commit /$filename #L$line "
552- else
553- return " "
554- end
555- end
556- end
557- catch err
558- isa (err, LibGit2. GitError) || rethrow ()
559- return " "
560- end
527+ commit = get (ENV , " TRAVIS_COMMIT" , nothing )
528+ commit === nothing && return " "
529+
530+ root = get (ENV , " TRAVIS_BUILD_DIR" , nothing )
531+ root === nothing && return " "
532+
533+ file = realpath (string (m. file))
534+ if startswith (file, root)
535+ filename = join (split (relpath (file, root), @static Sys. iswindows () ? ' \\ ' : ' /' ), ' /' )
536+ base = " https://github.com/$repo /tree"
537+ return " $base /$commit /$filename #L$(m. line) "
561538 else
562539 return " "
563540 end
541+ else
542+ return Base. url (m)
564543 end
565544end
566545
0 commit comments