Minor fixes and tweaks
This commit is contained in:
29
main.go
29
main.go
@@ -16,16 +16,19 @@ import (
|
||||
)
|
||||
|
||||
type GlobalStats struct {
|
||||
TotalMatches int
|
||||
TotalModifications int
|
||||
ProcessedFiles int
|
||||
FailedFiles int
|
||||
TotalMatches int
|
||||
TotalModifications int
|
||||
ProcessedFiles int
|
||||
FailedFiles int
|
||||
ModificationsPerCommand map[string]int
|
||||
}
|
||||
|
||||
var (
|
||||
repo *git.Repository
|
||||
worktree *git.Worktree
|
||||
stats GlobalStats = GlobalStats{}
|
||||
stats GlobalStats = GlobalStats{
|
||||
ModificationsPerCommand: make(map[string]int),
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -57,7 +60,7 @@ func main() {
|
||||
logger.Info("Initializing with log level: %s", level.String())
|
||||
|
||||
// The plan is:
|
||||
// Load all commands
|
||||
// Load all commands
|
||||
commands, err := utils.LoadCommands(args)
|
||||
if err != nil {
|
||||
logger.Error("Failed to load commands: %v", err)
|
||||
@@ -95,8 +98,6 @@ func main() {
|
||||
|
||||
// Add performance tracking
|
||||
startTime := time.Now()
|
||||
fileCount := 0
|
||||
modCount := 0
|
||||
var fileMutex sync.Mutex
|
||||
|
||||
for file, commands := range associations {
|
||||
@@ -127,6 +128,10 @@ func main() {
|
||||
return
|
||||
}
|
||||
modifications = append(modifications, commands...)
|
||||
// It is not guranteed that all the commands will be executed...
|
||||
// TODO: Make this better
|
||||
// We'd have to pass the map to executemodifications or something...
|
||||
stats.ModificationsPerCommand[command.Name] += len(commands)
|
||||
}
|
||||
|
||||
if len(modifications) == 0 {
|
||||
@@ -138,8 +143,8 @@ func main() {
|
||||
fileDataStr, count := utils.ExecuteModifications(modifications, fileDataStr)
|
||||
|
||||
fileMutex.Lock()
|
||||
fileCount++
|
||||
modCount += count
|
||||
stats.ProcessedFiles++
|
||||
stats.TotalModifications += count
|
||||
fileMutex.Unlock()
|
||||
|
||||
logger.Info("Executed %d modifications for file %q", count, file)
|
||||
@@ -157,8 +162,8 @@ func main() {
|
||||
|
||||
processingTime := time.Since(startTime)
|
||||
logger.Info("Processing completed in %v", processingTime)
|
||||
if fileCount > 0 {
|
||||
logger.Info("Average time per file: %v", processingTime/time.Duration(fileCount))
|
||||
if stats.ProcessedFiles > 0 {
|
||||
logger.Info("Average time per file: %v", processingTime/time.Duration(stats.ProcessedFiles))
|
||||
}
|
||||
|
||||
// TODO: Also give each command its own logger, maybe prefix it with something... Maybe give commands a name?
|
||||
|
Reference in New Issue
Block a user