Skip to content

Commit eab94f6

Browse files
committed
Don't produce new subtrac commits under so many conditions.
This cleans up the resulting tree significantly, without any loss of generality. We also change the commit description to identify the source commit (which by definition is one that's interesting because it changes a submodule).
1 parent ecc6f85 commit eab94f6

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

subtrac.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,38 @@ func (c *Cache) tracCommit(path string, commit *object.Commit) (*Trac, error) {
200200

201201
seenHeads := make(map[plumbing.Hash]bool)
202202
seenTracs := make(map[plumbing.Hash]bool)
203-
var heads []*Trac
203+
var newHeads []*Trac
204204
var tracs []*object.Commit
205205

206-
for _, h := range trac.subHeads {
207-
if !seenHeads[h.hash] {
208-
seenHeads[h.hash] = true
209-
heads = append(heads, h)
210-
}
211-
}
212206
for _, p := range trac.parents {
213207
if p.tracCommit != nil {
214208
if !seenTracs[p.tracCommit.Hash] {
215209
seenTracs[p.tracCommit.Hash] = true
216210
tracs = append(tracs, p.tracCommit)
217211
}
218212
}
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+
}
219224
}
220225

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+
}
224231
} 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)
228235
if err != nil {
229236
return nil, err
230237
}
@@ -279,12 +286,13 @@ func (c *Cache) newTracCommit(commit *object.Commit, tracs []*object.Commit, hea
279286
return nil, fmt.Errorf("emptyTree.Store: %v", err)
280287
}
281288

289+
msg := fmt.Sprintf("[git-subtrac for %v]", commit.Hash)
282290
tc := &object.Commit{
283291
Author: sig,
284292
Committer: sig,
285293
TreeHash: emptyTreeHash,
286294
ParentHashes: parents,
287-
Message: "[git-subtrac merge]",
295+
Message: msg,
288296
}
289297
nec = c.repo.Storer.NewEncodedObject()
290298
err = tc.Encode(nec)

0 commit comments

Comments
 (0)