Skip to content

Commit caf13c9

Browse files
committed
auto-coder: refactor diff-related functions to simplify parameter handling
- Removed `stats` parameter from `formatDiffLines` function. - Simplified `createProgressBar` function by removing unused parameters (`added`, `removed`, `total`). - Updated `diff` function to initialize `filesToStage` with a pre-allocated slice based on the length of `c.coder.absFileNames`. - Removed unused `ctx` parameter from `diff` function. Signed-off-by: codiing-hui <wecoding@yeah.net>
1 parent c1fccd3 commit caf13c9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

internal/git/git.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (c *Command) FormatDiff(diffOutput string) string {
262262

263263
lines := strings.Split(diffOutput, "\n")
264264
stats := c.calculateDiffStats(lines)
265-
formattedLines := c.formatDiffLines(lines, stats)
265+
formattedLines := c.formatDiffLines(lines)
266266

267267
// Add separator before file header
268268
if stats.FileHeader != "" {
@@ -317,7 +317,7 @@ func (c *Command) calculateDiffStats(lines []string) *DiffStats {
317317
}
318318

319319
// formatDiffLines formats diff lines with proper styling
320-
func (c *Command) formatDiffLines(lines []string, stats *DiffStats) []string {
320+
func (c *Command) formatDiffLines(lines []string) []string {
321321
var formattedLines []string
322322
var origLineNum, updatedLineNum int
323323

@@ -356,15 +356,15 @@ func (c *Command) formatDiffLines(lines []string, stats *DiffStats) []string {
356356

357357
// createDiffHeader creates the header with stats and progress
358358
func (c *Command) createDiffHeader(stats *DiffStats) string {
359-
progress := c.createProgressBar(stats.Added, stats.Removed, stats.Total, stats.Context, stats.Total)
359+
progress := c.createProgressBar(stats.Context, stats.Total)
360360

361361
return console.StdoutStyles().DiffHeader.Render(
362362
fmt.Sprintf("Changes (%d added, %d removed, %d unchanged):\n%s\n",
363363
stats.Added, stats.Removed, stats.Context, progress))
364364
}
365365

366366
// createProgressBar generates a visual progress bar with line numbers
367-
func (c *Command) createProgressBar(added, removed, total, lastNonDeleted, totalLines int) string {
367+
func (c *Command) createProgressBar(lastNonDeleted, totalLines int) string {
368368
const barWidth = 30
369369
if totalLines == 0 {
370370
return ""

internal/ui/coders/commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ func (c *CommandExecutor) help(_ context.Context, _ ...string) error {
337337
return nil
338338
}
339339

340-
func (c *CommandExecutor) diff(ctx context.Context, _ ...string) error {
340+
func (c *CommandExecutor) diff(_ context.Context, _ ...string) error {
341341
// Stage all added files
342-
var filesToStage []string
342+
filesToStage := make([]string, 0, len(c.coder.absFileNames))
343343
for file := range c.coder.absFileNames {
344344
filesToStage = append(filesToStage, file)
345345
}

0 commit comments

Comments
 (0)