Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 54 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,72 @@ package main
import (
"fmt"
"time"
"os"
"bufio"
"strings"
"strconv"
"os/exec"
)

//timeTrack tracks the time it took to do things.
//It's a convenient method that you can use everywhere
//you feel like it
func timeTrack(start time.Time, name string) {
elapsed := time.Since(start)
fmt.Printf("%s took %s\n", name, elapsed)
}

//main is the entry point of our go program. It defers
//the execution of timeTrack so we can know how long it
//took for the main to complete.
//It also calls the compute and output the returned struct
//to stdout.
func main() {
defer timeTrack(time.Now(), "compute diff")
fmt.Println(compute())
}

//compute parses the git diffs in ./diffs and returns
//a result struct that contains all the relevant informations
//about these diffs
// list of files in the diffs
// number of regions
// number of line added
// number of line deleted
// list of function calls seen in the diffs and their number of calls
func compute() *result {
var r result

return nil
exec.Command("./run.sh").Run()

r.files = calcFiles()
r.lineAdded, r.lineDeleted, r.regions = calcSummary()
r.functionCalls = calcCalls()

return &r
}

func calcFiles() []string {
return readLine("files.txt")
}

func calcSummary() (int, int, int) {
summary := readLine("summary.txt")
lines := strings.Split(summary[0]," ")

addedLines, _ := strconv.Atoi(lines[0])
deletedLines, _ := strconv.Atoi(lines[1])
regions, _ := strconv.Atoi(summary[1])

return addedLines, deletedLines, regions
}

func calcCalls() map[string]int {
m := make(map[string]int)

calls := readLine("calls.txt")
for _, call := range calls{
c := strings.Split(call," ")
key := c[0]
value,_ := strconv.Atoi(c[1])
m[key] = value
}
return m
}

func readLine(path string) []string {
var lines []string
fileHandle, _ := os.Open(path)
defer fileHandle.Close()
fileScanner := bufio.NewScanner(fileHandle)

for fileScanner.Scan() {
lines = append(lines, fileScanner.Text())
}

return lines
}
7 changes: 7 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
diffstat -l diffs/*.diff > files.txt&
diffstat -s diffs/*.diff | cut -d' ' -f5,7 > summary.txt; cat diffs/*.diff | grep '^@@' | wc -l >> summary.txt&
export MAX=$(cat diffs/* | grep $'^+\t' | grep -E '[A-Z]\(|[a-z]\(|[0-9]\(|\_\(' | awk 'BEGIN{max=-1}{n=split($0,c,"(")-1;if (n>max) max=n}END{print max}'); for i in $(seq 1 $MAX); do for j in $(seq 1 $i); do cat diffs/* | grep $'^+\t' | grep -E '[A-Z]\(|[a-z]\(|[0-9]\(|\_\(' | awk '{n=split($0,c,"(")-1;if (n!=0) print n,$0}' | grep "^$i" | cut -d"(" -f$j | grep -E '[A-Z]|[a-z]|[0-9]|\_$' | awk '{len=split($0,tokens," "); print tokens[len]}'; done; done | awk '/^[A-Z]|^[a-z]|^\_|^!/{gsub("!",""); print $0}' | grep -v 'for$' | grep -v 'while$' | grep -v 'if$' | cut -d\) -f2 | grep -E '[A-Z]|[a-z]|[0-9]|\_' | sort | uniq -c | awk '{s=$0; split(s,b," "); n=gsub(" ","");print b[2],b[1]}' > calls.txt