func SourceCommitToDstCommits()

in pkg/git/mapping.go [45:90]


func SourceCommitToDstCommits(r *gogit.Repository, commitMsgTag string, dstFirstParents, srcFirstParents []*object.Commit) (map[plumbing.Hash]plumbing.Hash, error) {
	// compute merge point table
	kubeMergePoints, err := MergePoints(r, srcFirstParents)
	if err != nil {
		return nil, fmt.Errorf("failed to build merge point table: %v", err)
	}

	// convert dstFirstParents to HashesWithKubeHashes
	directKubeHashToDstMainLineHash := map[plumbing.Hash]plumbing.Hash{}
	firstDstCommit := plumbing.ZeroHash
	for _, c := range dstFirstParents {
		firstDstCommit = c.Hash

		// kh might be a non-mainline-merge (because we had used branch commits as kube hashes long ago)
		kh := SourceHash(c, commitMsgTag)
		if kh == plumbing.ZeroHash {
			continue
		}
		merge := kubeMergePoints[kh]
		if merge == nil {
			continue
		}
		// do not override, because we might have seen the actual merge before
		if _, found := directKubeHashToDstMainLineHash[merge.Hash]; !found {
			directKubeHashToDstMainLineHash[merge.Hash] = c.Hash
		}
	}

	// fill up mainlineKubeHashes in dstMainlineCommits with collapsed kube commits
	dst := firstDstCommit
	kubeHashToDstMainLineHash := map[plumbing.Hash]plumbing.Hash{}
	for i := len(srcFirstParents) - 1; i >= 0; i-- {
		kc := srcFirstParents[i]
		if dh, found := directKubeHashToDstMainLineHash[kc.Hash]; found {
			dst = dh
		}
		if dst != plumbing.ZeroHash {
			kubeHashToDstMainLineHash[kc.Hash] = dst
		}
	}
	if dst == firstDstCommit {
		glog.Warningf("no upstream mainline commit found on branch")
	}

	return kubeHashToDstMainLineHash, nil
}