]> source.dussan.org Git - gitea.git/commitdiff
Fix #3321: commit tag shortener (#3418)
authorThibault Meyer <0xbaadf00d@users.noreply.github.com>
Thu, 11 Aug 2016 22:34:00 +0000 (00:34 +0200)
committer无闻 <u@gogs.io>
Thu, 11 Aug 2016 22:34:00 +0000 (15:34 -0700)
* Fix #3321: commit tag shortener

* Check short commit

* remove debug

* Edit unit tests

* Show 10-char short SHA

cmd/web.go
modules/base/tool.go
modules/markdown/markdown.go

index bcb99a0ee562d4fdb0ae554759f31812e29844e4..eb364cfec00ee7c059353190c9217434d405f44c 100644 (file)
@@ -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)
index 6088daf033d024176cfd9be3079f7d68428d4888..cf8fece0279146a820c83d43d60f43cd7592a2f6 100644 (file)
@@ -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
index 92a6154993039922059f9db3d461ee48c8e59fa4..1da1c5e2e82afdd82ea2ad83ac865f32e715aa5d 100644 (file)
@@ -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