Skip to content

Remember diff view style #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,20 @@ func runWeb(ctx *cli.Context) error {

m.Group("/pulls/:index", func() {
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.ViewPullFiles)
m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ViewPullFiles)
m.Post("/merge", reqRepoWriter, repo.MergePullRequest)
}, repo.MustAllowPulls)

m.Group("", func() {
m.Get("/src/*", repo.SetEditorconfigIfExists, repo.Home)
m.Get("/raw/*", repo.SingleDownload)
m.Get("/commits/*", repo.RefCommits)
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.Diff)
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff)
m.Get("/forks", repo.Forks)
}, context.RepoRef())
m.Get("/commit/:sha([a-f0-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]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.CompareDiff)
}, ignSignIn, context.RepoAssignment(), repo.MustBeNotBare)
m.Group("/:username/:reponame", func() {
m.Get("/stars", repo.Stars)
Expand Down
4 changes: 3 additions & 1 deletion models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ var migrations = []Migration{

// v13 -> v14:v0.9.87
NewMigration("set comment updated with created", setCommentUpdatedWithCreated),

NewMigration("create user column diff view style", createUserColumnDiffViewStyle),
}

// Migrate database to current version
Expand All @@ -96,7 +98,7 @@ func Migrate(x *xorm.Engine) error {

v := currentVersion.Version
if _MIN_DB_VER > v {
log.Fatal(4, `Gogs no longer supports auto-migration from your previously installed version.
log.Fatal(4, `Gogs no longer supports auto-migration from your previously installed version.
Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to current version.`)
return nil
}
Expand Down
12 changes: 12 additions & 0 deletions models/migrations/v14.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ func setCommentUpdatedWithCreated(x *xorm.Engine) (err error) {
}
return nil
}

type UserV14 struct {
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
}

func (*UserV14) TableName() string {
return "user"
}

func createUserColumnDiffViewStyle(x *xorm.Engine) error {
return x.Sync2(new(UserV14))
}
8 changes: 8 additions & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ type User struct {
NumMembers int
Teams []*Team `xorm:"-"`
Members []*User `xorm:"-"`

// Preferences
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
}

func (u *User) BeforeInsert() {
Expand All @@ -126,6 +129,11 @@ func (u *User) SetLastLogin() {
u.LastLoginUnix = time.Now().Unix()
}

func (u *User) UpdateDiffViewStyle(style string) error {
u.DiffViewStyle = style
return UpdateUser(u)
}

func (u *User) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "full_name":
Expand Down
2 changes: 0 additions & 2 deletions routers/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func Diff(ctx *context.Context) {
}

ctx.Data["CommitID"] = commitID
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName
ctx.Data["IsImageFile"] = commit.IsImageFile
Expand Down Expand Up @@ -239,7 +238,6 @@ func CompareDiff(ctx *context.Context) {
}
commits = models.ValidateCommitsWithEmails(commits)

ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["CommitRepoLink"] = ctx.Repo.RepoLink
ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = commits.Len()
Expand Down
21 changes: 21 additions & 0 deletions routers/repo/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,24 @@ func SetEditorconfigIfExists(ctx *context.Context) {

ctx.Data["Editorconfig"] = ec
}

func SetDiffViewStyle(ctx *context.Context) {
var (
userStyle = ctx.User.DiffViewStyle
queryStyle = ctx.Query("style")
style string
)

if queryStyle == "unified" || queryStyle == "split" {
style = queryStyle
} else if userStyle == "unified" || userStyle == "split" {
style = userStyle
} else {
style = "unified"
}

ctx.Data["IsSplitStyle"] = style == "split"
if err := ctx.User.UpdateDiffViewStyle(style); err != nil {
ctx.Handle(500, "ErrUpdateDiffViewStyle", err)
}
}
1 change: 0 additions & 1 deletion routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ func ViewPullFiles(ctx *context.Context) {
}

headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["Username"] = pull.HeadUserName
ctx.Data["Reponame"] = pull.HeadRepo.Name
ctx.Data["IsImageFile"] = commit.IsImageFile
Expand Down