Browse Source

Fmt; Disappeared % format; % format updates; Unkeyed things

master
Dashie der otter 10 months ago
parent
commit
d73871f155
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755

+ 37
- 18
Makefile View File

@@ -16,14 +16,16 @@ BUILD_FLAGS:=-o $(EXECUTABLE) -v
TAGS=sqlite
NOW=$(shell date -u '+%Y%m%d%I%M%S')

GOVET=go vet
GOLINT=golint -set_exit_status
GO ?= go
GOVET=$(GO) vet
GOLINT=golint -set_exit_status
GOFMT ?= gofmt -s

GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
PACKAGES ?= $(filter-out dev.sigpipe.me/dashie/git.txt/integrations,$(shell go list ./... | grep -v /vendor/))
PACKAGES_ALL ?= $(shell go list ./... | grep -v /vendor/)
SOURCES ?= $(shell find . -name "*.go" -type f)
XGO_DEPS = "--deps=https://s3.sigpipe.me/tarballs/1-mingw-libgnurx-2.5.1-src.tar.gz https://s3.sigpipe.me/tarballs/2-file-5.32.tar.gz"
#XGO_DEPS += "--deps=https://github.com/libgit2/libgit2/archive/maint/v0.25.zip"

ifneq ($(DRONE_TAG),)
VERSION ?= $(subst v,,$(DRONE_TAG))
@@ -35,44 +37,40 @@ else
endif
endif

### Targets
### Targets build and checks

.PHONY: build clean

all: build

check: test

web: build
./$(EXECUTABLE) web

vet:
$(GOVET) git.txt.go
$(GOVET) $(PACKAGES_ALL)

lint:
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/golang/lint/golint; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
for PKG in $(PACKAGES_ALL); do golint -set_exit_status $$PKG || exit 1; done;

build:
$(GO) build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'

build-dev: govet
$(GO) build $(BUILD_FLAGS) -tags '$(TAGS)'
build-dev: vet
$(GO) build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'

build-dev-race: govet
$(GO) build $(BUILD_FLAGS) -race -tags '$(TAGS)'
build-dev-race: vet
$(GO) build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -race -tags '$(TAGS)'

clean:
clean: clean-mac
$(GO) clean -i ./...
rm -f $(EXECUTABLE)

clean-mac: clean
clean-mac:
find . -name ".DS_Store" -delete

test:
$(GO) test -cover -v $(PACKAGES)

.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
@@ -87,8 +85,29 @@ misspell:
fi
misspell -w -i unknwon $(GOFILES)

.PHONY: fmt
fmt:
$(GOFMT) -w $(GOFILES)

.PHONY: fmt-check
fmt-check:
# get all go files and run go fmt on them
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;

### Targets for tests
# Use PACKAGES instead of PACKAGES_ALL because the integrations tests are run separately

test: fmt-check
$(GO) test -cover -v $(PACKAGES)

### Targets for releases
.PHONY: release
release: release-dirs release-windows release-linux release-copy release-check
release: release-dirs release-linux release-copy release-check

.PHONY: release-dirs
release-dirs:

+ 3
- 0
TODO.org View File

@@ -2,6 +2,9 @@

* Ways of improvement
** TODO Merge AssignUser and AssignRepository ?
** blackfriday dependency update to 2.x, breaking changes
** xorm update, breaking changes
*** migrate to gorm ?

** TODO Upgrade git2go to v26 (.3)
*** Blocked by https://github.com/libgit2/git2go/issues/407

+ 1
- 1
cmd/cmd.go View File

@@ -34,4 +34,4 @@ func durationFlag(name string, value time.Duration, usage string) cli.DurationFl
Value: value,
Usage: usage,
}
}
}

+ 3
- 3
cmd/web.go View File

@@ -97,7 +97,7 @@ func newMacaron() *macaron.Macaron {

m.Use(toolbox.Toolboxer(m, toolbox.Options{
HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
&toolbox.HealthCheckFuncDesc{
{
Desc: "Database connection",
Func: models.Ping,
},
@@ -116,7 +116,7 @@ func runWeb(ctx *cli.Context) error {
}

setting.InitConfig()
markup.NewSanitizer()
//markup.NewSanitizer() // IDK what I wanted to do here
models.InitDb()
cron.NewContext()
mailer.NewContext()
@@ -233,7 +233,7 @@ func runWeb(ctx *cli.Context) error {
os.Remove(listenAddr)

var listener *net.UnixListener
listener, err = net.ListenUnix("unix", &net.UnixAddr{listenAddr, "unix"})
listener, err = net.ListenUnix("unix", &net.UnixAddr{Name: listenAddr, Net: "unix"})
if err != nil {
break // Handle error after switch
}

+ 6
- 6
context/auth.go View File

@@ -1,11 +1,11 @@
package context

import (
"gopkg.in/macaron.v1"
"dev.sigpipe.me/dashie/git.txt/setting"
"github.com/go-macaron/csrf"
"net/url"
log "gopkg.in/clog.v1"
"gopkg.in/macaron.v1"
"net/url"
)

// ToggleOptions struct
@@ -26,7 +26,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
return
}

log.Trace("SignOutRequired: %s, DisableCSRF: %s, Req Method: %s", options.SignOutRequired, options.DisableCSRF, ctx.Req.Method)
log.Trace("SignOutRequired: %t, DisableCSRF: %t, Req Method: %s", options.SignOutRequired, options.DisableCSRF, ctx.Req.Method)
if !options.SignOutRequired && !options.DisableCSRF && ctx.Req.Method == "POST" {
log.Trace("Validating CSRF")
csrf.Validate(ctx.Context, ctx.csrf)
@@ -37,7 +37,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {

if options.SignInRequired {
if !ctx.IsLogged {
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL + ctx.Req.RequestURI), 0, setting.AppSubURL)
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
ctx.Redirect(setting.AppSubURL + "/user/login")
return
} else if !ctx.User.IsActive {
@@ -49,7 +49,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {

// Redirect to login page if auto-sign provided and not signed in
if !options.SignOutRequired && !ctx.IsLogged && len(ctx.GetCookie(setting.CookieUserName)) > 0 {
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL + ctx.Req.RequestURI), 0, setting.AppSubURL)
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
ctx.Redirect(setting.AppSubURL + "/user/login")
return
}
@@ -62,4 +62,4 @@ func Toggle(options *ToggleOptions) macaron.Handler {
ctx.Data["PageIsAdmin"] = true
}
}
}
}

+ 8
- 8
context/repo.go View File

@@ -1,21 +1,21 @@
package context

import (
"gopkg.in/macaron.v1"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"strings"
"dev.sigpipe.me/dashie/git.txt/setting"
"time"
log "gopkg.in/clog.v1"
"gopkg.in/macaron.v1"
"strings"
"time"
)

// Gitxt struct
type Gitxt struct {
User *models.User
Gitxt *models.Gitxt
Owner bool // Gitxt.Owner: "toto/repos" does "repos" belongs to "toto" ?
UserName string
User *models.User
Gitxt *models.Gitxt
Owner bool // Gitxt.Owner: "toto/repos" does "repos" belongs to "toto" ?
UserName string
}

// AssignRepository to context
@@ -64,4 +64,4 @@ func CheckRepoExpiry() macaron.Handler {
return
}
}
}
}

+ 2
- 2
context/user.go View File

@@ -1,9 +1,9 @@
package context

import (
"gopkg.in/macaron.v1"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"gopkg.in/macaron.v1"
)

// AssignUser to context
@@ -31,4 +31,4 @@ func AssignUser() macaron.Handler {
ctx.Gitxt.User = user
ctx.RepoOwnerUsername = userName
}
}
}

+ 4
- 4
models/counter.go View File

@@ -6,9 +6,9 @@ import (

// Counter struct
type Counter struct {
ID int64 `xorm:"pk autoincr"`
Name string `xorm:"UNIQUE NOT NULL"`
Count int64
ID int64 `xorm:"pk autoincr"`
Name string `xorm:"UNIQUE NOT NULL"`
Count int64
}

// Don't change them !
@@ -111,4 +111,4 @@ func updateCounterGitxtsManaged(e Engine, count int64) error {
// UpdateCounterGitxtsManaged with count
func UpdateCounterGitxtsManaged(c int64) error {
return updateCounterGitxtsManaged(x, c)
}
}

+ 0
- 1
models/error.go View File

@@ -239,7 +239,6 @@ func (err ErrDeployKeyNameAlreadyUsed) Error() string {
return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
}


// ErrHashAlreadyExist struct
type ErrHashAlreadyExist struct {
Hash string

+ 2
- 2
models/errors/repo.go View File

@@ -5,7 +5,7 @@ import "fmt"
// RepoNotExist struct
type RepoNotExist struct {
ID int64
UserID int64
UserID int64
Name string
}

@@ -18,4 +18,4 @@ func IsRepoNotExist(err error) bool {
// Error func
func (err RepoNotExist) Error() string {
return fmt.Sprintf("repository does not exist [id: %d, user_id: %d, name: %s]", err.ID, err.UserID, err.Name)
}
}

+ 21
- 21
models/gitxt.go View File

@@ -1,41 +1,41 @@
package models

import (
"time"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"github.com/go-xorm/xorm"
"fmt"
"os"
"dev.sigpipe.me/dashie/git.txt/setting"
"dev.sigpipe.me/dashie/git.txt/stuff/repository"
"dev.sigpipe.me/dashie/git.txt/stuff/sync"
"dev.sigpipe.me/dashie/git.txt/setting"
"fmt"
"github.com/Unknwon/com"
"github.com/go-xorm/xorm"
log "gopkg.in/clog.v1"
"os"
"os/exec"
"path/filepath"
"github.com/Unknwon/com"
"strings"
"os/exec"
"time"
)

// Gitxt struct
type Gitxt struct {
ID int64 `xorm:"pk autoincr"`
Hash string `xorm:"UNIQUE NOT NULL"`
UserID int64 `xorm:"INDEX"`
ID int64 `xorm:"pk autoincr"`
Hash string `xorm:"UNIQUE NOT NULL"`
UserID int64 `xorm:"INDEX"`
Anonymous bool
Description string `xorm:"TEXT"`
Description string `xorm:"TEXT"`

// Chosen expiry in hours
ExpiryHours int64 `xorm:"INDEX"`
ExpiryHours int64 `xorm:"INDEX"`
// Calculated expiry unix timestamp from the time of creation/update
ExpiryUnix int64
Expiry time.Time `xorm:"-"`
ExpiryUnix int64
Expiry time.Time `xorm:"-"`

// Permissions
IsPrivate bool `xorm:"DEFAULT 0"`
IsPrivate bool `xorm:"DEFAULT 0"`

Created time.Time `xorm:"-"`
Created time.Time `xorm:"-"`
CreatedUnix int64
Updated time.Time `xorm:"-"`
Updated time.Time `xorm:"-"`
UpdatedUnix int64

// Relations
@@ -67,8 +67,8 @@ func (gitxt *Gitxt) AfterSet(colName string, _ xorm.Cell) {

// GitxtWithUser struct
type GitxtWithUser struct {
User `xorm:"extends"`
Gitxt `xorm:"extends"`
User `xorm:"extends"`
Gitxt `xorm:"extends"`
}

// Preventing duplicate running tasks
@@ -131,7 +131,7 @@ func GetRepositoryByName(user string, name string) (*Gitxt, error) {
if err != nil {
return nil, err
} else if !has {
return nil, errors.RepoNotExist{0, repo.UserID, name}
return nil, errors.RepoNotExist{ID: 0, UserID: repo.UserID, Name: name}
}
return repo, nil
}
@@ -317,7 +317,7 @@ func DeleteRepository(ownerID int64, repoID int64) error {
if err != nil {
return err
} else if !has {
return errors.RepoNotExist{repoID, ownerID, ""}
return errors.RepoNotExist{ID: repoID, UserID: ownerID, Name: ""}
}

// By defaults use anonymoyus

+ 8
- 8
models/models.go View File

@@ -5,19 +5,19 @@ import (
_ "github.com/denisenkom/go-mssqldb"
// mysql
_ "github.com/go-sql-driver/mysql"
// Postgresql
_ "github.com/lib/pq"
"github.com/go-xorm/xorm"
"database/sql"
"dev.sigpipe.me/dashie/git.txt/setting"
"errors"
"fmt"
"github.com/go-xorm/core"
"path"
"strings"
"github.com/go-xorm/xorm"
// Postgresql
_ "github.com/lib/pq"
log "gopkg.in/clog.v1"
"net/url"
"os"
"dev.sigpipe.me/dashie/git.txt/setting"
"errors"
log "gopkg.in/clog.v1"
"path"
"strings"
)

// Engine represents a XORM engine or session.

+ 1
- 1
models/models_sqlite.go View File

@@ -8,4 +8,4 @@ import (

func init() {
EnableSQLite3 = true
}
}

+ 11
- 11
models/sshkey.go View File

@@ -6,19 +6,19 @@ import (

// SSHKey struct
type SSHKey struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"INDEX NOT NULL"`
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"INDEX NOT NULL"`

Name string `xorm:"NOT NULL"`
Fingerprint string `xorm:"NOT NULL"`
Content string `xorm:"TEXT NOT NULL"`
Mode int `xorm:"NOT NULL DEFAULT 2"`
Type int `xorm:"NOT NULL DEFAULT 1"`
Name string `xorm:"NOT NULL"`
Fingerprint string `xorm:"NOT NULL"`
Content string `xorm:"TEXT NOT NULL"`
Mode int `xorm:"NOT NULL DEFAULT 2"`
Type int `xorm:"NOT NULL DEFAULT 1"`

Created time.Time `xorm:"-"`
CreatedUnix int64
Updated time.Time `xorm:"-"`
UpdatedUnix int64
Created time.Time `xorm:"-"`
CreatedUnix int64
Updated time.Time `xorm:"-"`
UpdatedUnix int64

// Relations
// UserID

+ 32
- 32
models/user.go View File

@@ -1,43 +1,43 @@
package models

import (
"time"
"strings"
"unicode/utf8"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"golang.org/x/crypto/pbkdf2"
"crypto/sha256"
"fmt"
"crypto/subtle"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"os"
"path/filepath"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"dev.sigpipe.me/dashie/git.txt/setting"
"dev.sigpipe.me/dashie/git.txt/stuff/mailer"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"encoding/hex"
"fmt"
"github.com/Unknwon/com"
"golang.org/x/crypto/pbkdf2"
log "gopkg.in/clog.v1"
"dev.sigpipe.me/dashie/git.txt/stuff/mailer"
"os"
"path/filepath"
"strings"
"time"
"unicode/utf8"
)

// User struct
type User struct {
ID int64 `xorm:"pk autoincr"`
UserName string `xorm:"UNIQUE NOT NULL"`
LowerName string `xorm:"UNIQUE NOT NULL"`
Email string `xorm:"NOT NULL"`
ID int64 `xorm:"pk autoincr"`
UserName string `xorm:"UNIQUE NOT NULL"`
LowerName string `xorm:"UNIQUE NOT NULL"`
Email string `xorm:"NOT NULL"`

Password string `xorm:"NOT NULL"`
Rands string `xorm:"VARCHAR(10)"`
Salt string `xorm:"VARCHAR(10)"`
Password string `xorm:"NOT NULL"`
Rands string `xorm:"VARCHAR(10)"`
Salt string `xorm:"VARCHAR(10)"`

// Permissions
IsAdmin bool `xorm:"DEFAULT 0"`
IsActive bool `xorm:"DEFAULT 0"`
IsAdmin bool `xorm:"DEFAULT 0"`
IsActive bool `xorm:"DEFAULT 0"`

Created time.Time `xorm:"-"`
CreatedUnix int64
Updated time.Time `xorm:"-"`
UpdatedUnix int64
Created time.Time `xorm:"-"`
CreatedUnix int64
Updated time.Time `xorm:"-"`
UpdatedUnix int64

// Relations
// Gitxts
@@ -71,7 +71,7 @@ func getUserByID(e Engine, id int64) (*User, error) {
if err != nil {
return nil, err
} else if !has {
return nil, errors.UserNotExist{id, ""}
return nil, errors.UserNotExist{UserID: id, Name: ""}
}
return u, nil
}
@@ -84,14 +84,14 @@ func GetUserByID(id int64) (*User, error) {
// GetUserByName returns user by given name.
func GetUserByName(name string) (*User, error) {
if len(name) == 0 {
return nil, errors.UserNotExist{0, name}
return nil, errors.UserNotExist{UserID: 0, Name: name}
}
u := &User{LowerName: strings.ToLower(name)}
has, err := x.Get(u)
if err != nil {
return nil, err
} else if !has {
return nil, errors.UserNotExist{0, name}
return nil, errors.UserNotExist{UserID: 0, Name: name}
}
return u, nil
}
@@ -99,7 +99,7 @@ func GetUserByName(name string) (*User, error) {
// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(email string) (*User, error) {
if len(email) == 0 {
return nil, errors.UserNotExist{0, "email"}
return nil, errors.UserNotExist{UserID: 0, Name: "email"}
}

email = strings.ToLower(email)
@@ -112,7 +112,7 @@ func GetUserByEmail(email string) (*User, error) {
return user, nil
}

return nil, errors.UserNotExist{0, email}
return nil, errors.UserNotExist{UserID: 0, Name: email}
}

// IsUserExist checks if given user name exist,
@@ -255,10 +255,10 @@ func UserLogin(username, password string) (*User, error) {
return user, nil
}

return nil, errors.UserNotExist{user.ID, user.UserName}
return nil, errors.UserNotExist{UserID: user.ID, Name: user.UserName}
}

return nil, errors.UserNotExist{user.ID, user.UserName}
return nil, errors.UserNotExist{UserID: user.ID, Name: user.UserName}
}

// get user by verify code
@@ -300,7 +300,7 @@ func VerifyUserActiveCode(code string) (user *User) {
// GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
func (user *User) GenerateEmailActivateCode(email string) string {
code := tool.CreateTimeLimitCode(
com.ToStr(user.ID)+email+user.LowerName+user.Password+user.Rands,180, nil)
com.ToStr(user.ID)+email+user.LowerName+user.Password+user.Rands, 180, nil)

// Add tail hex username
code += hex.EncodeToString([]byte(user.LowerName))
@@ -345,4 +345,4 @@ func (mUser mailerUser) GenerateEmailActivateCode(email string) string {
// NewMailerUser mail user
func NewMailerUser(u *User) mailer.User {
return mailerUser{u}
}
}

+ 4
- 4
routers/admin/admin.go View File

@@ -2,11 +2,11 @@ package admin

import (
"dev.sigpipe.me/dashie/git.txt/context"
"time"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"dev.sigpipe.me/dashie/git.txt/stuff/cron"
"runtime"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"fmt"
"runtime"
"time"
)

const (
@@ -107,4 +107,4 @@ func Dashboard(ctx *context.Context) {
ctx.Data["SysStatus"] = sysStatus
ctx.Data["Entries"] = cron.ListTasks()
ctx.HTML(200, tmplDashboard)
}
}

+ 3
- 3
routers/gitxt/gitxt.go View File

@@ -14,7 +14,7 @@ import (
"fmt"
"github.com/Unknwon/paginater"
log "gopkg.in/clog.v1"
"gopkg.in/libgit2/git2go.v25"
"gopkg.in/libgit2/git2go.v26"
gotemplate "html/template"
"os"
"path/filepath"
@@ -244,7 +244,7 @@ func NewPost(ctx *context.Context, f form.Gitxt) {
models.UpdateCounterGitxtsManaged(counterManaged.Count + 1)

// 5. Return render to gitxt view page
log.Trace("Pushed repository %s to database as %i", repositoryName, u.ID)
log.Trace("Pushed repository %s to database as %d", repositoryName, u.ID)
ctx.Redirect(setting.AppSubURL + "/" + repositoryUser + "/" + repositoryName)
}

@@ -753,7 +753,7 @@ func EditPost(ctx *context.Context, f form.GitxtEdit) {

// 5. Return render to gitxt view page

log.Trace("Edit Pushed repository %s - %i", ctx.Gitxt.Gitxt.Hash, ctx.Gitxt.Gitxt.ID)
log.Trace("Edit Pushed repository %s - %d", ctx.Gitxt.Gitxt.Hash, ctx.Gitxt.Gitxt.ID)
ctx.Redirect(setting.AppSubURL + "/" + repositoryUser + "/" + ctx.Gitxt.Gitxt.Hash)

}

+ 1
- 1
routers/hub.go View File

@@ -6,4 +6,4 @@ import "dev.sigpipe.me/dashie/git.txt/context"
func NotFound(ctx *context.Context) {
ctx.Title(ctx.Tr("error.page_not_found"))
ctx.Handle(404, "home.NotFound", nil)
}
}

+ 13
- 13
routers/repo/archive.go View File

@@ -5,23 +5,23 @@ import (
"dev.sigpipe.me/dashie/git.txt/stuff/repository"
log "gopkg.in/clog.v1"

"gopkg.in/libgit2/git2go.v25"
"strings"
"path"
"dev.sigpipe.me/dashie/git.txt/stuff/gite"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"github.com/Unknwon/com"
"gopkg.in/libgit2/git2go.v26"
"os"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"dev.sigpipe.me/dashie/git.txt/stuff/gite"
"path"
"strings"
)

// DownloadArchive of repository
func DownloadArchive(ctx *context.Context) {
var (
uri = ctx.Params("*")
refName string
ext string
archivePath string
archiveType string
uri = ctx.Params("*")
refName string
ext string
archivePath string
archiveType string
)

pathRepo := repository.RepoPath(ctx.RepoOwnerUsername, ctx.Gitxt.Gitxt.Hash)
@@ -40,7 +40,7 @@ func DownloadArchive(ctx *context.Context) {
ctx.Error(404)
return
}
refName = strings.TrimSuffix(uri, ext)
if refName != "master" {
ctx.Handle(500, "Ref other than master not supported", nil)
@@ -65,7 +65,7 @@ func DownloadArchive(ctx *context.Context) {
}

// Test if repository is empty
isEmpty, err := repo.IsEmpty();
isEmpty, err := repo.IsEmpty()
if err != nil || isEmpty {
log.Warn("Empty repository or corrupted %s: %s", ctx.Gitxt.Gitxt.Hash, err)
ctx.Flash.Error(ctx.Tr("gitxt_git.repo_corrupt_or_empty"))
@@ -116,4 +116,4 @@ func DownloadArchive(ctx *context.Context) {
}

ctx.ServeFile(archivePath, ctx.Gitxt.Gitxt.Hash+"-"+refName+ext)
}
}

+ 24
- 24
routers/repo/repo.go View File

@@ -4,25 +4,25 @@
package repo

import (
"gopkg.in/macaron.v1"
"bytes"
"compress/gzip"
"dev.sigpipe.me/dashie/git.txt/context"
"strings"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"net/http"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"dev.sigpipe.me/dashie/git.txt/setting"
log "gopkg.in/clog.v1"
"regexp"
"time"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"fmt"
"path"
"os"
"github.com/Unknwon/com"
"compress/gzip"
"bytes"
log "gopkg.in/clog.v1"
"gopkg.in/macaron.v1"
"net/http"
"os"
"os/exec"
"path"
"regexp"
"strconv"
"strings"
"time"
)

const (
@@ -39,11 +39,11 @@ const (
// HTTPContext struct
type HTTPContext struct {
*context.Context
OwnerName string
OwnerSalt string
RepoID int64
RepoName string
AuthUser *models.User
OwnerName string
OwnerSalt string
RepoID int64
RepoName string
AuthUser *models.User
}

// askCredentials responses HTTP header and status which informs client to provide credentials
@@ -125,18 +125,18 @@ func HTTPContexter() macaron.Handler {
log.Trace("HTTPGit - Authenticated user: %s", authUser.UserName)

// Reject if not pulling and user doesn't match repo ID
if authUser.ID != repo.UserID && !isPull {
if authUser.ID != repo.UserID && !isPull {
askCredentials(ctx, http.StatusForbidden, "User permission denied")
return
}

ctx.Map(&HTTPContext{
Context: ctx,
Context: ctx,
OwnerName: ownerName,
OwnerSalt: owner.Salt,
RepoID: repo.ID,
RepoName: repoName,
AuthUser: authUser,
RepoID: repo.ID,
RepoName: repoName,
AuthUser: authUser,
})

}
@@ -250,7 +250,7 @@ func serviceRPC(h serviceHandler, service string) {
cmd.Stderr = &stderr
cmd.Stdin = reqBody
if err = cmd.Run(); err != nil {
log.Error(2, "HTTP.serviceRPC: fail to serve RPC '%s': %v - %s", service, err, stderr)
log.Error(2, "HTTP.serviceRPC: fail to serve RPC '%s': %v - %q", service, err, stderr)
h.w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -413,6 +413,6 @@ func HTTP(ctx *HTTPContext) {
return
}

log.Trace("Not found %s", ctx.Req.Request)
log.Trace("Not found %s", ctx.Req.Request.URL.Path)
ctx.NotFound()
}
}

+ 10
- 11
routers/user/auth.go View File

@@ -2,14 +2,14 @@ package user

import (
"dev.sigpipe.me/dashie/git.txt/context"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"dev.sigpipe.me/dashie/git.txt/setting"
"dev.sigpipe.me/dashie/git.txt/stuff/form"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/stuff/mailer"
"fmt"
log "gopkg.in/clog.v1"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"net/url"
"fmt"
)

const (
@@ -153,7 +153,7 @@ func afterLogin(ctx *context.Context, u *models.User, remember bool) {
// Register GET
func Register(ctx *context.Context) {
ctx.Title("register.title")
if ! setting.CanRegister {
if !setting.CanRegister {
ctx.Flash.Error(ctx.Tr("register.not_allowed"))
ctx.Redirect(setting.AppSubURL + "/")
return
@@ -166,7 +166,7 @@ func Register(ctx *context.Context) {
func RegisterPost(ctx *context.Context, f form.Register) {
ctx.Title("register.title")

if ! setting.CanRegister {
if !setting.CanRegister {
ctx.Flash.Error(ctx.Tr("register.not_allowed"))
ctx.Redirect(setting.AppSubURL + "/")
return
@@ -185,10 +185,10 @@ func RegisterPost(ctx *context.Context, f form.Register) {
}

u := &models.User{
UserName: f.UserName,
Email: f.Email,
Password: f.Password,
IsActive: true, // FIXME: implement user activation by email
UserName: f.UserName,
Email: f.Email,
Password: f.Password,
IsActive: true, // FIXME: implement user activation by email
}
if err := models.CreateUser(u); err != nil {
switch {
@@ -234,7 +234,6 @@ func Logout(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/")
}


// ResetPasswd GET
func ResetPasswd(ctx *context.Context) {
ctx.Title("auth.reset_password")
@@ -352,4 +351,4 @@ func ForgotPasswdPost(ctx *context.Context) {
ctx.Data["Hours"] = 180 / 60
ctx.Data["IsResetSent"] = true
ctx.HTML(200, tmplForgotPassword)
}
}

+ 2
- 2
routers/user/setting.go View File

@@ -2,8 +2,8 @@ package user

import (
"dev.sigpipe.me/dashie/git.txt/context"
"dev.sigpipe.me/dashie/git.txt/stuff/form"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/stuff/form"
)

const (
@@ -37,4 +37,4 @@ func SettingsPost(ctx *context.Context, f form.UpdateSettingsProfile) {

ctx.Flash.Success(ctx.Tr("settings.update_profile_success"))
ctx.SubURLRedirect("/user/settings")
}
}

+ 54
- 56
setting/setting.go View File

@@ -1,20 +1,20 @@
package setting

import (
"os"
"strings"
"runtime"
"os/exec"
"path/filepath"
"github.com/Unknwon/com"
"github.com/go-macaron/session"
log "gopkg.in/clog.v1"
"gopkg.in/ini.v1"
"net/mail"
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strconv"
"github.com/Unknwon/com"
"net/url"
"github.com/go-macaron/session"
"strings"
"time"
"net/mail"
)

// Scheme type
@@ -28,44 +28,43 @@ const (
SchemeUnixSocket Scheme = "unix"
)


// Settings
var (
// Build infos added by -ldflags
BuildTime string
BuildGitHash string
BuildTime string
BuildGitHash string

// App Settings

AppVer string
AppPath string
AppVer string
AppPath string
AppName string
AppURL string
AppURL string
AppSubURL string
AppSubURLDepth int // Number of slashes
CanRegister bool
AnonymousCreate bool
ProdMode bool
CanRegister bool
AnonymousCreate bool
ProdMode bool

// Cron tasks
Cron struct {
RepoArchiveCleanup struct {
Enabled bool
RunAtStart bool
Schedule string
OlderThan time.Duration
Enabled bool
RunAtStart bool
Schedule string
OlderThan time.Duration
} `ini:"cron.repo_archive_cleanup"`
}

// Server settings

Protocol Scheme
UnixSocketPermission uint32
Domain string
HTTPAddr string
HTTPPort string
DisableRouterLog bool
StaticRootPath string
Protocol Scheme
UnixSocketPermission uint32
Domain string
HTTPAddr string
HTTPPort string
DisableRouterLog bool
StaticRootPath string

HTTP struct {
AccessControlAllowOrigin string
@@ -73,24 +72,24 @@ var (

// Database Settings

UseSQLite3 bool
UseMySQL bool
UsePostgreSQL bool
UseMSSQL bool
UseSQLite3 bool
UseMySQL bool
UsePostgreSQL bool
UseMSSQL bool

// Global setting objects

CustomConf string
IsWindows bool
Cfg *ini.File
HasRobotsTxt bool
RobotsTxtPath string
CustomConf string
IsWindows bool
Cfg *ini.File
HasRobotsTxt bool
RobotsTxtPath string

// Log settings

LogRootPath string
LogModes []string
LogConfigs []interface{}
LogRootPath string
LogModes []string
LogConfigs []interface{}

// Repository settings

@@ -112,13 +111,13 @@ var (
CookieRememberName string
CookieSecure bool
EnableLoginStatusCookie bool
LoginStatusCookieName string
LoginStatusCookieName string

// Cache settings

CacheAdapter string
CacheInterval int
CacheConn string
CacheConn string

// Langs settings
Langs []string
@@ -127,25 +126,25 @@ var (

// Markdown sttings
Markdown struct {
EnableHardLineBreak bool
CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
FileExtensions []string
EnableHardLineBreak bool
CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
FileExtensions []string
}

// Smartypants settings
Smartypants struct {
Enabled bool
Fractions bool
Dashes bool
LatexDashes bool
AngledQuotes bool
Enabled bool
Fractions bool
Dashes bool
LatexDashes bool
AngledQuotes bool
}

// Bloby struct for static limitations
Bloby struct {
MaxSizeDisplay int64
MaxPageDisplay int64
MaxRawSize int64
MaxSizeDisplay int64
MaxPageDisplay int64
MaxRawSize int64
}
)

@@ -205,7 +204,7 @@ func forcePathSeparator(path string) {
func InitConfig() {
workDir, err := WorkDir()
if err != nil {
log.Fatal(2,"Fail to get work directory: %v", err)
log.Fatal(2, "Fail to get work directory: %v", err)
}

if len(CustomConf) == 0 {
@@ -489,4 +488,3 @@ func initMailer() {

log.Info("Mail Service Enabled")
}


+ 1
- 1
stuff/auth/auth.go View File

@@ -5,9 +5,9 @@
package auth

import (
"strings"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/models/errors"
"strings"

"github.com/go-macaron/session"
log "gopkg.in/clog.v1"

+ 7
- 7
stuff/cron/cron.go View File

@@ -1,10 +1,10 @@
package cron

import (
log "gopkg.in/clog.v1"
"github.com/gogits/cron"
"dev.sigpipe.me/dashie/git.txt/setting"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/setting"
"github.com/gogits/cron"
log "gopkg.in/clog.v1"
"time"
)

@@ -13,8 +13,8 @@ var c = cron.New()
// NewContext initialize Cron stuff
func NewContext() {
var (
entry *cron.Entry
err error
entry *cron.Entry
err error
)

if setting.Cron.RepoArchiveCleanup.Enabled {
@@ -34,7 +34,7 @@ func NewContext() {
if err != nil {
log.Fatal(2, "Cron.(delete expired repositories): %v", err)
}
entry.Next = time.Now().Add(time.Minute*1)
entry.Next = time.Now().Add(time.Minute * 1)

c.Start()
}
@@ -42,4 +42,4 @@ func NewContext() {
// ListTasks returns all running cron tasks.
func ListTasks() []*cron.Entry {
return c.Entries()
}
}

+ 2
- 2
stuff/form/auth.go View File

@@ -10,7 +10,7 @@ type Register struct {
UserName string `binding:"Required;AlphaDashDot;MaxSize(35)"`
Email string `binding:"Required;Email;MaxSize(254)"`
Password string `binding:"Required;MaxSize(255)"`
Repeat string
Repeat string
}

// Validate func
@@ -28,4 +28,4 @@ type Login struct {
// Validate func
func (f *Login) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale)
}
}

+ 6
- 6
stuff/form/form.go View File

@@ -1,14 +1,14 @@
package form

import (
"reflect"
"fmt"
"github.com/Unknwon/com"
"github.com/go-macaron/binding"
log "gopkg.in/clog.v1"
"gopkg.in/macaron.v1"
"github.com/Unknwon/com"
"strings"
"reflect"
"regexp"
"fmt"
log "gopkg.in/clog.v1"
"strings"
)

const errAlphaDashDotSlash = "AlphaDashDotSlashError"
@@ -157,4 +157,4 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro
}
}
return errs
}
}

+ 9
- 9
stuff/form/gitxt.go View File

@@ -1,8 +1,8 @@
package form

import (
"gopkg.in/macaron.v1"
"github.com/go-macaron/binding"
"gopkg.in/macaron.v1"
)

// Gitxt form struct
@@ -11,11 +11,11 @@ type Gitxt struct {
IsPublic bool `binding:"Default:1"`
// Validation builtin into Macaron/Binding doesn't validates theses slices
// See the router view for manual validation
FilesFilename []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
FilesContent []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
FilesFilename []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
FilesContent []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`

// no, 1h, 4h, 1d, 2d, 3d, 4d, 5d, 6d, 7d, 1m, 1y
ExpiryHours int64 `binding:"In(0,1,4,24,48,72,96,120,144,168,730,8760);Default(0)"`
ExpiryHours int64 `binding:"In(0,1,4,24,48,72,96,120,144,168,730,8760);Default(0)"`
}

// Validate func
@@ -25,8 +25,8 @@ func (f *Gitxt) Validate(ctx *macaron.Context, errs binding.Errors) binding.Erro

// GitxtDelete form
type GitxtDelete struct {
Hash string `binding:"Required"`
Owner string `binding:"Required"`
Hash string `binding:"Required"`
Owner string `binding:"Required"`
}

// Validate func
@@ -39,12 +39,12 @@ type GitxtEdit struct {
Description string `binding:"MaxSize(255)"`
// Validation builtin into Macaron/Binding doesn't validates theses slices
// See the router view for manual validation
FilesFilename []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
FilesContent []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
FilesFilename []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
FilesContent []string `binding:"Required;MaxSize(255);MinSizeSlice(1)"`
FilesNotHandled []bool

// no, 1h, 4h, 1d, 2d, 3d, 4d, 5d, 6d, 7d, 1m, 1y
ExpiryHours int64 `binding:"In(0,1,4,24,48,72,96,120,144,168,730,8760);Default(0)"`
ExpiryHours int64 `binding:"In(0,1,4,24,48,72,96,120,144,168,730,8760);Default(0)"`
}

// Validate struct

+ 1
- 1
stuff/form/user.go View File

@@ -1,8 +1,8 @@
package form

import (
"gopkg.in/macaron.v1"
"github.com/go-macaron/binding"
"gopkg.in/macaron.v1"
)

// UpdateSettingsProfile form struct

+ 1
- 1
stuff/gite/gite.go View File

@@ -5,7 +5,7 @@ import (
"archive/zip"
"dev.sigpipe.me/dashie/git.txt/setting"
"github.com/rakyll/magicmime"
"gopkg.in/libgit2/git2go.v25"
"gopkg.in/libgit2/git2go.v26"
gotemplate "html/template"
"os"
"path/filepath"

+ 1
- 1
stuff/markup/markdown_test.go View File

@@ -9,8 +9,8 @@ import (

. "github.com/smartystreets/goconvey/convey"

. "dev.sigpipe.me/dashie/git.txt/stuff/markup"
"dev.sigpipe.me/dashie/git.txt/setting"
. "dev.sigpipe.me/dashie/git.txt/stuff/markup"
)

func Test_IsMarkdownFile(t *testing.T) {

+ 1
- 1
stuff/markup/markup.go View File

@@ -14,8 +14,8 @@ import (
"github.com/Unknwon/com"
"golang.org/x/net/html"

"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"dev.sigpipe.me/dashie/git.txt/setting"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
)

// IsReadmeFile reports whether name looks like a README file based on its extension.

+ 2
- 2
stuff/repository/repository.go View File

@@ -1,8 +1,8 @@
package repository

import (
git "gopkg.in/libgit2/git2go.v25"
"dev.sigpipe.me/dashie/git.txt/setting"
git "gopkg.in/libgit2/git2go.v26"
"path"
)

@@ -22,4 +22,4 @@ func InitRepository(username string, repoName string) (*git.Repository, error) {
return nil, err
}
return repo, err
}
}

+ 2
- 2
stuff/template/highlight/highlight.go View File

@@ -20,8 +20,8 @@ var (
// File names that are representing highlight classes.
highlightFileNames = map[string]bool{
"cmakelists.txt": true,
"dockerfile": true,
"makefile": true,
"dockerfile": true,
"makefile": true,
}

// Extensions that are same as highlight classes.

+ 21
- 21
stuff/template/template.go View File

@@ -1,20 +1,20 @@
package template

import (
"time"
"strings"
"mime"
"path/filepath"
"fmt"
"runtime"
"html/template"
"container/list"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/setting"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"github.com/microcosm-cc/bluemonday"
"dev.sigpipe.me/dashie/git.txt/stuff/markup"
"dev.sigpipe.me/dashie/git.txt/stuff/template/highlight"
"container/list"
"dev.sigpipe.me/dashie/git.txt/models"
"dev.sigpipe.me/dashie/git.txt/stuff/tool"
"fmt"
"github.com/microcosm-cc/bluemonday"
"html/template"
"mime"
"path/filepath"
"runtime"
"strings"
"time"
)

// NewFuncMap initialize the Functions Map
@@ -50,9 +50,9 @@ func NewFuncMap() []template.FuncMap {
"LoadTimes": func(startTime time.Time) string {
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
},
"FileSize": tool.FileSize,
"Safe": safe,
"Sanitize": bluemonday.UGCPolicy().Sanitize,
"FileSize": tool.FileSize,
"Safe": safe,
"Sanitize": bluemonday.UGCPolicy().Sanitize,
"Str2html": str2html,
"Add": func(a, b int) int {
return a + b
@@ -60,7 +60,7 @@ func NewFuncMap() []template.FuncMap {
"DateFmtLong": func(t time.Time) string {
return t.Format(time.RFC1123Z)
},
"DateFmtShort": func(t time.Time) string {
"DateFmtShort": func(t time.Time) string {
return t.Format("Jan 02, 2006")
},
"List": listWhatever,
@@ -77,11 +77,11 @@ func NewFuncMap() []template.FuncMap {
}
return str[start:end]
},
"Join": strings.Join,
"Sha1": sha1,
"ShortSHA1": tool.ShortSHA1,
"MD5": tool.MD5,
"EscapePound": escapePound,
"Join": strings.Join,
"Sha1": sha1,
"ShortSHA1": tool.ShortSHA1,
"MD5": tool.MD5,
"EscapePound": escapePound,
"FilenameIsImage": func(filename string) bool {
mimeType := mime.TypeByExtension(filepath.Ext(filename))
return strings.HasPrefix(mimeType, "image/")
@@ -136,4 +136,4 @@ func escapePound(str string) string {

func str2html(raw string) template.HTML {
return template.HTML(markup.Sanitize(raw))
}
}

+ 1
- 1
stuff/tool/file_test.go View File

@@ -13,7 +13,7 @@ import (
func Test_FileSize(t *testing.T) {
Convey("File size to human", t, func() {
testCases := []struct {
size int64
size int64
human string
}{
{6, "6 B"},

+ 7
- 7
stuff/tool/tool.go View File

@@ -1,17 +1,17 @@
package tool

import (
"encoding/hex"
"crypto/sha1"
"crypto/md5"
"math/big"
"crypto/rand"
"strings"
"crypto/sha1"
"dev.sigpipe.me/dashie/git.txt/setting"
"encoding/base64"
"time"
"encoding/hex"
"fmt"
"github.com/Unknwon/com"
"dev.sigpipe.me/dashie/git.txt/setting"
"math/big"
"strings"
"time"
)

const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
@@ -233,4 +233,4 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string

code := fmt.Sprintf("%s%06d%s", startStr, minutes, encoded)
return code
}
}

+ 6
- 6
stuff/tool/tool_test.go View File

@@ -13,7 +13,7 @@ import (
func Test_MD5(t *testing.T) {
Convey("Validate MD5", t, func() {
testCases := []struct {
src string
src string
hash string
}{
{"coincoin", "3dc6862aaced087142142587cba2123e"},
@@ -30,7 +30,7 @@ func Test_MD5(t *testing.T) {
func Test_SHA1(t *testing.T) {
Convey("Validate SHA1", t, func() {
testCases := []struct {
src string
src string
hash string
}{
{"coincoin", "0f78ee98759868a8b5d5aeb6b9dbd2106b14e965"},
@@ -47,7 +47,7 @@ func Test_SHA1(t *testing.T) {
func Test_ShortSHA1(t *testing.T) {
Convey("Validate SHA1", t, func() {
testCases := []struct {
src string
src string
hash string
}{
{"0aadb9081430eb80435b9a442484387f9a443a65", "0aadb90814"},
@@ -63,7 +63,7 @@ func Test_ShortSHA1(t *testing.T) {

func Test_RandomString(t *testing.T) {
Convey("Test random string size 5", t, func() {
for i := 0; i<10; i++ {
for i := 0; i < 10; i++ {
r1, _ := RandomString(5)
r2, _ := RandomString(5)
So(r1, ShouldNotEqual, r2)
@@ -71,7 +71,7 @@ func Test_RandomString(t *testing.T) {
})

Convey("Test random string size 10", t, func() {
for i := 0; i<10; i++ {
for i := 0; i < 10; i++ {
r1, _ := RandomString(10)
r2, _ := RandomString(10)
So(r1, ShouldNotEqual, r2)
@@ -79,7 +79,7 @@ func Test_RandomString(t *testing.T) {
})

Convey("Test random string size 20", t, func() {
for i := 0; i<10; i++ {
for i := 0; i < 10; i++ {
r1, _ := RandomString(20)
r2, _ := RandomString(20)
So(r1, ShouldNotEqual, r2)

Loading…
Cancel
Save