From 58529741373f592f6023de97b89a154f27c1f09e Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Mon, 5 Aug 2019 13:01:26 +0800 Subject: [PATCH] Use rev-parse to check if commit exists Signed-off-by: Gary Kim --- modules/markup/html.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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],