diff options
author | Thibault Meyer <0xbaadf00d@users.noreply.github.com> | 2016-08-12 00:34:00 +0200 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2016-08-11 15:34:00 -0700 |
commit | 7eafe3213f456bb4fcbaeea5562ab60c4ef6cf87 (patch) | |
tree | 735dcb1d84219002924be4b49caed3056602d854 | |
parent | 2cb04db52661b346bed26daeb94402f460195797 (diff) | |
download | gitea-7eafe3213f456bb4fcbaeea5562ab60c4ef6cf87.tar.gz gitea-7eafe3213f456bb4fcbaeea5562ab60c4ef6cf87.zip |
Fix #3321: commit tag shortener (#3418)
* Fix #3321: commit tag shortener
* Check short commit
* remove debug
* Edit unit tests
* Show 10-char short SHA
-rw-r--r-- | cmd/web.go | 6 | ||||
-rw-r--r-- | modules/base/tool.go | 2 | ||||
-rw-r--r-- | modules/markdown/markdown.go | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/cmd/web.go b/cmd/web.go index bcb99a0ee5..eb364cfec0 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -534,12 +534,12 @@ func runWeb(ctx *cli.Context) error { m.Get("/src/*", repo.Home) m.Get("/raw/*", repo.SingleDownload) m.Get("/commits/*", repo.RefCommits) - m.Get("/commit/:sha([a-z0-9]{40})$", repo.Diff) + m.Get("/commit/:sha([a-z0-9]{7,40})$", repo.Diff) m.Get("/forks", repo.Forks) }, context.RepoRef()) - m.Get("/commit/:sha([a-z0-9]{40})\\.:ext(patch|diff)", repo.RawDiff) + m.Get("/commit/:sha([a-z0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff) - m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.CompareDiff) + m.Get("/compare/:before([a-z0-9]{7,40})\\.\\.\\.:after([a-z0-9]{7,40})", repo.CompareDiff) }, ignSignIn, context.RepoAssignment(), repo.MustBeNotBare) m.Group("/:username/:reponame", func() { m.Get("/stars", repo.Stars) diff --git a/modules/base/tool.go b/modules/base/tool.go index 6088daf033..cf8fece027 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -45,7 +45,7 @@ func EncodeSha1(str string) string { } func ShortSha(sha1 string) string { - if len(sha1) == 40 { + if len(sha1) > 10 { return sha1[:10] } return sha1 diff --git a/modules/markdown/markdown.go b/modules/markdown/markdown.go index 92a6154993..1da1c5e2e8 100644 --- a/modules/markdown/markdown.go +++ b/modules/markdown/markdown.go @@ -90,7 +90,7 @@ var ( IssueAlphanumericPattern = regexp.MustCompile(`( |^|\()[A-Z]{1,10}-[1-9][0-9]*\b`) // Sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae - Sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{40}\b`) + Sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{7,40}\b`) ) // FindAllMentions matches mention patterns in given content |