@@ -90,8 +90,10 @@ func (c *Cache) tracByRef(refname string) (*Trac, error) {
90
90
// any cycles when traversing the commit+submodule hierarchy, although the
91
91
// same sub-objects may occur many times at different points in the tree.
92
92
func (c * Cache ) tracCommit (path string , commit * object.Commit ) (* Trac , error ) {
93
+ // debugf("commit %.10v %v\n", commit.Hash, path)
93
94
trac := c .tracs [commit .Hash ]
94
95
if trac != nil {
96
+ // debugf(" found: %v\n", trac)
95
97
return trac , nil
96
98
}
97
99
trac = & Trac {
@@ -113,8 +115,11 @@ func (c *Cache) tracCommit(path string, commit *object.Commit) (*Trac, error) {
113
115
}
114
116
np := commitPath (path , i + 1 )
115
117
_ , err = c .tracCommit (np , pc )
118
+ if err != nil {
119
+ return nil , err
120
+ }
116
121
}
117
- c .tracs [ commit . Hash ] = trac
122
+ c .add ( trac )
118
123
return trac , nil
119
124
}
120
125
@@ -140,12 +145,21 @@ func (c *Cache) tracTree(path string, tree *object.Tree) (*Trac, error) {
140
145
}
141
146
for _ , e := range tree .Entries {
142
147
if e .Mode == filemode .Submodule {
143
- debugf ("submodule: %v/\n " , e .Name )
148
+ sc , err := c .repo .CommitObject (e .Hash )
149
+ subpath := fmt .Sprintf ("%s%s@%.10v" , path , e .Name , e .Hash )
150
+ if err != nil {
151
+ return nil , fmt .Errorf ("%v: %v (maybe fetch it?)" ,
152
+ subpath , err )
153
+ }
154
+ _ , err = c .tracCommit (subpath , sc )
155
+ if err != nil {
156
+ return nil , err
157
+ }
144
158
} else if e .Mode == filemode .Dir {
145
159
t , err := c .repo .TreeObject (e .Hash )
146
160
if err != nil {
147
161
return nil , fmt .Errorf ("%v:%.10v: %v" ,
148
- path , e .Hash , err )
162
+ path + e . Name , e .Hash , err )
149
163
}
150
164
_ , err = c .tracTree (path + e .Name + "/" , t )
151
165
if err != nil {
@@ -157,10 +171,15 @@ func (c *Cache) tracTree(path string, tree *object.Tree) (*Trac, error) {
157
171
name : path ,
158
172
hash : tree .Hash ,
159
173
}
160
- c .tracs [ tree . Hash ] = trac
174
+ c .add ( trac )
161
175
return trac , nil
162
176
}
163
177
178
+ func (c * Cache ) add (trac * Trac ) {
179
+ debugf (" add %.10v %v\n " , trac .hash , trac .name )
180
+ c .tracs [trac .hash ] = trac
181
+ }
182
+
164
183
func main () {
165
184
log .SetFlags (0 )
166
185
r , err := git .PlainOpen ("." )
@@ -171,7 +190,7 @@ func main() {
171
190
refname := "junk"
172
191
_ , err = c .tracByRef (refname )
173
192
if err != nil {
174
- fatalf ("AddByRef: %v\n " , err )
193
+ fatalf ("%v\n " , err )
175
194
}
176
195
fmt .Printf ("%v\n " , c )
177
196
}
0 commit comments