Skip to content

Commit

Permalink
Create first version of WriteChanges
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Dec 31, 2017
1 parent 28a354a commit 131da5d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,11 @@ func main() {
}

g.Close()

for fname := range allFileLines {
if err := WriteChanges(fname); err != nil {
fmt.Println(err)
}
}
printSummary()
}
38 changes: 38 additions & 0 deletions summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,41 @@ func printSummary() {
}
fmt.Println(buf.String())
}

func conflictsIn(fname string) (list []Conflict) {
for _, c := range conflicts {
if c.AbsolutePath == fname && c.Choice != 0 {
list = append(list, c)
}
}
return
}

func WriteChanges(fname string) error {
targetConflicts := conflictsIn(fname)

var replacementLines []string

for _, c := range targetConflicts {
if c.Choice == Local {
replacementLines = append([]string{}, c.CurrentLines...)
} else {
replacementLines = append([]string{}, c.ForeignLines...)
}

i := 0
for ; i < len(replacementLines); i++ {
allFileLines[fname][c.Start+i-1] = replacementLines[i]
}
for ; c.End-c.Start >= i; i++ {
allFileLines[fname][c.Start+i-1] = ""
}
}

for _, l := range allFileLines[fname] {
if l != "" {
fmt.Println(l)
}
}
return nil
}

0 comments on commit 131da5d

Please sign in to comment.