From cc79e232f591772be02e9922143ee2506b5a6a99 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Tue, 28 Oct 2025 14:19:46 -0700 Subject: [PATCH] Remove unreachable functions from import_shared.go (bd-18) - Removed renameImportedIssuePrefixes and supporting functions - Removed unused imports (fmt, sort, strings, utils) - Saved ~130 LOC of dead code - All tests pass --- cmd/bd/import_shared.go | 134 ---------------------------------------- 1 file changed, 134 deletions(-) diff --git a/cmd/bd/import_shared.go b/cmd/bd/import_shared.go index d297c9f9..ff4cae64 100644 --- a/cmd/bd/import_shared.go +++ b/cmd/bd/import_shared.go @@ -2,14 +2,10 @@ package main import ( "context" - "fmt" - "sort" - "strings" "github.com/steveyegge/beads/internal/importer" "github.com/steveyegge/beads/internal/storage" "github.com/steveyegge/beads/internal/types" - "github.com/steveyegge/beads/internal/utils" ) // fieldComparator handles comparison logic for a specific field type @@ -228,136 +224,6 @@ func importIssuesCore(ctx context.Context, dbPath string, store storage.Storage, } - -// renameImportedIssuePrefixes renames all issues and their references to match the target prefix -func renameImportedIssuePrefixes(issues []*types.Issue, targetPrefix string) error { - // Build a mapping of old IDs to new IDs - idMapping := make(map[string]string) - - for _, issue := range issues { - oldPrefix := utils.ExtractIssuePrefix(issue.ID) - if oldPrefix == "" { - return fmt.Errorf("cannot rename issue %s: malformed ID (no hyphen found)", issue.ID) - } - - if oldPrefix != targetPrefix { - // Extract the numeric part - numPart := strings.TrimPrefix(issue.ID, oldPrefix+"-") - - // Validate that the numeric part is actually numeric - if numPart == "" || !isNumeric(numPart) { - return fmt.Errorf("cannot rename issue %s: non-numeric suffix '%s'", issue.ID, numPart) - } - - newID := fmt.Sprintf("%s-%s", targetPrefix, numPart) - idMapping[issue.ID] = newID - } - } - - // Now update all issues and their references - for _, issue := range issues { - // Update the issue ID itself if it needs renaming - if newID, ok := idMapping[issue.ID]; ok { - issue.ID = newID - } - - // Update all text references in issue fields - issue.Title = replaceIDReferences(issue.Title, idMapping) - issue.Description = replaceIDReferences(issue.Description, idMapping) - if issue.Design != "" { - issue.Design = replaceIDReferences(issue.Design, idMapping) - } - if issue.AcceptanceCriteria != "" { - issue.AcceptanceCriteria = replaceIDReferences(issue.AcceptanceCriteria, idMapping) - } - if issue.Notes != "" { - issue.Notes = replaceIDReferences(issue.Notes, idMapping) - } - - // Update dependency references - for i := range issue.Dependencies { - if newID, ok := idMapping[issue.Dependencies[i].IssueID]; ok { - issue.Dependencies[i].IssueID = newID - } - if newID, ok := idMapping[issue.Dependencies[i].DependsOnID]; ok { - issue.Dependencies[i].DependsOnID = newID - } - } - - // Update comment references - for i := range issue.Comments { - issue.Comments[i].Text = replaceIDReferences(issue.Comments[i].Text, idMapping) - } - } - - return nil -} - -// replaceIDReferences replaces all old issue ID references with new ones in text -// Uses boundary-aware matching to avoid partial replacements (e.g., wy-1 inside wy-10) -func replaceIDReferences(text string, idMapping map[string]string) string { - if len(idMapping) == 0 { - return text - } - - // Sort old IDs by length descending to handle longer IDs first - // This prevents "wy-1" from being replaced inside "wy-10" - oldIDs := make([]string, 0, len(idMapping)) - for oldID := range idMapping { - oldIDs = append(oldIDs, oldID) - } - sort.Slice(oldIDs, func(i, j int) bool { - return len(oldIDs[i]) > len(oldIDs[j]) - }) - - result := text - for _, oldID := range oldIDs { - newID := idMapping[oldID] - // Replace with boundary checking - result = replaceBoundaryAware(result, oldID, newID) - } - return result -} - -// replaceBoundaryAware replaces oldID with newID only when surrounded by boundaries -func replaceBoundaryAware(text, oldID, newID string) string { - if !strings.Contains(text, oldID) { - return text - } - - var result strings.Builder - result.Grow(len(text)) - - for i := 0; i < len(text); { - // Check if we match oldID at this position - if strings.HasPrefix(text[i:], oldID) { - // Check boundaries before and after - beforeOK := i == 0 || isBoundary(text[i-1]) - afterOK := (i+len(oldID) >= len(text)) || isBoundary(text[i+len(oldID)]) - - if beforeOK && afterOK { - // Valid match - replace - result.WriteString(newID) - i += len(oldID) - continue - } - } - - // Not a match or invalid boundaries - keep original character - result.WriteByte(text[i]) - i++ - } - - return result.String() -} - -// isBoundary returns true if the character is not part of an issue ID -func isBoundary(c byte) bool { - // Issue IDs contain: lowercase letters, digits, and hyphens - // Boundaries are anything else (space, punctuation, etc.) - return (c < 'a' || c > 'z') && (c < '0' || c > '9') && c != '-' -} - // isNumeric returns true if the string contains only digits func isNumeric(s string) bool { for i := 0; i < len(s); i++ {