gerrit.series.AssembleSeries: improve logging, also log i and j
This commit is contained in:
parent
fb9e9fa724
commit
ece32d3d7c
1 changed files with 20 additions and 16 deletions
|
@ -18,14 +18,14 @@ import (
|
||||||
// Concatenation moves changesets of the later changeset in the previous one
|
// Concatenation moves changesets of the later changeset in the previous one
|
||||||
// in a cleanup phase, we remove orphaned series (those without any changesets inside)
|
// in a cleanup phase, we remove orphaned series (those without any changesets inside)
|
||||||
// afterwards, we do an integrity check, just to be on the safe side.
|
// afterwards, we do an integrity check, just to be on the safe side.
|
||||||
func AssembleSeries(changesets []*Changeset, log *log.Logger) ([]*Serie, error) {
|
func AssembleSeries(changesets []*Changeset, logger *log.Logger) ([]*Serie, error) {
|
||||||
series := make([]*Serie, 0)
|
series := make([]*Serie, 0)
|
||||||
mapLeafToSerie := make(map[string]*Serie, 0)
|
mapLeafToSerie := make(map[string]*Serie, 0)
|
||||||
|
|
||||||
for _, changeset := range changesets {
|
for _, changeset := range changesets {
|
||||||
logger := log.WithField("changeset", changeset.String())
|
l := logger.WithField("changeset", changeset.String())
|
||||||
|
|
||||||
logger.Debug("creating initial serie")
|
l.Debug("creating initial serie")
|
||||||
serie := &Serie{
|
serie := &Serie{
|
||||||
ChangeSets: []*Changeset{changeset},
|
ChangeSets: []*Changeset{changeset},
|
||||||
}
|
}
|
||||||
|
@ -34,29 +34,33 @@ func AssembleSeries(changesets []*Changeset, log *log.Logger) ([]*Serie, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine series using a fixpoint approach, with a max iteration count.
|
// Combine series using a fixpoint approach, with a max iteration count.
|
||||||
log.Debug("glueing together phase")
|
logger.Debug("glueing together phase")
|
||||||
for i := 1; i < 100; i++ {
|
for i := 1; i < 100; i++ {
|
||||||
didUpdate := false
|
didUpdate := false
|
||||||
log.Debugf("at iteration %d", i)
|
logger.Debugf("at iteration %d", i)
|
||||||
for _, serie := range series {
|
for j, serie := range series {
|
||||||
logger := log.WithField("serie", serie.String())
|
l := logger.WithFields(log.Fields{
|
||||||
|
"i": i,
|
||||||
|
"j": j,
|
||||||
|
"serie": serie.String(),
|
||||||
|
})
|
||||||
parentCommitIDs, err := serie.GetParentCommitIDs()
|
parentCommitIDs, err := serie.GetParentCommitIDs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return series, err
|
return series, err
|
||||||
}
|
}
|
||||||
if len(parentCommitIDs) != 1 {
|
if len(parentCommitIDs) != 1 {
|
||||||
// We can't append merge commits to other series
|
// We can't append merge commits to other series
|
||||||
logger.Infof("No single parent, skipping.")
|
l.Infof("No single parent, skipping.")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parentCommitID := parentCommitIDs[0]
|
parentCommitID := parentCommitIDs[0]
|
||||||
logger.Debug("Looking for a predecessor.")
|
l.Debug("Looking for a predecessor.")
|
||||||
// if there's another serie that has this parent as a leaf, glue together
|
// if there's another serie that has this parent as a leaf, glue together
|
||||||
if otherSerie, ok := mapLeafToSerie[parentCommitID]; ok {
|
if otherSerie, ok := mapLeafToSerie[parentCommitID]; ok {
|
||||||
if otherSerie == serie {
|
if otherSerie == serie {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logger := logger.WithField("otherSerie", otherSerie)
|
l = l.WithField("otherSerie", otherSerie)
|
||||||
|
|
||||||
myLeafCommitID, err := serie.GetLeafCommitID()
|
myLeafCommitID, err := serie.GetLeafCommitID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -64,7 +68,7 @@ func AssembleSeries(changesets []*Changeset, log *log.Logger) ([]*Serie, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// append our changesets to the other serie
|
// append our changesets to the other serie
|
||||||
logger.Debug("Splicing together.")
|
l.Debug("Splicing together.")
|
||||||
otherSerie.ChangeSets = append(otherSerie.ChangeSets, serie.ChangeSets...)
|
otherSerie.ChangeSets = append(otherSerie.ChangeSets, serie.ChangeSets...)
|
||||||
|
|
||||||
delete(mapLeafToSerie, parentCommitID)
|
delete(mapLeafToSerie, parentCommitID)
|
||||||
|
@ -77,23 +81,23 @@ func AssembleSeries(changesets []*Changeset, log *log.Logger) ([]*Serie, error)
|
||||||
|
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
} else {
|
} else {
|
||||||
logger.Debug("Not found.")
|
l.Debug("Not found.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
series = removeOrphanedSeries(series)
|
series = removeOrphanedSeries(series)
|
||||||
if !didUpdate {
|
if !didUpdate {
|
||||||
log.Infof("converged after %d iterations", i)
|
logger.Infof("converged after %d iterations", i)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check integrity, just to be on the safe side.
|
// Check integrity, just to be on the safe side.
|
||||||
for _, serie := range series {
|
for _, serie := range series {
|
||||||
logger := log.WithField("serie", serie.String())
|
l := logger.WithField("serie", serie.String())
|
||||||
logger.Debugf("checking integrity")
|
l.Debugf("checking integrity")
|
||||||
err := serie.CheckIntegrity()
|
err := serie.CheckIntegrity()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("checking integrity failed: %s", err)
|
l.Errorf("checking integrity failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return series, nil
|
return series, nil
|
||||||
|
|
Loading…
Reference in a new issue