add submodule basic support & buf fixed #478

tokarchuk/v1.17
lunnyxiao 10 years ago
parent 7ba9257a7f
commit 150eef93b2
  1. 48
      modules/git/commit.go
  2. 6
      modules/git/submodule.go
  3. 2
      modules/git/tree.go
  4. 4
      modules/git/tree_entry.go
  5. 5
      routers/repo/http.go
  6. 30
      routers/repo/view.go
  7. 15
      templates/repo/view_list.tmpl

@ -5,6 +5,7 @@
package git package git
import ( import (
"bufio"
"container/list" "container/list"
"strings" "strings"
) )
@ -18,6 +19,7 @@ type Commit struct {
CommitMessage string CommitMessage string
parents []sha1 // sha1 strings parents []sha1 // sha1 strings
submodules map[string]*SubModule
} }
// Return the commit message. Same as retrieving CommitMessage directly. // Return the commit message. Same as retrieving CommitMessage directly.
@ -84,3 +86,49 @@ func (c *Commit) CommitsByRange(page int) (*list.List, error) {
func (c *Commit) GetCommitOfRelPath(relPath string) (*Commit, error) { func (c *Commit) GetCommitOfRelPath(relPath string) (*Commit, error) {
return c.repo.getCommitOfRelPath(c.Id, relPath) return c.repo.getCommitOfRelPath(c.Id, relPath)
} }
func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
moduels, err := c.GetSubModules()
if err != nil {
return nil, err
}
return moduels[entryname], nil
}
func (c *Commit) GetSubModules() (map[string]*SubModule, error) {
if c.submodules != nil {
return c.submodules, nil
}
entry, err := c.GetTreeEntryByPath(".gitmodules")
if err != nil {
return nil, err
}
rd, err := entry.Blob().Data()
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(rd)
c.submodules = make(map[string]*SubModule)
var ismodule bool
var path string
for scanner.Scan() {
if strings.HasPrefix(scanner.Text(), "[submodule") {
ismodule = true
continue
}
if ismodule {
fields := strings.Split(scanner.Text(), "=")
k := strings.TrimSpace(fields[0])
if k == "path" {
path = strings.TrimSpace(fields[1])
} else if k == "url" {
c.submodules[path] = &SubModule{path, strings.TrimSpace(fields[1])}
ismodule = false
}
}
}
return c.submodules, nil
}

@ -0,0 +1,6 @@
package git
type SubModule struct {
Name string
Url string
}

@ -51,6 +51,8 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
case "160000": case "160000":
entry.mode = ModeCommit entry.mode = ModeCommit
entry.Type = COMMIT entry.Type = COMMIT
step = 8
case "040000": case "040000":
entry.mode = ModeTree entry.mode = ModeTree
entry.Type = TREE entry.Type = TREE

@ -61,6 +61,10 @@ func (te *TreeEntry) Size() int64 {
return te.size return te.size
} }
func (te *TreeEntry) IsSubModule() bool {
return te.mode == ModeCommit
}
func (te *TreeEntry) IsDir() bool { func (te *TreeEntry) IsDir() bool {
return te.mode == ModeTree return te.mode == ModeTree
} }

@ -103,6 +103,7 @@ func Http(ctx *middleware.Context) {
// check access // check access
if askAuth { if askAuth {
baHead := ctx.Req.Header.Get("Authorization") baHead := ctx.Req.Header.Get("Authorization")
fmt.Println("auth:", baHead)
if baHead == "" { if baHead == "" {
authRequired(ctx) authRequired(ctx)
return return
@ -121,6 +122,8 @@ func Http(ctx *middleware.Context) {
return return
} }
fmt.Println("auth2:", authUsername, passwd)
authUser, err = models.GetUserByName(authUsername) authUser, err = models.GetUserByName(authUsername)
if err != nil { if err != nil {
ctx.Handle(401, "no basic auth and digit auth", nil) ctx.Handle(401, "no basic auth and digit auth", nil)
@ -134,6 +137,8 @@ func Http(ctx *middleware.Context) {
return return
} }
fmt.Println("passwd is right")
if !isPublicPull { if !isPublicPull {
var tp = models.WRITABLE var tp = models.WRITABLE
if isPull { if isPull {

@ -10,6 +10,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/git"
@ -21,6 +22,15 @@ const (
HOME base.TplName = "repo/home" HOME base.TplName = "repo/home"
) )
type fakeCommit struct {
Id string
Summary string
Url string
Committer struct {
When time.Time
}
}
func Home(ctx *middleware.Context) { func Home(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Repo.Repository.Name ctx.Data["Title"] = ctx.Repo.Repository.Name
@ -127,13 +137,31 @@ func Home(ctx *middleware.Context) {
files := make([][]interface{}, 0, len(entries)) files := make([][]interface{}, 0, len(entries))
for _, te := range entries { for _, te := range entries {
if te.Type != git.COMMIT {
c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name())) c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name()))
if err != nil { if err != nil {
ctx.Handle(404, "GetCommitOfRelPath", err) ctx.Handle(404, "GetCommitOfRelPath", err)
return return
} }
files = append(files, []interface{}{te, c}) files = append(files, []interface{}{te, c})
} else {
sm, err := ctx.Repo.Commit.GetSubModule(path.Join(treename, te.Name()))
if err != nil {
ctx.Handle(404, "GetSubModule", err)
return
}
commit := git.Commit{
Tree: *tree,
Id: te.Id,
Committer: &git.Signature{
When: time.Now(),
},
CommitMessage: sm.Url,
}
files = append(files, []interface{}{te, &commit})
}
} }
ctx.Data["Files"] = files ctx.Data["Files"] = files

@ -27,8 +27,20 @@
{{$entry := index $item 0}} {{$entry := index $item 0}}
{{$commit := index $item 1}} {{$commit := index $item 1}}
<tr> <tr>
{{if $entry.IsSubModule}}
<td class="icon"> <td class="icon">
<span class="octicon octicon-file-{{if $entry.IsDir}}directory{{else}}text{{end}}"></span> <span class="octicon octicon-file-submodule"></span>
</td>
<td class="name">
<a href="{{$commit.CommitMessage}}" class="text-truncate">{{$entry.Name}}</a> @ <a href="{{$commit.CommitMessage}}/commit/{{$commit.Id}}">{{ShortSha $commit.Id.String}}</a>
</td>
<td class="msg">
<a class="text-truncate" href="{{$commit.CommitMessage}}/commit/{{$commit.Id}}" rel="nofollow">{{$commit.Summary}}</a>
</td>
<td class="age">{{TimeSince $commit.Committer.When $.i18n.Lang}}</td>
{{else}}
<td class="icon">
<span class="octicon octicon-file-{{if or $entry.IsDir}}directory{{else}}text{{end}}"></span>
</td> </td>
<td class="name"> <td class="name">
<a href="{{$.BranchLink}}/{{$.TreePath}}{{$entry.Name}}" class="text-truncate">{{$entry.Name}}</a> <a href="{{$.BranchLink}}/{{$.TreePath}}{{$entry.Name}}" class="text-truncate">{{$entry.Name}}</a>
@ -37,6 +49,7 @@
<a class="text-truncate" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{$commit.Id}}" rel="nofollow">{{$commit.Summary}}</a> <a class="text-truncate" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{$commit.Id}}" rel="nofollow">{{$commit.Summary}}</a>
</td> </td>
<td class="age">{{TimeSince $commit.Committer.When $.i18n.Lang}}</td> <td class="age">{{TimeSince $commit.Committer.When $.i18n.Lang}}</td>
{{end}}
</tr> </tr>
{{end}} {{end}}
</tbody> </tbody>

Loading…
Cancel
Save