diff --git a/modules/markup/html.go b/modules/markup/html.go index 1dcd3389bc..e6c4be64cd 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -647,6 +647,9 @@ func fullSha1PatternProcessor(ctx *postProcessCtx, node *html.Node) { // sha1CurrentPatternProcessor renders SHA1 strings to corresponding links that // are assumed to be in the same repository. func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) { + if ctx.metas == nil || ctx.metas["user"] == "" || ctx.metas["repo"] == "" || ctx.metas["repoPath"] == "" { + return + } m := sha1CurrentPattern.FindStringSubmatchIndex(node.Data) if m == nil { return @@ -660,11 +663,8 @@ func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) { // as used by git and github for linking and thus we have to do similar. // Because of this, we check to make sure that a matched hash is actually // a commit in the repository before making it a link. - if ctx.metas["repoPath"] != "" { - repo, err := git.OpenRepository(ctx.metas["repoPath"]) - if err != nil || !repo.IsCommitExist(hash) { - return - } + if _, err := git.NewCommand("rev-parse", "--verify", hash).RunInDirBytes(ctx.metas["repoPath"]); err != nil { + return } replaceContent(node, m[2], m[3],