diff --git a/cmd/web.go b/cmd/web.go index 0d472cd73..2376fd212 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -343,6 +343,7 @@ func runWeb(*cli.Context) { r.Get("/issues/:index", repo.ViewIssue) r.Get("/pulls", repo.Pulls) r.Get("/branches", repo.Branches) + r.Get("/archive/*", repo.Download) }, ignSignIn, middleware.RepoAssignment(true)) m.Group("/:username/:reponame", func(r *macaron.Router) { @@ -355,8 +356,6 @@ func runWeb(*cli.Context) { r.Get("/commit/:branchname", repo.Diff) r.Get("/commit/:branchname/*", repo.Diff) r.Get("/releases", repo.Releases) - r.Get("/archive/:branchname/*.*", repo.Download) - r.Get("/archive/*.*", repo.Download) r.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff) }, ignSignIn, middleware.RepoAssignment(true, true)) diff --git a/gogs.go b/gogs.go index 0821dbc22..6956b9f50 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.4.0923 Beta" +const APP_VER = "0.5.4.0924 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index e447ee3a4..c0290b2e8 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -200,7 +200,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(refName) if err != nil { - ctx.Handle(404, "RepoAssignment invalid branch", nil) + ctx.Handle(500, "RepoAssignment invalid branch", err) return } ctx.Repo.CommitId = ctx.Repo.Commit.Id.String() @@ -209,14 +209,9 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Repo.IsTag = true ctx.Repo.BranchName = refName - ctx.Repo.Tag, err = gitRepo.GetTag(refName) + ctx.Repo.Commit, err = gitRepo.GetCommitOfTag(refName) if err != nil { - ctx.Handle(404, "RepoAssignment invalid tag", nil) - return - } - ctx.Repo.Commit, err = ctx.Repo.Tag.Commit() - if err != nil { - ctx.Handle(500, "RepoAssignment", fmt.Errorf("fail to get tag commit(%s): %v", refName, err)) + ctx.Handle(500, "RepoAssignment invalid tag", err) return } ctx.Repo.CommitId = ctx.Repo.Commit.Id.String() diff --git a/routers/repo/repo.go b/routers/repo/repo.go index ae599f9fa..5562a8400 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -244,18 +244,25 @@ func Action(ctx *middleware.Context) { } func Download(ctx *middleware.Context) { - ext := "." + ctx.Params(":ext") + var ( + uri = ctx.Params("*") + refName string + ext string + archivePath string + ) - var archivePath string - switch ext { - case ".zip": + switch { + case strings.HasSuffix(uri, ".zip"): + ext = ".zip" archivePath = path.Join(ctx.Repo.GitRepo.Path, "archives/zip") - case ".tar.gz": + case strings.HasSuffix(uri, ".tar.gz"): + ext = ".tar.gz" archivePath = path.Join(ctx.Repo.GitRepo.Path, "archives/targz") default: ctx.Error(404) return } + refName = strings.TrimSuffix(uri, ext) if !com.IsDir(archivePath) { if err := os.MkdirAll(archivePath, os.ModePerm); err != nil { @@ -264,13 +271,42 @@ func Download(ctx *middleware.Context) { } } + // Get corresponding commit. + var ( + commit *git.Commit + err error + ) + gitRepo := ctx.Repo.GitRepo + if gitRepo.IsBranchExist(refName) { + commit, err = gitRepo.GetCommitOfBranch(refName) + if err != nil { + ctx.Handle(500, "Download", err) + return + } + } else if gitRepo.IsTagExist(refName) { + commit, err = gitRepo.GetCommitOfTag(refName) + if err != nil { + ctx.Handle(500, "Download", err) + return + } + } else if len(refName) == 40 { + commit, err = gitRepo.GetCommit(refName) + if err != nil { + ctx.Handle(404, "Download", nil) + return + } + } else { + ctx.Error(404) + return + } + archivePath = path.Join(archivePath, ctx.Repo.CommitId+ext) if !com.IsFile(archivePath) { - if err := ctx.Repo.Commit.CreateArchive(archivePath, git.ZIP); err != nil { + if err := commit.CreateArchive(archivePath, git.ZIP); err != nil { ctx.Handle(500, "Download -> CreateArchive "+archivePath, err) return } } - ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+base.ShortSha(ctx.Repo.CommitId)+ext) + ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+base.ShortSha(commit.Id.String())+ext) } diff --git a/templates/.VERSION b/templates/.VERSION index 23f5f0fe5..49d86b406 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.4.0923 Beta \ No newline at end of file +0.5.4.0924 Beta \ No newline at end of file diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index 58a050ab5..1eb11fc5e 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -36,8 +36,8 @@ {{str2html .Note}}
- Source Code (ZIP) - Source Code (TAR.GZ) + Source Code (ZIP) + Source Code (TAR.GZ)
@@ -48,8 +48,8 @@