package versionhistory import ( "context" "fmt" "knowledge-governance/internal/governance" "sort" "strings" ) func (s *Syncer) includeDeliveredCommits(ctx context.Context, commits []RawCommit, tags []RawTag) ([]RawCommit, error) { seen := map[string]bool{} for _, c := range commits { seen[c.SHA] = true } refs := append([]string{}, s.targetSHAs...) snapshots := []RawTag{} for _, tag := range tags { if tag.Annotated && strings.HasPrefix(tag.Name, "snapshot/v") && governance.SemverValid(strings.TrimPrefix(tag.Name, "snapshot/v")) { snapshots = append(snapshots, tag) } } sort.Slice(snapshots, func(i, j int) bool { return governance.CompareSemver(strings.TrimPrefix(snapshots[i].Name, "snapshot/v"), strings.TrimPrefix(snapshots[j].Name, "snapshot/v")) > 0 }) for _, tag := range snapshots { refs = append(refs, tag.TargetSHA) } for _, ref := range refs { if seen[ref] { continue } if !fullSHA.MatchString(ref) { return nil, fmt.Errorf("开发快照缺少完整提交身份") } extra, total, e := s.fetchCommitsAt(ctx, ref) if e != nil { return nil, e } if total > 0 && len(extra) != total { return nil, codeError{code: ErrorCodeCountMismatch, message: "开发快照提交历史不完整"} } found := false for _, c := range extra { if c.SHA == ref { found = true } if !seen[c.SHA] { seen[c.SHA] = true commits = append(commits, c) } } if !found { return nil, codeError{code: ErrorCodeIncompletePages, message: "开发快照目标没有被取回"} } } return commits, nil }