aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorlunnyxiao <xiaolunwen@gmail.com>2014-09-22 10:43:16 +0800
committerlunnyxiao <xiaolunwen@gmail.com>2014-09-22 10:43:16 +0800
commit150eef93b2340f665c070158ade1863339829e05 (patch)
tree6c44b11cfcd4d74cec98c25b734608296020cc75 /modules
parent7ba9257a7ff659417501baf7358216555cebcd86 (diff)
downloadgitea-150eef93b2340f665c070158ade1863339829e05.tar.gz
gitea-150eef93b2340f665c070158ade1863339829e05.zip
add submodule basic support & buf fixed #478
Diffstat (limited to 'modules')
-rw-r--r--modules/git/commit.go50
-rw-r--r--modules/git/submodule.go6
-rw-r--r--modules/git/tree.go2
-rw-r--r--modules/git/tree_entry.go4
4 files changed, 61 insertions, 1 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 52348fefed..d2d373da12 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -5,6 +5,7 @@
package git
import (
+ "bufio"
"container/list"
"strings"
)
@@ -17,7 +18,8 @@ type Commit struct {
Committer *Signature
CommitMessage string
- parents []sha1 // sha1 strings
+ parents []sha1 // sha1 strings
+ submodules map[string]*SubModule
}
// 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) {
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
+}
diff --git a/modules/git/submodule.go b/modules/git/submodule.go
new file mode 100644
index 0000000000..28b5b9f375
--- /dev/null
+++ b/modules/git/submodule.go
@@ -0,0 +1,6 @@
+package git
+
+type SubModule struct {
+ Name string
+ Url string
+}
diff --git a/modules/git/tree.go b/modules/git/tree.go
index 03152c34ac..a3012443d7 100644
--- a/modules/git/tree.go
+++ b/modules/git/tree.go
@@ -51,6 +51,8 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
case "160000":
entry.mode = ModeCommit
entry.Type = COMMIT
+
+ step = 8
case "040000":
entry.mode = ModeTree
entry.Type = TREE
diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go
index e842f2332a..f65f332666 100644
--- a/modules/git/tree_entry.go
+++ b/modules/git/tree_entry.go
@@ -61,6 +61,10 @@ func (te *TreeEntry) Size() int64 {
return te.size
}
+func (te *TreeEntry) IsSubModule() bool {
+ return te.mode == ModeCommit
+}
+
func (te *TreeEntry) IsDir() bool {
return te.mode == ModeTree
}