@@ -200,31 +200,38 @@ func (c *Cache) tracCommit(path string, commit *object.Commit) (*Trac, error) {
200
200
201
201
seenHeads := make (map [plumbing.Hash ]bool )
202
202
seenTracs := make (map [plumbing.Hash ]bool )
203
- var heads []* Trac
203
+ var newHeads []* Trac
204
204
var tracs []* object.Commit
205
205
206
- for _ , h := range trac .subHeads {
207
- if ! seenHeads [h .hash ] {
208
- seenHeads [h .hash ] = true
209
- heads = append (heads , h )
210
- }
211
- }
212
206
for _ , p := range trac .parents {
213
207
if p .tracCommit != nil {
214
208
if ! seenTracs [p .tracCommit .Hash ] {
215
209
seenTracs [p .tracCommit .Hash ] = true
216
210
tracs = append (tracs , p .tracCommit )
217
211
}
218
212
}
213
+ for _ , h := range p .subHeads {
214
+ // parent tracCommit already includes this subHead,
215
+ // so we don't need to include it again.
216
+ seenHeads [h .hash ] = true
217
+ }
218
+ }
219
+ for _ , h := range trac .subHeads {
220
+ if ! seenHeads [h .hash ] {
221
+ seenHeads [h .hash ] = true
222
+ newHeads = append (newHeads , h )
223
+ }
219
224
}
220
225
221
- if len (trac .parents ) == 1 && equalSubs (trac .subHeads , trac .parents [0 ].subHeads ) {
222
- // Nothing has changed since our parent, no new commit needed.
223
- trac .tracCommit = trac .parents [0 ].tracCommit
226
+ if len (newHeads ) == 0 && len (tracs ) <= 1 {
227
+ if len (tracs ) == 1 {
228
+ // Nothing added since our parent, no new commit needed.
229
+ trac .tracCommit = tracs [0 ]
230
+ }
224
231
} else {
225
- // Generate a new commit that includes our parent(s) and all
226
- // our submodules.
227
- trac .tracCommit , err = c .newTracCommit (commit , tracs , heads )
232
+ // Generate a new commit that includes our parent(s) and our
233
+ // new submodules.
234
+ trac .tracCommit , err = c .newTracCommit (commit , tracs , newHeads )
228
235
if err != nil {
229
236
return nil , err
230
237
}
@@ -279,12 +286,13 @@ func (c *Cache) newTracCommit(commit *object.Commit, tracs []*object.Commit, hea
279
286
return nil , fmt .Errorf ("emptyTree.Store: %v" , err )
280
287
}
281
288
289
+ msg := fmt .Sprintf ("[git-subtrac for %v]" , commit .Hash )
282
290
tc := & object.Commit {
283
291
Author : sig ,
284
292
Committer : sig ,
285
293
TreeHash : emptyTreeHash ,
286
294
ParentHashes : parents ,
287
- Message : "[git-subtrac merge]" ,
295
+ Message : msg ,
288
296
}
289
297
nec = c .repo .Storer .NewEncodedObject ()
290
298
err = tc .Encode (nec )
0 commit comments