diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-14 23:54:16 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-14 23:54:16 +0800 |
commit | b27e8e87f8be2d11468e9057254b6c8933e0af33 (patch) | |
tree | bbfb32d7e248ae6f2ec63164722523d96447848a /models | |
parent | 607303e4dee3ddf9ba3d9d67b0186fc5213b167b (diff) | |
parent | d18237850c6a4ae855b3f8592994c91462fcdb0a (diff) |
add tree view
Diffstat (limited to 'models')
-rw-r--r-- | models/repo.go | 34 | ||||
-rw-r--r-- | models/user.go | 6 |
2 files changed, 35 insertions, 5 deletions
diff --git a/models/repo.go b/models/repo.go index a44bf69a..c5fa899f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -9,6 +9,7 @@ import ( "fmt" "io/ioutil" "os" + "path" "path/filepath" "strings" "time" @@ -270,6 +271,7 @@ type RepoFile struct { Id *git.Oid Type int Name string + Path string Message string Created time.Time } @@ -282,7 +284,7 @@ func (f *RepoFile) IsDir() bool { return f.Type == git.FilemodeTree } -func GetReposFiles(userName, reposName, treeName, rpath string) ([]*RepoFile, error) { +func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { f := RepoPath(userName, reposName) repo, err := git.OpenRepository(f) if err != nil { @@ -299,8 +301,28 @@ func GetReposFiles(userName, reposName, treeName, rpath string) ([]*RepoFile, er if err != nil { return nil, err } - var i uint64 = 0 - for ; i < tree.EntryCount(); i++ { + //var i uint64 = 0 + if rpath != "" { + rpath = rpath + "/" + } + fmt.Println("...", rpath, "...") + + tree.Walk(func(dirname string, entry *git.TreeEntry) int { + if dirname == rpath { + fmt.Println("====", dirname, "==", entry.Name) + repofiles = append(repofiles, &RepoFile{ + entry.Id, + entry.Filemode, + entry.Name, + path.Join(dirname, entry.Name), + lastCommit.Message(), + lastCommit.Committer().When, + }) + } + return 0 + }) + + /*for ; i < tree.EntryCount(); i++ { entry := tree.EntryByIndex(i) repofiles = append(repofiles, &RepoFile{ @@ -310,7 +332,7 @@ func GetReposFiles(userName, reposName, treeName, rpath string) ([]*RepoFile, er lastCommit.Message(), lastCommit.Committer().When, }) - } + }*/ return repofiles, nil } @@ -354,6 +376,10 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) { session.Rollback() return err } + if _, err := session.Delete(&Access{UserName: userName, RepoName: repo.Name}); err != nil { + session.Rollback() + return err + } if _, err = session.Exec("update user set num_repos = num_repos - 1 where id = ?", userId); err != nil { session.Rollback() return err diff --git a/models/user.go b/models/user.go index c59e4ae1..8f7a37cb 100644 --- a/models/user.go +++ b/models/user.go @@ -48,7 +48,10 @@ type User struct { NumFollowings int NumStars int NumRepos int - Avatar string `xorm:"varchar(2048) not null"` + Avatar string `xorm:"varchar(2048) not null"` + AvatarEmail string `xorm:"not null"` + Location string + Website string Created time.Time `xorm:"created"` Updated time.Time `xorm:"updated"` } @@ -104,6 +107,7 @@ func RegisterUser(user *User) (err error) { user.LowerName = strings.ToLower(user.Name) user.Avatar = base.EncodeMd5(user.Email) + user.AvatarEmail = user.Email if err = user.EncodePasswd(); err != nil { return err } |