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,25 @@ 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)
526-
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 "
523+ function url (m:: Method )
524+ if haskey (ENV , " TRAVIS_REPO_SLUG" )
525+ repo = ENV [" TRAVIS_REPO_SLUG" ]
526+ commit = get (ENV , " TRAVIS_COMMIT" , nothing )
527+ root = get (ENV , " TRAVIS_BUILD_DIR" , nothing )
528+ if any (isnothing, (commit, root))
529+ return " "
533530 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 ()
531+ file = string (m. file)
532+ if startswith (file, root) || startswith (realpath (file), root)
533+ base = " https://github.com/$repo /tree"
534+ filename = lstrip (file[(length (root)+ 1 ): end ], ' /' )
535+ return " $base /$commit /$filename #L$(m. line) "
536+ else
559537 return " "
560538 end
561- else
562- return " "
563539 end
540+ else
541+ return Base. url (m)
564542 end
565543end
566544
0 commit comments