508
508
#
509
509
# Source URLs.
510
510
#
511
- # Based on code from https://github.com/JuliaLang/julia/blob/master/base/methodshow.jl.
512
- #
513
511
# Customised to handle URLs on travis since the directory is not a Git repo and we must
514
512
# instead rely on `TRAVIS_REPO_SLUG` to get the remote repo.
515
513
#
@@ -522,45 +520,25 @@ Get the URL (file and line number) where a method `m` is defined.
522
520
Note that this is based on the implementation of `Base.url`, but handles URLs correctly
523
521
on TravisCI as well.
524
522
"""
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 " "
533
530
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
559
537
return " "
560
538
end
561
- else
562
- return " "
563
539
end
540
+ else
541
+ return Base. url (m)
564
542
end
565
543
end
566
544
0 commit comments