Skip to content

Commit

Permalink
Import debug
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleyfalzon committed Jan 27, 2017
1 parent 00f316f commit b8e9351
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions revgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c Checker) Check(reader io.Reader, writer io.Writer) (issues []Issue, err
// TODO consider lazy loading this, if there's nothing in stdin, no point
// checking for recent changes
linesChanged := c.linesChanged()
c.debug(fmt.Sprintf("lines changed: %+v", linesChanged))
c.debugf("lines changed: %+v", linesChanged)

absPath := c.AbsPath
if absPath == "" {
Expand All @@ -117,7 +117,7 @@ func (c Checker) Check(reader io.Reader, writer io.Writer) (issues []Issue, err
for scanner.Scan() {
line := lineRE.FindSubmatch(scanner.Bytes())
if line == nil {
c.debug("cannot parse file+line number:", scanner.Text())
c.debugf("cannot parse file+line number:", scanner.Text())
continue
}

Expand All @@ -129,14 +129,14 @@ func (c Checker) Check(reader io.Reader, writer io.Writer) (issues []Issue, err
// Make absolute path names relative
path := string(line[1])
if rel, err := filepath.Rel(absPath, path); err == nil {
c.debug("rewrote path from %q to %q", path, rel)
c.debugf("rewrote path from %q to %q (absPath: %q)", path, rel, absPath)
path = rel
}

// Parse line number
lno, err := strconv.ParseUint(string(line[2]), 10, 64)
if err != nil {
c.debug("cannot parse line number:", scanner.Text())
c.debugf("cannot parse line number: %q", scanner.Text())
continue
}

Expand All @@ -145,14 +145,16 @@ func (c Checker) Check(reader io.Reader, writer io.Writer) (issues []Issue, err
if len(line[3]) > 0 {
cno, err = strconv.ParseUint(string(line[3]), 10, 64)
if err != nil {
c.debug("cannot parse column number:", scanner.Text())
c.debugf("cannot parse column number: %q", scanner.Text())
// Ignore this error and continue
}
}

// Extract message
msg := string(line[4])

c.debugf("path: %q, lineNo: %v, colNo: %v, msg: %q", path, lno, cno, msg)

var (
fpos pos
changed bool
Expand Down Expand Up @@ -184,7 +186,7 @@ func (c Checker) Check(reader io.Reader, writer io.Writer) (issues []Issue, err
}
}
if !changed {
c.debug("unchanged:", scanner.Text())
c.debugf("unchanged:", scanner.Text())
}
}
if err := scanner.Err(); err != nil {
Expand All @@ -193,10 +195,10 @@ func (c Checker) Check(reader io.Reader, writer io.Writer) (issues []Issue, err
return issues, returnErr
}

func (c Checker) debug(s ...interface{}) {
func (c Checker) debugf(format string, s ...interface{}) {
if c.Debug != nil {
fmt.Fprint(c.Debug, "DEBUG: ")
fmt.Fprintln(c.Debug, s...)
fmt.Fprintf(c.Debug, format+"\n", s...)
}
}

Expand Down Expand Up @@ -230,7 +232,7 @@ func (c Checker) linesChanged() map[string][]pos {
scanner := bufio.NewScanner(c.Patch)
for scanner.Scan() {
line := scanner.Text() // TODO scanner.Bytes()
c.debug(line)
c.debugf(line)
s.lineNo++
switch {
case strings.HasPrefix(line, "+++ ") && len(line) > 4:
Expand Down

0 comments on commit b8e9351

Please sign in to comment.