diff --git a/main.go b/main.go index c14334f21..be777708e 100644 --- a/main.go +++ b/main.go @@ -56,7 +56,7 @@ func main() { &processor.UlocMode, "uloc", false, - "flip into uloc mode and count the number of unique lines of code", + "calculate the number of unique lines of code (ULOC) for the project", ) flags.BoolVar( &processor.DisableCheckBinary, diff --git a/processor/processor.go b/processor/processor.go index 94f37caf8..ebf47f303 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -613,17 +613,13 @@ func Process() { close(fileListQueue) }() - if UlocMode { - fileProcessorWorkerUloc(fileListQueue, fileSummaryJobQueue) - } else { - go fileProcessorWorker(fileListQueue, fileSummaryJobQueue) + go fileProcessorWorker(fileListQueue, fileSummaryJobQueue) - result := fileSummarize(fileSummaryJobQueue) - if FileOutput == "" { - fmt.Println(result) - } else { - _ = os.WriteFile(FileOutput, []byte(result), 0644) - fmt.Println("results written to " + FileOutput) - } + result := fileSummarize(fileSummaryJobQueue) + if FileOutput == "" { + fmt.Println(result) + } else { + _ = os.WriteFile(FileOutput, []byte(result), 0644) + fmt.Println("results written to " + FileOutput) } } diff --git a/processor/workers.go b/processor/workers.go index bed253c25..e2de80108 100644 --- a/processor/workers.go +++ b/processor/workers.go @@ -645,6 +645,8 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) { var fileCount int64 var gcEnabled int64 var wg sync.WaitGroup + var ulocMutex = sync.Mutex{} + uloc := map[string]struct{}{} for i := 0; i < FileProcessJobWorkers; i++ { wg.Add(1) @@ -680,6 +682,13 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) { if processFile(job) { output <- job } + if UlocMode { + ulocMutex.Lock() + for _, l := range strings.Split(string(content), "\n") { + uloc[l] = struct{}{} + } + ulocMutex.Unlock() + } } else { if Verbose { printWarn(fmt.Sprintf("error reading: %s %s", job.Location, err)) @@ -694,6 +703,7 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) { go func() { wg.Wait() close(output) + fmt.Println(ulocDisplay(len(uloc))) if Debug { printDebug(fmt.Sprintf("milliseconds reading files into memory: %d", makeTimestampMilli()-startTime))