Skip to content

Commit

Permalink
Fix #3321: commit tag shortener (#3418)
Browse files Browse the repository at this point in the history
* Fix #3321: commit tag shortener

* Check short commit

* remove debug

* Edit unit tests

* Show 10-char short SHA
  • Loading branch information
0xBAADF00D authored and unknwon committed Aug 11, 2016
1 parent 2cb04db commit 7eafe32
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7eafe32

Please sign in to comment.